forked from mrooding/gulp-protractor-cucumber-html-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (53 loc) · 2.02 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
var through = require('through2'),
gutil = require('gulp-util'),
formatter = require('./lib/html_formatter'),
path = require('path'),
fs = require('fs-extra'),
PluginError = gutil.PluginError;
var PLUGIN_NAME = 'gulp-protractor-cucumber-html-reporter';
function gulpProtractorCucumberHtmlReport(opts) {
var currentDir = __dirname;
opts = opts || {};
opts.templates = {
featureTemplate: path.join(currentDir, './templates/feature_template.html'),
headerTemplate: path.join(currentDir, './templates/header_template.html'),
reportTemplate: path.join(currentDir, './templates/report_template.html'),
scenarioTemplate: path.join(currentDir, './templates/scenario_template.html'),
stepTemplate: path.join(currentDir, './templates/step_template.html'),
screenshotTemplate: path.join(currentDir, './templates/screenshot_template.html')
};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
var fileName;
if (file.isBuffer()) {
if (!opts.dest) {
opts.dest = __dirname;
}
if (opts.filename) {
fileName = opts.filename;
}
else {
fileName = path.basename(gutil.replaceExtension(file.path, '.html'));
}
var testResults = JSON.parse(file.contents);
var output = path.join(opts.dest, fileName);
fs.open(output, 'w+', function (err, fd) {
if (err) {
fs.mkdirsSync(opts.dest);
fd = fs.openSync(output, 'w+');
}
fs.writeSync(fd, formatter.generateReport(testResults, opts.templates));
fs.copySync(path.join(__dirname, 'templates', 'assets'), path.join(opts.dest, 'assets'));
gutil.log(PLUGIN_NAME + ':', 'HTML report has been created in', gutil.colors.cyan(output));
cb(null, file);
});
} else {
throw new PluginError(PLUGIN_NAME, '[Error] Currently only buffers are supported');
}
});
}
// Exporting the plugin main function
module.exports = gulpProtractorCucumberHtmlReport;