-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
102 lines (88 loc) · 3.04 KB
/
index.js
File metadata and controls
102 lines (88 loc) · 3.04 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var q = require('q'),
path = require('path'),
glob = require('glob'),
assign = require('object-assign'),
debug = require('debug')('protractor-cucumber-framework'),
Cucumber = require('cucumber'),
state = require('./lib/runState');
/**
* Execute the Runner's test cases through Cucumber.
*
* @param {Runner} runner The current Protractor Runner.
* @param {Array} specs Array of Directory Path Strings.
* @return {q.Promise} Promise resolved with the test results
*/
exports.run = function(runner, specs) {
var results = {};
return runner.runTestPreparer().then(function() {
var config = runner.getConfig();
var opts = assign({}, config.cucumberOpts, config.capabilities.cucumberOpts);
state.initialize(runner, results, opts.strict);
return q.promise(function(resolve, reject) {
var cliArguments = convertOptionsToCliArguments(opts);
cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js'));
cliArguments = cliArguments.concat(specs);
debug('cucumber command: "' + cliArguments.join(' ') + '"');
Cucumber.Cli(cliArguments).run(function (isSuccessful) {
try {
var complete = q();
if (runner.getConfig().onComplete) {
complete = q(runner.getConfig().onComplete());
}
complete.then(function() {
resolve(results);
});
} catch (err) {
reject(err);
}
});
});
});
function convertOptionsToCliArguments(options) {
var cliArguments = ['node', 'cucumberjs'];
for (var option in options) {
var cliArgumentValues = convertOptionValueToCliValues(option, options[option]);
if (Array.isArray(cliArgumentValues)) {
cliArgumentValues.forEach(function (value) {
cliArguments.push('--' + option, value);
});
} else if (cliArgumentValues) {
cliArguments.push('--' + option);
}
}
return cliArguments;
}
function convertRequireOptionValuesToCliValues(values) {
var configDir = runner.getConfig().configDir;
return toArray(values).map(function(path) {
// Handle glob matching
return glob.sync(path, {cwd: configDir});
}).reduce(function(opts, globPaths) {
// Combine paths into flattened array
return opts.concat(globPaths);
}, []).map(function(requirePath) {
// Resolve require absolute path
return path.resolve(configDir, requirePath);
}).filter(function(item, pos, orig) {
// Make sure requires are unique
return orig.indexOf(item) == pos;
});
}
function convertGenericOptionValuesToCliValues(values) {
if (values === true || !values) {
return values;
} else {
return toArray(values);
}
}
function convertOptionValueToCliValues(option, values) {
if (option === 'require') {
return convertRequireOptionValuesToCliValues(values);
} else {
return convertGenericOptionValuesToCliValues(values);
}
}
function toArray(values) {
return Array.isArray(values) ? values : [values];
}
};