-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (40 loc) · 1.33 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
/**
* Copyright (c) 2016-present, lookly
* All rights reserved.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const Api = require('ava/api');
const glob = require('ultra-glob');
const gutil = require('gulp-util');
const Logger = require('ava/lib/logger');
const VerboseReporter = require('ava/lib/reporters/verbose');
const options = require('./options');
function runAva(globPatterns, config = {}) {
const reporter = new VerboseReporter({ color: true });
const api = new Api(Object.assign({}, options, config));
reporter.api = api;
const logger = new Logger(reporter);
logger.start();
api.on('test-run', runStatus => {
reporter.api = runStatus;
runStatus.on('test', logger.test);
runStatus.on('error', logger.unhandledError);
runStatus.on('stdout', logger.stdout);
runStatus.on('stderr', logger.stderr);
});
return glob(globPatterns)
.then(files => api.run(files))
.then(runStatus => {
logger.finish(runStatus);
if (runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount > 0) {
throw new gutil.PluginError({
message: new Error('ava detected errors'),
plugin: 'lookly-preset-ava',
});
}
});
}
module.exports = runAva;