JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q32189F
  • License ISC

Super simple NodeJS test tools for free-style testing and benchmarking at home.

Package Exports

  • test-a-bit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (test-a-bit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

test-a-bit

Zero-dependency light weight testing & benchmarking tool for node-js.

BEWARE!!!

This package is not ready for production, but still can be fun to use.

Installation

npm i test-a-bit --save-dev

runner(, [silent=false])

Each test script running in a separate process. You can specify the timeout for each script.

/* run_test.js */

import { runner } from 'test-a-bit'

runner([
  { script: './tests/success.js' },
  { script: './tests/fail.js' },
  { script: './tests/timeout.js', timeout: 200 },
  { script: './tests/random.js', timeout: 200 },
]).then(results => console.log(results, 'bye'))

<tests_list>

List of objects with script and timeout.

[silent=false]

Set to true to suppress console output from console.log inside the tests.

results

Runner returns Promise with results map like this:

[
  '12ebd1-9daf62-594cd5' => {
    uid: '12ebd1-9daf62-594cd5',
    name: 'sample fail test',
    note: 'oh, no!',
    timeout: 200,
    script: './tests/random.js',
    silent: false,
    result: 'fail',
    delta: 0.09140002727508545,
    delta_precision: 'milli',
    delta_precision_sym: 'ms',
    exit_code: 1
  }
]

If you are lazy enough - just use auto_runner to automatically run all scripts in the specific folder.

auto_runner('./tests/').then(results => console.log('bye'))

Actual Test

Each test is a separated file that calls the execute method once with the test function. To indicate test result - run the success or fail function.

/* tests/random-test.js */

import { execute } from 'test-a-bit'

execute('sample fail test', (success, fail, is_runner) => {
  const rnd = Math.random()
  
  if (!is_runner) console.log(`oh wow! rolled: rnd`)
  
  success > 0.5
    ? success('got lucky!')
    : fail('oh, no!')
})

Possible output:

[fail]     sample fail test >> oh, no! / Δ=0.07ms

execute(<name>, <callback>)

<name> - Is a string - will be passed to the output.

<callback> - Callback Function with your test inside.

Callback Arguments

Callback function has 3 arguments: result functions success & fail, and is_runner flag.

fail([note]) & success([note])

Call this to mark test passed or failed respectively.

note - string, will be passed to the output.

is_runner

Is this test was runner by a runner (along with other tests). Might be handy to decide if you need to spam the console.

That's it. Have a fun! :3