This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
67 lines (53 loc) · 1.82 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
var flatten = require('lodash.flatten');
var createTestCafe = require('testcafe');
var PluginError = require('plugin-error');
var through = require('through2');
var DEFAULT_REPORTER = 'spec';
function prepareReporters (reporters) {
reporters = flatten(reporters);
reporters.forEach(function (reporter) {
if (typeof reporter !== 'string')
reporter.name = reporter.name || DEFAULT_REPORTER;
});
return reporters;
}
module.exports = function gulpTestCafe (opts) {
opts.reporter = prepareReporters([opts.reporter]);
opts.src = [];
function onFile (file, enc, cb) {
if (file.isNull())
cb(null, file);
else if (file.isStream())
cb(new PluginError('gulp-testcafe', 'Streaming is not supported.'));
else {
opts.src.push(file.path);
cb(null, file);
}
}
function onStreamEnd (cb) {
var stream = this;
var testcafe = null;
createTestCafe(opts)
.then(function (tc) {
testcafe = tc;
var runner = testcafe.createRunner();
return runner.run(opts);
})
.then(function (failed) {
if (failed > 0)
stream.emit('error', new PluginError('gulp-testcafe', { message: failed + ' test(s) failed.' }));
// NOTE: for testing purposes
else
stream.emit('done');
})
.catch(function (err) {
stream.emit('error', new PluginError('gulp-testcafe', { message: err.message }));
})
.then(function () {
if (testcafe)
return testcafe.close();
})
.then(cb);
}
return through.obj(onFile, onStreamEnd);
};