Skip to content

JJ/aqa

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aqa

Dependency-less Test Runner for Node.js

aqa is a light-weight and a quick alternative to ava, with a similar API.

Installation

npm i aqa -D

Usage

Simple single-file usage

your.tests.js:

const test = require('aqa')

test('Test ourself', t => {    
  t.is(1 + 1, 2);
  t.not(1 + 1, 3);
  t.true(1 === 1);
  t.false(1 === 2);
})

node your.tests.js

Integration

To run multiple tests and integrate CI testing with your package, you need to change your package.json's test in the scripts section to "aqa":

"scripts": {
  "test": "aqa"
},

Then, to run all your tests: npm run test

All files anywhere in your package's directory (and subdirectories, excluding node_modules and directories that start with a single _ ) that match the following patterns will be ran:

test.js
tests.js
*.test.js
*.tests.js
*/test-*.js
*.spec.js
**/test/*.js
**/tests/*.js
**/__tests__/*.js

If your test files are named differently, for instance *.spec.js, you can write your test script like this:

"scripts": {
  "test": "aqa *.spec.js"
},

Watch mode

To automatically run tests whenever you modify your files, aqa has a watch mode. If you desire this functionality, add a new script to your package.json:

"scripts": {
  "test": "aqa",
  "test:watch": "aqa --watch"
},

To start the watch script, run npm run test:watch.

Like with the test script, you can watch files other than *.test.js:

"test:watch": "aqa *.foo.js --watch"

Assertion

These assertion methods are currently supported:

t.is(actual, expected, message?)

Asserts that actual is equal to expected.

t.not(actual, notEpected, message?)

Asserts that actual is not equal to notEpected.

t.deepEqual(actual, expected, message?)

Asserts that actual is deeply equal to expected. test.ignore can be used to skip certain properties, i.e.:

let actual = { a: 3, b: 'ok', c: 7 }
t.deepEqual(actual, {
  a: 3,
  b: 'ok',
  c: test.ignore
})

Differences are reported with a minus - for actual values and plus + for expected values.

You may also use test.ignoreExtra() to only assert the given properties in the expected object:

let actual = { a: 3, b: 'ok', c: 7 }
t.deepEqual(actual, test.ignoreExtra({
  b: 'ok',
}))

t.notDeepEqual(actual, expected, message?)

Asserts that actual is not deeply equal to expected.

t.true(value, message?)

Asserts that value is true.

t.false(value, message?)

Asserts that value is false.

t.throws(fn, opts?, message?)

Asserts that fn throws an exception.

function uhOh() {
  throw new Error("Uh oh.");
}

t.throws(_ => {
  uhOh();
})

You can also check for specific types of exception. If the exception does not match it, the test will fail:

t.throws(_ => {
  uhOh();
}, { instanceOf: TypeError })

t.throwsAsync(fn, opts?, message?)

The asynchronous version of t.throws(). Note the addition of async/await.

test('Async test', async t => {
  await t.throwsAsync(async _ => {
    await uhOhAsync();
  })
})

You can also check for specific types of exception. If the exception does not match it, the test will fail:

await t.throws(async _ => {
  await uhOhAsync();
}, { instanceOf: TypeError })

t.notThrows(fn, message?)

Asserts that fn does not throw an exception.

t.notThrowsAsync(fn, message?)

Asserts that async function or Promise fn does not throw an exception.

t.log(message, ...arguments?)

Not actually an assertion method, but helps you easily find for which test method you've logged information. Could be used instead of console.log.

Work in progress:

  • Configuration in (nearest) package.json

About

Dependency-less Test Runner for Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%