forked from avajs/ava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·128 lines (110 loc) · 2.74 KB
/
cli.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env node
'use strict';
var debug = require('debug')('ava');
// Prefer the local installation of AVA.
var resolveCwd = require('resolve-cwd');
var localCLI = resolveCwd('ava/cli');
if (localCLI && localCLI !== __filename) {
debug('Using local install of AVA.');
require(localCLI);
return;
}
if (debug.enabled) {
require('time-require');
}
var updateNotifier = require('update-notifier');
var figures = require('figures');
var arrify = require('arrify');
var meow = require('meow');
var Promise = require('bluebird');
var pkgConf = require('pkg-conf');
var isCi = require('is-ci');
var colors = require('./lib/colors');
var verboseReporter = require('./lib/reporters/verbose');
var miniReporter = require('./lib/reporters/mini');
var tapReporter = require('./lib/reporters/tap');
var Logger = require('./lib/logger');
var Api = require('./api');
// Bluebird specific
Promise.longStackTraces();
var conf = pkgConf.sync('ava');
var cli = meow([
'Usage',
' ava [<file|folder|glob> ...]',
'',
'Options',
' --init Add AVA to your project',
' --fail-fast Stop after first test failure',
' --serial, -s Run tests serially',
' --require, -r Module to preload (Can be repeated)',
' --tap, -t Generate TAP output',
' --verbose, -v Enable verbose output',
' --no-cache Disable the transpiler cache',
'',
'Examples',
' ava',
' ava test.js test2.js',
' ava test-*.js',
' ava test',
' ava --init',
' ava --init foo.js',
'',
'Default patterns when no arguments:',
'test.js test-*.js test/**/*.js'
], {
string: [
'_',
'require'
],
boolean: [
'fail-fast',
'verbose',
'serial',
'tap'
],
default: conf,
alias: {
t: 'tap',
v: 'verbose',
r: 'require',
s: 'serial'
}
});
updateNotifier({pkg: cli.pkg}).notify();
if (cli.flags.init) {
require('ava-init')();
return;
}
var api = new Api(cli.input.length ? cli.input : arrify(conf.files), {
failFast: cli.flags.failFast,
serial: cli.flags.serial,
require: arrify(cli.flags.require),
cacheEnabled: cli.flags.cache !== false
});
var logger = new Logger();
logger.api = api;
if (cli.flags.tap) {
logger.use(tapReporter());
} else if (cli.flags.verbose || isCi) {
logger.use(verboseReporter());
} else {
logger.use(miniReporter());
}
logger.start();
api.on('test', logger.test);
api.on('error', logger.unhandledError);
api.on('stdout', logger.stdout);
api.on('stderr', logger.stderr);
api.run()
.then(function () {
logger.finish();
logger.exit(api.failCount > 0 || api.rejectionCount > 0 || api.exceptionCount > 0 ? 1 : 0);
})
.catch(function (err) {
if (err.name === 'AvaError') {
console.log(' ' + colors.error(figures.cross) + ' ' + err.message);
} else {
console.error(colors.stack(err.stack));
}
logger.exit(1);
});