
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@locustjs/test
Advanced tools
This library provides a simple test runner for unit-testing.
npm i @locustjs/test
2.0.2
import { TestRunner } from '@locustjs/test';
const tests = [
['test 1', () => expect(2 + 2).toBe(4)],
['test 2', () => expect(undefined).toBeUndefined()],
['test 3', () => expect(5).toBeGt(10)], // this test fails
...
];
const runner = new TestRunner();
await runner.run(tests);
runner.report(); // detailed report
runner.log(); // save report to file
Sample output:
Test 1: number: passed (0 sec)
Test 2: string: passed (0 sec)
Test 3: empty array: passed (0 sec)
Test 4: array: passed (0 sec)
Test 5: empty object: passed (0 sec)
Test 6: object: passed (0 sec)
Test 7: error: failed (0.001 sec)
Test 8: not satisfied: expect not used (0 sec)
Test 9: error without expect: faulted (0 sec)
expect did not succeed).expect was called).expect was seen.Pay attention: TestRunner runs test simultaneously. Thus, tests should not have side-effects.
import { Test, TestRunner } from '@locustjs/test';
const t1 = new Test('test 1', () => expect(2 + 2).toBe(4));
const t2 = () => expect(2 + 2).toBe(4);
const t3 = [t1]
const t4 = [t1, t2]
const t5 = ['test 5', () => expect(2 + 2).toBe(4)]
TestRunner.start(t1, t2, t3, t4, t5)
Positive
toBe(value)toBeGt(value)toBeGreaterThan(value)toBeGte(value)toBeGreaterThanOrEqualTo(value)toBeLt(value)toBeLowerThan(value)toBeLte(value)toBeLowerThanOrEqualTo(value)toBeBetween(n, m)toBeOfType(type)toBeString()toBeSomeString()toBeNumber()toBeNumeric()toBeDate()toBeBool()toBeBasicType()toBePrimitive()toBeEmpty()toBeObject()toBeSomeObject()toBeFunction()toBeArray()toBeEmptyArray()toBeSomeArray()toBeIterable()toBeSubClassOf(type)toBeInstanceOf(type)toMatch(pattern, flags)toBeDefined()toBeUndefined()toBeNull()toBeNullOrUndefined()toBeValid(fnValidation)toThrow()toThrow(ex, shape = false, strict = false)async toThrowAsync()async toThrowAsync(ex, shape = false, strict = false)toBeTruthy()toBeTrue()toBeFalsy()toBeFalse()toBeNaN()Negative
notToBe(value)notToBeBetween(n, m)notToBeOfType(type)notToBeString()notToBeSomeString()notToBeNumber()notToBeDate()notToBeBool()notToBeBasicType()notToBePrimitive()notToBeEmpty()notToBeObject()notToBeSomeObject()notToBeFunction()notToBeNumeric()notToBeArray()notToBeSomeArray()notToBeIterable()notToBeSubClassOf(type)notToBeInstanceOf(type)notToMatch(pattern, flags)doesNotMatch(pattern, flags)notToBeDefined()notToBeUndefined()notToBeNull()notToBeNullOrUndefined()notToBeValid(fnValidation)notToThrow()notToThrow(ex, shape = false, strict = false)async notToThrowAsync()async notToThrowAsync(ex, shape = false, strict = false)notToBeNaN()TestRunner has a static method start() that simplifies running tests.
const tests = [
...
];
TestRunner.start(tests);
It is possible to pass multiple tests to start() method.
import tests1 from './test1.js'
import tests2 from './test2.js'
import tests3 from './test3.js'
TestRunner.start(tests1, tests2, tests3);
The above example is equal to merging all tests and pass one array to start().
TestRunner.start([...tests1, ...tests2, ...tests3])
By default, test runner shows detailed output only when there is at least one error. However, by passing true as the last argument of start() method, we can ask the detailed output to be always shown.
TestRunner.start(tests, true);
TestRunner.start(tests1, tests2, tests3, true);
FAQs
This library provides a simple test runner for unit-testing.
We found that @locustjs/test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.