-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·115 lines (96 loc) · 2.4 KB
/
cli.js
File metadata and controls
executable file
·115 lines (96 loc) · 2.4 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env node
'use strict';
var debug = require('debug')('ava');
// Prefer the local installation of AVA.
var resolveFrom = require('resolve-from');
var localCLI = resolveFrom('.', 'ava/cli');
if (localCLI && localCLI !== __filename) {
debug('Using local install of AVA.');
require(localCLI);
return;
}
if (debug.enabled) {
require('time-require');
}
var meow = require('meow');
var updateNotifier = require('update-notifier');
var chalk = require('chalk');
var Promise = require('bluebird');
var log = require('./lib/logger');
var Api = require('./api');
// Bluebird specific
Promise.longStackTraces();
var cli = meow([
'Usage',
' ava [<file|folder|glob> ...]',
'',
'Options',
' --init Add AVA to your project',
' --fail-fast Stop after first test failure',
' --serial Run tests serially',
'',
'Examples',
' ava',
' ava test.js test2.js',
' ava test-*.js',
' ava --init',
' ava --init foo.js',
'',
'Default patterns when no arguments:',
'test.js test-*.js test/*.js'
], {
string: ['_'],
boolean: [
'fail-fast',
'serial'
]
});
updateNotifier({pkg: cli.pkg}).notify();
if (cli.flags.init) {
require('ava-init')();
return;
}
log.write();
var api = new Api(cli.input, {
failFast: cli.flags.failFast,
serial: cli.flags.serial
});
api.on('test', function (test) {
if (test.error) {
log.error(test.title, chalk.red(test.error.message));
} else {
// don't log it if there's only one file and one anonymous test
if (api.fileCount === 1 && api.testCount === 1 && test.title === '[anonymous]') {
return;
}
log.test(test);
}
});
api.on('error', function (data) {
log.unhandledError(data.type, data.file, data);
});
api.run()
.then(function () {
log.write();
log.report(api.passCount, api.failCount, api.rejectionCount, api.exceptionCount);
log.write();
if (api.failCount > 0) {
log.errors(api.errors);
}
process.stdout.write('');
flushIoAndExit(api.failCount > 0 || api.rejectionCount > 0 || api.exceptionCount > 0 ? 1 : 0);
})
.catch(function (err) {
log.error(err.message);
flushIoAndExit(1);
});
function flushIoAndExit(code) {
// TODO: figure out why this needs to be here to
// correctly flush the output when multiple test files
process.stdout.write('');
process.stderr.write('');
// timeout required to correctly flush IO on Node.js 0.10 on Windows
setTimeout(function () {
process.exit(code);
}, process.env.AVA_APPVEYOR ? 500 : 0);
}