Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Tiny test runner for Node.js
test()
function, plus .skip() and .only()Often for small projects, test suites consist of some wrapped assertions in test
or it
functions. Node.js has a fine
assert
module built-in, while exception output is pretty since Node v12. Last but not least, if any test fails, the
process should exit with a non-zero code so that CI/CD environments can act accordingly.
Turns out this isn't very hard to implement, all source code of bron combined is only <100 LOC. In case you need more from your test framework, I'm happy to recommend one of the more full fledged options:
Runner | Dependencies | Size |
---|---|---|
Bron (v1.1.0) | 0 | 5K |
Tape (v4.11.0) | 32 | 265K |
Mocha (v6.2.0) | 116 | 1.53M |
Ava (v2.2.0) | 387 | 3.68M |
beforeEach
, after
)npm install bron -D
Add a test
script to run the tests (npm test
), e.g.:
{
"scripts": {
"test": "bron test/*.js"
}
}
bron <file> [--serial] [--timeout=ms]
import test from 'bron';
import { strict as assert } from 'assert';
const add = (x, y) => x + y;
test('should pass', () => {
assert.equal(add(1, 2), 3);
});
test('should fail', () => {
assert.equal(add(1, 2), 4);
});
$ bron test.js
✔ should pass
✖ should fail
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
3 !== 4
at /Users/lars/Projects/bron/sync.js:11:10
...
✖ 1 test(s) failed
✔ 1 test(s) passed
No magic, but know that the tests run in parallel.
const isTwoAsync = x => (x === 2 ? Promise.resolve('OK') : Promise.reject('NOT OK'));
test('should pass with resolved promise', () => {
assert.doesNotReject(() => isTwoAsync(2));
});
test('should pass with rejected promise', () => {
assert.rejects(() => isTwoAsync(10), /NOT OK/);
});
Add --serial
:
const wait = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
test('should run serial (first)', async () => {
await wait(100);
assert(true);
});
test('should run serial (last)', async () => {
await wait(0);
assert(true);
});
$ bron --serial
✔ should run serial (first)
✔ should run serial (last)
Return a promise, and the test will pass (resolved) or fail (rejected).
const isTwoAsync = x => (x === 2 ? Promise.resolve('OK') : Promise.reject('NOT OK'));
test('should pass with resolved promise', () => {
return isTwoAsync(2);
});
test('should fail with rejected promise', () => {
return isTwoAsync(10);
});
$ bron
✔ should pass with resolved promise
✖ should fail with rejected promise
NOT OK
✖ 1 test(s) failed.
✔ 1 test(s) passed.
test.skip('should be skipped', () => {
assert.equal(1, 1);
});
test.only('should pass', () => {
assert.equal(1, 1);
});
test('should be skipped', () => {
assert.equal(1, 1);
});
You can use .only
multiple times (each .only
will run).
Add --timeout=n
(with n
in milliseconds) to change the default value for each test (15000
).
FAQs
Tiny test runner
We found that bron demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.