start-testing
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Start Testing

Start Testing is a lightweight Typescript Testing Library with 0 dependencies and a minimal yet flexible API to get you from idea to validation as fast as possible.

Install

npm install --save-dev start-testing

Usage

Writing Tests

import * as testing from 'start-testing'

export async function testSimple(t: testing.Context) {
    const { status } = await fetch('https://www.example.com')
    if (status !== 200) {
        t.error(`expected: ${200}, got: ${status}`)
    }
}

export async function testFatal(t: testing.Context) {
    const { status } = await fetch('https://www.example.com')
    if (status !== 403) {
        t.fatal(`expected: ${403}, got: ${status}`)
    }
}

export async function testTableSerial(t: testing.Context) {
    const tests = [
        { url: "https://www.example.com", expectedCode: 200 },
        { url: "https://www.google.com", expectedCode: 200 },
        { url: "https://www.facebook.com", expectedCode: 200 },
        { url: "https://www.amazon.com", expectedCode: 200 }
    ]

    for (let test of tests) {
        await t.run(test.url, async t => {
            const res = await fetch(test.url)
            if (res.status !== test.expectedCode) {
                t.error(`expected: ${test.expectedCode}, got: ${res.status}`)
            }
        })
    }
}

export async function testTableParallel(t: testing.Context) {
    const tests = [
        { url: "https://www.example.com", expectedCode: 200 },
        { url: "https://www.google.com", expectedCode: 200 },
        { url: "https://www.facebook.com", expectedCode: 200 },
        { url: "https://www.amazon.com", expectedCode: 200 }
    ]

    await Promise.all(
        tests.map(test => t.run(test.url, async (t) => {
            const res = await fetch(test.url)
            if (res.status !== test.expectedCode) {
                t.error(`expected: ${test.expectedCode}, got: ${res.status}`)
            }
        }))
    )
}

Running Tests (Node)

runTests.ts

import * as testing from 'start-testing'
import * as tests from 'path/to/tests'

testing.Runner.runSuite('example tests', tests)
    .then(process.exit)
npx ts-node ./runTests.ts

Reference

Context API

  • log(...message: any[]) - logs a message
  • error(message: any) - marks the test as failed and records the error, allows the test to continue
  • fatal(message: any) - marks the test as failed and records the error, stops the test from continuing

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    7
    • latest

Version History

Package Sidebar

Install

npm i start-testing

Weekly Downloads

7

Version

1.0.4

License

MIT

Unpacked Size

24.8 kB

Total Files

15

Last publish

Collaborators

  • connormckelvey