@gozala/subtest
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

subtest

Native ES test system that simply runs tests that were exported by your modules.

Format

subtest will run functions exported by a name starting with test

// You can use camel case naming
/** @type {import('subtest').Test} */
export const testSum = (assert) => {
  assert.equal(1 + 1, 2)
}

// You can also use snake case naming
/** @type {import('subtest').Test} */
export const test_multiply = (assert) => {
  assert.equal(2 * 2, 4)
}

// Or just use name `test`
/** @type {import('subtest').Test} */
export const test = (assert) => {
  assert.throws(() => new Error('boom'))
}

It will also run exported test suites, which are objects (with test functions) exported by name starting with test.

Test suites can contain nested suites with arbitrary names.

export test = {
  'multiply': (assert) => {
    assert.equal(2 * 2, 4)
  },
  'range check': (assert) => {
    assert.throws(() => new Uint8Array().set([1, 2]), /out of bound/)
  }
}

Usage

You can run all the tests in the test folder by running

subtest test

Alternatively you can create node script e.g. mytest.js that runs tests

import test from 'subtest'
import * testMath from './test/math.js'
import * testString from './test/string.js'

test({ testMath, testString })
node ./mytest.js

Dependencies (2)

Dev Dependencies (3)

Package Sidebar

Install

npm i @gozala/subtest

Weekly Downloads

2

Version

1.0.5

License

(Apache-2.0 AND MIT)

Unpacked Size

28.2 kB

Total Files

19

Last publish

Collaborators

  • gozala