TestQueue
Enqueue and run tests (optionally in parallel).
Methods
Properties
-
reporterReporter
Events
-
runStartRunStartInfo —emitted when the queue begins processing tests
-
runEndRunEndInfo —emitted when the queue finishes processing tests
-
testResultTestResultInfo —emitted when a test completes
-
errorError —emitted when an error occurs (not including test failures) when running tests
new TestQueue(reporter, options)
Creates a new TestQueue object and sets the this.reporter property.
-
reporterReporter —optional (if not defined, no output will be written but events will still fire)
-
optionsObject —optional
Examples
const {Tap, Reporter, TestQueue} = require('spooning');
const testQueue = new TestQueue(new Reporter(new Tap(), process.stdout));
push(name, test, callback)
alias:test,it
Enqueue a test. This should not be called after this.run.
Compatible with promisify.
This method is a context-bound version of the private method _push.
If a subclass needs to override, it should override the private method.
-
namestring —name of test
-
testfunction —test definition
-
callbackfunction —call to indicate test is complete
-
errorError|falsy —Error indicating failure reason (or falsy)
-
messageany —optional diagnostic message (or falsy)
-
-
-
callbackfunction —called when test has run (optional)
-
errorError|falsy —error indicating test failure (or falsy)
-
infoTestResultInfo
-
Examples
testQueue.push('Should pass', (callback) => {
setTimeout(() => {
callback(null, 'optional diagnostic message'); // pass
}, 100);
});
testQueue.push('Should fail', (callback) => {
setTimeout(() => {
callback(new Error('nope')); // fail
}, 100);
});
pushPromise(name, test, callback)
alias: swearEnqueue a Promise-based test. This should not be called after this.run.
Compatible with promisify.
This method is a context-bound version of the private method _pushPromise.
If a subclass needs to override, it should override the private method.
-
namestring —name of test
-
testfunction —test definition, returns
Promiseobject that resolves (with an optional diagnostic message of any type) or rejects (withError) to indicate pass/fail -
callbackfunction —called when test has run (optional)
-
errorError|falsy —error indicating test failure (or falsy)
-
infoTestResultInfo
-
Examples
testQueue.pushPromise('Should pass', () => new Promise((resove, reject) => {
setTimeout(() => {
resove('optional diagnostic message'); // pass
}, 100);
}));
testQueue.pushPromise('Should fail', () => new Promise((resove, reject) => {
setTimeout(() => {
reject(new Error('nope')); // fail
}, 100);
}));
pushSync(name, test, callback)
Enqueue a synchronous test. This should not be called after this.run.
Compatible with promisify.
This method is a context-bound version of the private method _pushSync.
If a subclass needs to override, it should override the private method.
-
namestring —name of test
-
testfunction —test definition, returns optional diagnostic message of any type (or falsy), throw an
Errorto indicate failure -
callbackfunction —called when test has run (optional)
-
errorError|falsy —error indicating test failure (or falsy)
-
infoTestResultInfo
-
Examples
testQueue.pushSync('Should pass', () => {
return 'optional diagnostic message'; // pass
});
testQueue.pushSync('Should pass', () => {
throw new Error('nope'); // fail
});
run(callback)
Run enqueued tests. This should only be called once.
Compatible with promisify.
This method is a context-bound version of the private method _run.
If a subclass needs to override, it should override the private method.
-
callbackfunction —called when all tests have run (optional)
-
errorError|falsy —Reporter error (an error encountered while reporting the result, not an error indicating test failure) that occurred (or falsy)
-
infoRunEndInfo
-
Examples
// exit the process when complete
testQueue.run(testQueue.exit);// provide a custom callback
testQueue.run((error, info) => {
// handle error/info
});
exit(error, info)
If error is not falsy, emit it.
Otherwise, exit the process with code determined by info.exitCode.
This method is a context-bound version of the private method _exit.
If a subclass needs to override, it should override the private method.
-
errorError|falsy -
infoRunEndInfo
Examples
// exit the process when complete
testQueue.run(testQueue.exit);
setAutoRun(isEnabled)
Enable/disable auto-run mode.
Tests will be executed as soon as they are defined (without waiting for this.run to be called).
When in auto-run mode, the runStart event does not fire and reporter.runStart is not called.
Also, the TAP plan (ex. “1..4”) is not included in the output.
This method is context-bound.
-
isEnabledbool
Examples
testQueue.setAutoRun(true);
setBail(isEnabled)
Enable/disable bail mode.
If true, the queue will drain after the first test failure
(when running tests in parallel, tests that are already running when the failure occurs may still complete).
This method is context-bound.
-
isEnabledbool
Examples
testQueue.setBail(true);
setConcurrency(n)
Set the number of tests to run in parallel.
This method is context-bound.
-
nnumber —max number of tests to run concurrently
Examples
testQueue.setConcurrency(10);