-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
111 lines (104 loc) · 3.47 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const gutil = require('gulp-util');
const async = require('async');
const path = require('path');
const fs = require('fs');
const Chimp = require('chimp');
const reporter = require('cucumber-html-reporter');
const PLUGIN_NAME = 'gulp-chimp';
function createOutputFolder(pathOutput, cb) {
var e2eOutput = path.resolve(process.cwd() + pathOutput);
if (!fs.existsSync(e2eOutput)) {
fs.mkdirSync(e2eOutput);
fs.mkdirSync(e2eOutput + '/logs');
fs.mkdirSync(e2eOutput + '/report');
fs.mkdirSync(e2eOutput + '/screenshots');
}
cb();
}
function createCucumberReport(options, cb) {
reporter.generate({
theme: 'bootstrap',
jsonFile: options.htmlReport.jsonFile,
output: options.htmlReport.output,
reportSuiteAsScenarios: options.htmlReport.reportSuiteAsScenarios,
launchReport: options.htmlReport.launchReport
});
cb();
}
function runChimp(optionsGulp, cb) {
var options = require('./chimp.conf.js');
if (typeof optionsGulp === 'object') {
options.path = optionsGulp.features;
options.browser = optionsGulp.browser;
options.singleRun = optionsGulp.singleRun;
options.debug = optionsGulp.debug;
options.screenshotsPath = optionsGulp.output.screenshotsPath;
options.jsonOutput = optionsGulp.output.jsonOutput;
options.htmlReport = optionsGulp.htmlReport.enable;
options.jsonFile = optionsGulp.htmlReport.jsonFile;
options.output = optionsGulp.htmlReport.output;
options.reportSuiteAsScenarios = optionsGulp.htmlReport.reportSuiteAsScenarios;
options.launchReport = optionsGulp.htmlReport.launchReport;
} else {
var configFile = path.resolve(process.cwd() + '/' + optionsGulp);
options = require(configFile);
}
options._ = ['./node_modules/.bin/chimp.js'];
var chimp = new Chimp(options);
if (options.singleRun) {
chimp.run(function (err) {
if (err) {
console.log(err);
}
cb();
});
} else {
chimp.init(function (err) {
if (err) {
console.log(err);
}
cb();
});
}
}
function init(options) {
if (options === undefined) {
throw new gutil.PluginError(PLUGIN_NAME, 'Options is required!');
} else {
if (typeof options === 'object') {
async.series([
function (cb) {
createOutputFolder(options.pathOutput, cb);
},
function (cb) {
runChimp(options, cb);
},
function (cb) {
if (options.htmlReport.enable) {
createCucumberReport(options, cb);
} else {
cb();
}
}
]);
} else {
async.series([
function (cb) {
createOutputFolder(options.pathOutput, cb);
},
function (cb) {
runChimp(options, cb);
},
function (cb) {
options = require(path.resolve(process.cwd() + '/' + options));
if (options.htmlReport.enable) {
createCucumberReport(options, cb);
} else {
cb();
}
}
]);
}
}
}
module.exports = init;