aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ava/lib/main.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/ava/lib/main.js
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/ava/lib/main.js')
-rw-r--r--node_modules/ava/lib/main.js103
1 files changed, 103 insertions, 0 deletions
diff --git a/node_modules/ava/lib/main.js b/node_modules/ava/lib/main.js
new file mode 100644
index 000000000..52618e8b7
--- /dev/null
+++ b/node_modules/ava/lib/main.js
@@ -0,0 +1,103 @@
+'use strict';
+const worker = require('./test-worker');
+const adapter = require('./process-adapter');
+const serializeError = require('./serialize-error');
+const globals = require('./globals');
+const Runner = require('./runner');
+
+const opts = globals.options;
+const runner = new Runner({
+ bail: opts.failFast,
+ failWithoutAssertions: opts.failWithoutAssertions,
+ file: opts.file,
+ match: opts.match,
+ serial: opts.serial,
+ updateSnapshots: opts.updateSnapshots
+});
+
+worker.setRunner(runner);
+
+// If fail-fast is enabled, use this variable to detect
+// that no more tests should be logged
+let isFailed = false;
+
+Error.stackTraceLimit = Infinity;
+
+function test(props) {
+ if (isFailed) {
+ return;
+ }
+
+ const hasError = typeof props.error !== 'undefined';
+
+ // Don't display anything if it's a passed hook
+ if (!hasError && props.type !== 'test') {
+ return;
+ }
+
+ if (hasError) {
+ props.error = serializeError(props.error);
+ } else {
+ props.error = null;
+ }
+
+ adapter.send('test', props);
+
+ if (hasError && opts.failFast) {
+ isFailed = true;
+ exit();
+ }
+}
+
+function exit() {
+ // Reference the IPC channel now that tests have finished running.
+ adapter.ipcChannel.ref();
+
+ const stats = runner.buildStats();
+ adapter.send('results', {stats});
+}
+
+globals.setImmediate(() => {
+ const hasExclusive = runner.tests.hasExclusive;
+ const numberOfTests = runner.tests.testCount;
+
+ if (numberOfTests === 0) {
+ adapter.send('no-tests', {avaRequired: true});
+ return;
+ }
+
+ adapter.send('stats', {
+ testCount: numberOfTests,
+ hasExclusive
+ });
+
+ runner.on('test', test);
+
+ process.on('ava-run', options => {
+ // Unreference the IPC channel. This stops it from keeping the event loop
+ // busy, which means the `beforeExit` event can be used to detect when tests
+ // stall.
+ adapter.ipcChannel.unref();
+
+ runner.run(options)
+ .then(() => {
+ runner.saveSnapshotState();
+
+ return exit();
+ })
+ .catch(err => {
+ process.emit('uncaughtException', err);
+ });
+ });
+
+ process.on('ava-init-exit', () => {
+ exit();
+ });
+});
+
+module.exports = runner.chain;
+
+// TypeScript imports the `default` property for
+// an ES2015 default import (`import test from 'ava'`)
+// See: https://github.com/Microsoft/TypeScript/issues/2242#issuecomment-83694181
+module.exports.default = runner.chain;