forked from vgamula/gulp-cucumber
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
86 lines (68 loc) · 2.07 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var path = require('path');
var glob = require('simple-glob');
var through2 = require('through2');
var Cucumber = require('cucumber');
var clearFileCache = function(filePath) {
delete require.cache[require.resolve(path.resolve(filePath))];
}
module.exports = function(options) {
var files = [];
var runOptions = [];
var emitErrors = true;
if (options.support) {
files = files.concat(glob([].concat(options.support)));
}
if (options.steps) {
files = files.concat(glob([].concat(options.steps)));
}
files.forEach(function(file) {
clearFileCache(file);
runOptions.push('-r');
runOptions.push(file);
});
if (!options.format) {
options.format = 'pretty';
}
var formats = Array.isArray(options.format) ? options.format : [options.format];
formats.forEach(function(f) {
runOptions.push('--format');
runOptions.push(f);
});
if (options.tags) {
var tags = Array.isArray(options.tags) ? options.tags : [options.tags];
tags.forEach(function(t) {
runOptions.push('--tags');
runOptions.push(t);
});
}
if (options.compiler) {
runOptions.push('--compiler');
runOptions.push(options.compiler);
}
if (options.emitErrors === false) {
emitErrors = false;
}
var features = [];
var collect = function(file, enc, callback) {
var filename = file.path;
if (filename.indexOf('.feature') === -1) {
return callback();
}
features.push(filename);
callback();
};
var run = function() {
var argv = ['node', 'cucumber-js'];
argv.push.apply(argv, runOptions);
argv.push.apply(argv, features);
var stream = this;
Cucumber.Cli(argv).run(function(succeeded) {
if (succeeded || !emitErrors) {
stream.emit("end");
} else {
stream.emit("error", new Error('Cucumber tests failed!'));
}
});
};
return through2.obj(collect, run);
};