Détail du package

@atakama/qtest

AtakamaLLC2ISC1.6.5

quick and simple test runner for nodejs (alternative to jest)

test, jest, runner, unit

readme

Build Status codecov

qtest

Simple test runner for nodejs.

Install:

npm install @atakama/qtest

Use:

test = require('@atakama/qtest')
assert = require('assert')

test("test name", async (ctx)=>{
    ctx.log("some log")

    assert.equal(ctx.someFixture, 444)

    // parameterized test
    assert.equal(ctx.param, true)
}, {param: [true, false]})

test.beforeAll = async (ctx) => {
    ctx.someFixture = 444
}

test.run()

Coverage:

npm install nyc
node_modules/.bin/nyc node test.js

Other features:

  • cli options
    • -t \<test-name\> : pick a test to run
    • -l : disable parallelism
    • -s : disable log cap
  • before/after/beforeAll/afterAll
    • does what you expect
  • fixtures
    • beforeAll/before/after/afterAll take objects... stuff your fixtures in there
  • test.skip(...)
  • t = test.scope("name")
    • creates a new, scoped test collection
    • will get run if the parent is run
  • yarn add --dev sinon for asseritions, mocks, and spies
    • see sinonjs.org for more details
    • test.assert will include augmented assertions (assert.calledOnce, et al)
    • test.spy, test.stub, ... aliased to sinon equivalents
    • some jesty aliases:
      • test.fn == sinon.fake
      • test.replaceFn = sinon.replace
      • test.argsMatch = sinon.match
  • unawaited promise handling
    • async calls that linger are considered failures
    • unawaited promise rejections are failures

Babel:

Example package.json using babel and coverage:

  "scripts": {
    "test": "babel-node --ignore nothing test.js",
    "coverage": "nyc npm run test"
  },
  "nyc": {
    "require": [
      "@babel/register"
    ],
    "reporter": [
      "lcov",
      "text"
    ]

Webstorm or VSCode interactive debugger

On Windows, you cannot set the interpreter to babel-node, because it's a cmd file and that causes most debuggers to get confused. This config works on all debuggers:

  • Click Run/Edit Configurations..
  • Set NodeParameters: node_modules/@babel/node/bin/babel-node.js --ignore nothing --
  • Optionally set Application parameters: -t <your test name

Changelog

changelog

Changelog

[1.6.5]:

Changed

  • missing find-up package

[1.6.4]:

Changed

  • trackAsync output is better

[1.6.3]:

Changed

  • trackAsync useful

[1.6.1]:

Fixed

  • node 8 fix

[1.6.0]:

Added

  • use test() instead of test.add (if you want)

[1.5.1]:

Changed

  • --trackAsync to be off by default for real

[1.5.0]:

Changed

  • --trackAsync to be off by default
  • --exitMsecs 500
  • --noReject : don't fail on unhandled

    Changed

    [1.4.4]:

    Changed

  • Fiddling with async tracking stuff

[1.4.2]:

Changed

  • Sinon plugin works with scoped tests

[1.4.1]:

Changed

  • Package minor change

[1.4.0]:

Added

  • Track async calls. Fail on unawaited.
  • Fail on unhandled promise rejections.
  • Options: -noreject, -noasync to disable these.
  • Show durations

[1.3.0]:

Added

  • If sinon is installed, expose assertions/mocks/spy's

[1.2.2]:

Changed

  • Fix some printing issues

[1.2.1]:

Changed

  • Test fails if 'after' fails
  • Reorgnize runner options
  • -t option works properly with scopes

    Added

  • Added changelog

[1.1.2]:

Added

  • test.skip() skips test
  • test.scope() creates new scope