smoltest
v1.0.5
Published
A JavaScript test runner. Like Mocha but smol.
Downloads
17
Maintainers
Readme
smol
A JavaScript test runner. Like Mocha but smol.
Ok so basically I'm very smol
Why smol
- No global variables
- No dependencies
- Basically it's very smol
Installation
npm add smoltest
Synopsis
smol <DIR>
Usage
Put the following code in a file:
const assert = require('assert').strict
const { describe, it } = require('smoltest')(exports)
describe('String', () => {
it('#concat()', () => {
assert.strictEqual('a'.concat('b'), 'ab')
})
it('#repeat()', () => {
assert.strictEqual('a'.repeat(2), 'aa')
})
})
Run the tests:
npx smol .
Test files are those
- Starting with test and ending with .js
- Ending with .test.js
- Ending with .spec.js
Syntax
Smol supports the following Mocha syntax:
| Mocha "BDD" 🔗 | Mocha "TDD" 🔗 | --- | --- | describe | suite | it | test | before | suiteSetup | after | suiteTeardown | beforeEach | setup | afterEach | teardown | context | | specify | | xdescribe | | xit |
Unlike Mocha, these functions aren't global. They can be imported as follows:
const { describe, it, beforeEach, afterEach } = require('smoltest')(exports)
You can also write test functions without any special syntax whatsoever, similar to pytest. Make sure to export any functions that are meant to be test cases with names starting with test.
For example:
const assert = require('assert').strict
exports['test Array#concat()'] = () => {
assert.deepStrictEqual(['a'].concat(['b']), ['a', 'b'])
}
exports['test Array#fill()'] = () => {
assert.deepStrictEqual(Array(2).fill('a'), ['a', 'a'])
}
License
MIT