forked from dtinth/gulp-cucumber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (49 loc) · 1.5 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
var through2 = require('through2');
var glob = require('simple-glob');
var fs = require('fs');
var Cucumber = require('cucumber');
var cucumber = function(options) {
var runOptions = [];
// load support files and step_definitions from options
var files = [];
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) {
var code = succeeded ? 0 : 1;
if (succeeded) {
callback()
stream.emit('end')
} else {
callback(new Error("Cucumber tests failed!"))
}
process.exit(code);
})
};
return through2.obj(collect, run);
};
module.exports = cucumber;