-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (68 loc) · 1.81 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
var process = require('./lib/process-adapter');
var serializeError = require('./lib/serialize-error');
var globals = require('./lib/globals');
var Runner = require('./lib/runner');
var send = process.send;
var opts = globals.options;
var runner = new Runner({
serial: opts.serial,
bail: opts.failFast,
match: opts.match
});
// note that test files have require('ava')
require('./lib/test-worker').avaRequired = true;
// if fail-fast is enabled, use this variable to detect
// that no more tests should be logged
var isFailed = false;
Error.stackTraceLimit = Infinity;
function test(props) {
if (isFailed) {
return;
}
var 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;
}
send('test', props);
if (hasError && opts.failFast) {
isFailed = true;
exit();
}
}
function exit() {
var stats = runner._buildStats();
send('results', {
stats: stats
});
}
globals.setImmediate(function () {
var hasExclusive = runner.tests.hasExclusive;
var numberOfTests = runner.tests.tests.concurrent.length + runner.tests.tests.serial.length;
if (numberOfTests === 0) {
send('no-tests', {avaRequired: true});
return;
}
send('stats', {
testCount: numberOfTests,
hasExclusive: hasExclusive
});
runner.on('test', test);
process.on('ava-run', function (options) {
runner.run(options).then(exit);
});
process.on('ava-init-exit', function () {
exit();
});
});
module.exports = runner.test;
// 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.test;