ava 0.16.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.js +297 -265
- package/cli.js +15 -179
- package/index.js +5 -98
- package/index.js.flow +201 -0
- package/lib/assert.js +87 -53
- package/lib/ava-error.js +4 -8
- package/lib/ava-files.js +282 -0
- package/lib/babel-config.js +35 -73
- package/lib/beautify-stack.js +17 -16
- package/lib/caching-precompiler.js +72 -87
- package/lib/cli.js +181 -0
- package/lib/code-excerpt.js +57 -0
- package/lib/colors.js +6 -2
- package/lib/concurrent.js +62 -75
- package/lib/enhance-assert.js +57 -49
- package/lib/extract-stack.js +10 -0
- package/lib/fork.js +67 -68
- package/lib/format-assert-error.js +72 -0
- package/lib/globals.js +3 -8
- package/lib/hook.js +15 -20
- package/lib/logger.js +59 -82
- package/lib/main.js +90 -0
- package/lib/prefix-title.js +21 -0
- package/lib/process-adapter.js +108 -0
- package/lib/reporters/mini.js +260 -257
- package/lib/reporters/tap.js +80 -85
- package/lib/reporters/verbose.js +142 -115
- package/lib/run-status.js +110 -152
- package/lib/runner.js +125 -137
- package/lib/sequence.js +68 -84
- package/lib/serialize-error.js +68 -4
- package/lib/snapshot-state.js +30 -0
- package/lib/test-collection.js +144 -156
- package/lib/test-worker.js +45 -95
- package/lib/test.js +289 -318
- package/lib/throws-helper.js +9 -9
- package/lib/validate-test.js +48 -0
- package/lib/watcher.js +258 -297
- package/package.json +63 -53
- package/profile.js +68 -55
- package/readme.md +215 -101
- package/types/generated.d.ts +848 -228
- package/types/make.js +54 -23
- package/lib/send.js +0 -16
package/lib/logger.js
CHANGED
|
@@ -1,104 +1,81 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
const autoBind = require('auto-bind');
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Logger {
|
|
5
|
+
constructor(reporter) {
|
|
6
|
+
this.reporter = reporter;
|
|
7
|
+
autoBind(this);
|
|
6
8
|
}
|
|
9
|
+
start(runStatus) {
|
|
10
|
+
if (!this.reporter.start) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
this[key] = this[key].bind(this);
|
|
10
|
-
}, this);
|
|
11
|
-
|
|
12
|
-
this.reporter = reporter;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = Logger;
|
|
16
|
-
|
|
17
|
-
Logger.prototype.start = function (runStatus) {
|
|
18
|
-
if (!this.reporter.start) {
|
|
19
|
-
return;
|
|
14
|
+
this.write(this.reporter.start(runStatus), runStatus);
|
|
20
15
|
}
|
|
16
|
+
reset(runStatus) {
|
|
17
|
+
if (!this.reporter.reset) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
Logger.prototype.reset = function (runStatus) {
|
|
26
|
-
if (!this.reporter.reset) {
|
|
27
|
-
return;
|
|
21
|
+
this.write(this.reporter.reset(runStatus), runStatus);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
Logger.prototype.test = function (test, runStatus) {
|
|
34
|
-
this.write(this.reporter.test(test, runStatus), runStatus);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
Logger.prototype.unhandledError = function (err, runStatus) {
|
|
38
|
-
if (!this.reporter.unhandledError) {
|
|
39
|
-
return;
|
|
23
|
+
test(test, runStatus) {
|
|
24
|
+
this.write(this.reporter.test(test, runStatus), runStatus);
|
|
40
25
|
}
|
|
26
|
+
unhandledError(err, runStatus) {
|
|
27
|
+
if (!this.reporter.unhandledError) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
Logger.prototype.finish = function (runStatus) {
|
|
46
|
-
if (!this.reporter.finish) {
|
|
47
|
-
return;
|
|
31
|
+
this.write(this.reporter.unhandledError(err, runStatus), runStatus);
|
|
48
32
|
}
|
|
33
|
+
finish(runStatus) {
|
|
34
|
+
if (!this.reporter.finish) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
Logger.prototype.section = function () {
|
|
54
|
-
if (!this.reporter.section) {
|
|
55
|
-
return;
|
|
38
|
+
this.write(this.reporter.finish(runStatus), runStatus);
|
|
56
39
|
}
|
|
40
|
+
section() {
|
|
41
|
+
if (!this.reporter.section) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
57
44
|
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
Logger.prototype.clear = function () {
|
|
62
|
-
if (!this.reporter.clear) {
|
|
63
|
-
return false;
|
|
45
|
+
this.write(this.reporter.section());
|
|
64
46
|
}
|
|
47
|
+
clear() {
|
|
48
|
+
if (!this.reporter.clear) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
65
51
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
Logger.prototype.write = function (str, runStatus) {
|
|
71
|
-
if (typeof str === 'undefined') {
|
|
72
|
-
return;
|
|
52
|
+
this.write(this.reporter.clear());
|
|
53
|
+
return true;
|
|
73
54
|
}
|
|
55
|
+
write(str, runStatus) {
|
|
56
|
+
if (typeof str === 'undefined') {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
74
59
|
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
Logger.prototype.stdout = function (data, runStatus) {
|
|
79
|
-
if (!this.reporter.stdout) {
|
|
80
|
-
return;
|
|
60
|
+
this.reporter.write(str, runStatus);
|
|
81
61
|
}
|
|
62
|
+
stdout(data, runStatus) {
|
|
63
|
+
if (!this.reporter.stdout) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
82
66
|
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
Logger.prototype.stderr = function (data, runStatus) {
|
|
87
|
-
if (!this.reporter.stderr) {
|
|
88
|
-
return;
|
|
67
|
+
this.reporter.stdout(data, runStatus);
|
|
89
68
|
}
|
|
69
|
+
stderr(data, runStatus) {
|
|
70
|
+
if (!this.reporter.stderr) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
90
73
|
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
process.stdout.write('');
|
|
98
|
-
process.stderr.write('');
|
|
74
|
+
this.reporter.stderr(data, runStatus);
|
|
75
|
+
}
|
|
76
|
+
exit(code) {
|
|
77
|
+
process.exit(code); // eslint-disable-line unicorn/no-process-exit
|
|
78
|
+
}
|
|
79
|
+
}
|
|
99
80
|
|
|
100
|
-
|
|
101
|
-
setTimeout(function () {
|
|
102
|
-
process.exit(code); // eslint-disable-line xo/no-process-exit
|
|
103
|
-
}, process.env.AVA_APPVEYOR ? 500 : 0);
|
|
104
|
-
};
|
|
81
|
+
module.exports = Logger;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const process = require('./process-adapter');
|
|
3
|
+
const serializeError = require('./serialize-error');
|
|
4
|
+
const globals = require('./globals');
|
|
5
|
+
const Runner = require('./runner');
|
|
6
|
+
const send = process.send;
|
|
7
|
+
|
|
8
|
+
const opts = globals.options;
|
|
9
|
+
const runner = new Runner({
|
|
10
|
+
serial: opts.serial,
|
|
11
|
+
bail: opts.failFast,
|
|
12
|
+
match: opts.match
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Note that test files have require('ava')
|
|
16
|
+
require('./test-worker').avaRequired = true;
|
|
17
|
+
|
|
18
|
+
// If fail-fast is enabled, use this variable to detect
|
|
19
|
+
// that no more tests should be logged
|
|
20
|
+
let isFailed = false;
|
|
21
|
+
|
|
22
|
+
Error.stackTraceLimit = Infinity;
|
|
23
|
+
|
|
24
|
+
function test(props) {
|
|
25
|
+
if (isFailed) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const hasError = typeof props.error !== 'undefined';
|
|
30
|
+
|
|
31
|
+
// Don't display anything if it's a passed hook
|
|
32
|
+
if (!hasError && props.type !== 'test') {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (hasError) {
|
|
37
|
+
props.error = serializeError(props.error);
|
|
38
|
+
} else {
|
|
39
|
+
props.error = null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
send('test', props);
|
|
43
|
+
|
|
44
|
+
if (hasError && opts.failFast) {
|
|
45
|
+
isFailed = true;
|
|
46
|
+
exit();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function exit() {
|
|
51
|
+
const stats = runner._buildStats();
|
|
52
|
+
|
|
53
|
+
send('results', {stats});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
globals.setImmediate(() => {
|
|
57
|
+
const hasExclusive = runner.tests.hasExclusive;
|
|
58
|
+
const numberOfTests = runner.tests.testCount;
|
|
59
|
+
|
|
60
|
+
if (numberOfTests === 0) {
|
|
61
|
+
send('no-tests', {avaRequired: true});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
send('stats', {
|
|
66
|
+
testCount: numberOfTests,
|
|
67
|
+
hasExclusive
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
runner.on('test', test);
|
|
71
|
+
|
|
72
|
+
process.on('ava-run', options => {
|
|
73
|
+
runner.run(options)
|
|
74
|
+
.then(exit)
|
|
75
|
+
.catch(err => {
|
|
76
|
+
process.emit('uncaughtException', err);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
process.on('ava-init-exit', () => {
|
|
81
|
+
exit();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
module.exports = runner.test;
|
|
86
|
+
|
|
87
|
+
// TypeScript imports the `default` property for
|
|
88
|
+
// an ES2015 default import (`import test from 'ava'`)
|
|
89
|
+
// See: https://github.com/Microsoft/TypeScript/issues/2242#issuecomment-83694181
|
|
90
|
+
module.exports.default = runner.test;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports = (file, base, separator) => {
|
|
5
|
+
let prefix = file
|
|
6
|
+
// Only replace this.base if it is found at the start of the path
|
|
7
|
+
.replace(base, (match, offset) => offset === 0 ? '' : match)
|
|
8
|
+
.replace(/\.spec/, '')
|
|
9
|
+
.replace(/\.test/, '')
|
|
10
|
+
.replace(/test-/g, '')
|
|
11
|
+
.replace(/\.js$/, '')
|
|
12
|
+
.split(path.sep)
|
|
13
|
+
.filter(p => p !== '__tests__')
|
|
14
|
+
.join(separator);
|
|
15
|
+
|
|
16
|
+
if (prefix.length > 0) {
|
|
17
|
+
prefix += separator;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return prefix;
|
|
21
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const sourceMapSupport = require('source-map-support');
|
|
6
|
+
const installPrecompiler = require('require-precompiled');
|
|
7
|
+
|
|
8
|
+
const debug = require('debug')('ava');
|
|
9
|
+
|
|
10
|
+
// Check if the test is being run without AVA cli
|
|
11
|
+
const isForked = typeof process.send === 'function';
|
|
12
|
+
|
|
13
|
+
if (!isForked) {
|
|
14
|
+
const fp = path.relative('.', process.argv[1]);
|
|
15
|
+
|
|
16
|
+
console.log();
|
|
17
|
+
console.error('Test files must be run with the AVA CLI:\n\n ' + chalk.grey.dim('$') + ' ' + chalk.cyan('ava ' + fp) + '\n');
|
|
18
|
+
|
|
19
|
+
process.exit(1); // eslint-disable-line unicorn/no-process-exit
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.send = (name, data) => {
|
|
23
|
+
process.send({
|
|
24
|
+
name: `ava-${name}`,
|
|
25
|
+
data,
|
|
26
|
+
ava: true
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.on = process.on.bind(process);
|
|
31
|
+
exports.emit = process.emit.bind(process);
|
|
32
|
+
exports.exit = process.exit.bind(process);
|
|
33
|
+
exports.env = process.env;
|
|
34
|
+
|
|
35
|
+
const opts = exports.opts = JSON.parse(process.argv[2]);
|
|
36
|
+
|
|
37
|
+
// Fake TTY support
|
|
38
|
+
if (opts.tty) {
|
|
39
|
+
process.stdout.isTTY = true;
|
|
40
|
+
process.stdout.columns = opts.tty.columns || 80;
|
|
41
|
+
process.stdout.rows = opts.tty.rows;
|
|
42
|
+
|
|
43
|
+
const tty = require('tty');
|
|
44
|
+
const isatty = tty.isatty;
|
|
45
|
+
|
|
46
|
+
tty.isatty = function (fd) {
|
|
47
|
+
if (fd === 1 || fd === process.stdout) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return isatty(fd);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (debug.enabled) {
|
|
56
|
+
// Forward the `time-require` `--sorted` flag.
|
|
57
|
+
// Intended for internal optimization tests only.
|
|
58
|
+
if (opts._sorted) {
|
|
59
|
+
process.argv.push('--sorted');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
require('time-require'); // eslint-disable-line import/no-unassigned-import
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const sourceMapCache = new Map();
|
|
66
|
+
const cacheDir = opts.cacheDir;
|
|
67
|
+
|
|
68
|
+
exports.installSourceMapSupport = () => {
|
|
69
|
+
sourceMapSupport.install({
|
|
70
|
+
environment: 'node',
|
|
71
|
+
handleUncaughtExceptions: false,
|
|
72
|
+
retrieveSourceMap(source) {
|
|
73
|
+
if (sourceMapCache.has(source)) {
|
|
74
|
+
return {
|
|
75
|
+
url: source,
|
|
76
|
+
map: fs.readFileSync(sourceMapCache.get(source), 'utf8')
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.installPrecompilerHook = () => {
|
|
84
|
+
installPrecompiler(filename => {
|
|
85
|
+
const precompiled = opts.precompiled[filename];
|
|
86
|
+
|
|
87
|
+
if (precompiled) {
|
|
88
|
+
sourceMapCache.set(filename, path.join(cacheDir, `${precompiled}.js.map`));
|
|
89
|
+
return fs.readFileSync(path.join(cacheDir, `${precompiled}.js`), 'utf8');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return null;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.installDependencyTracking = (dependencies, testPath) => {
|
|
97
|
+
Object.keys(require.extensions).forEach(ext => {
|
|
98
|
+
const wrappedHandler = require.extensions[ext];
|
|
99
|
+
|
|
100
|
+
require.extensions[ext] = (module, filename) => {
|
|
101
|
+
if (filename !== testPath) {
|
|
102
|
+
dependencies.push(filename);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
wrappedHandler(module, filename);
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
};
|