forked from vgamula/gulp-cucumber
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (45 loc) · 1.35 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
var Cucumber = require('cucumber');
var glob = require('simple-glob');
var through2 = require('through2');
var cucumber = function(options) {
var files = [];
var runOptions = [];
if (options.support) {
files = files.concat(glob([].concat(options.support)));
}
if (options.steps) {
files = files.concat(glob([].concat(options.steps)));
}
files.forEach(function(file) {
runOptions.push('-r');
runOptions.push(file);
});
runOptions.push('-f');
var format = options.format || 'pretty';
runOptions.push(format);
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(callback) {
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) {
callback();
stream.emit('end');
} else {
callback(new Error("Cucumber tests failed!"));
}
});
};
return through2.obj(collect, run);
};
module.exports = cucumber;