-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
108 lines (83 loc) · 2.64 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
/*jshint node:true */
'use strict';
var map = require('map-stream'),
gutil = require('gulp-util'),
os = require('os'),
exec = require('child_process').exec;
module.exports = function(command, opt) {
var counter = 0;
var skipCmd = '';
if (typeof command === 'object') {
throw new gutil.PluginError("gulp-codeception", "Invalid Codeception Binary");
}
// if path to codecept bin not supplied, use default vendor/bin path
if(! command) {
command = './vendor/bin/codecept';
if (os.platform() === 'win32') {
command = '.\\vendor\\bin\\codecept';
}
}
// create default opt object if no options supplied
if ( ! opt) { opt = {}; }
// assign default options if one is not supplied
if (typeof opt.testSuite === 'undefined') { opt.testSuite = ''; }
if (typeof opt.silent === 'undefined') { opt.silent = false; }
if (typeof opt.debug === 'undefined') { opt.debug = false; }
if (typeof opt.testClass === 'undefined') { opt.testClass = ''; }
if (typeof opt.clear === 'undefined') { opt.clear = false; }
if (typeof opt.flags === 'undefined') { opt.flags = ''; }
if (typeof opt.notify === 'undefined') { opt.notify = false; }
if (typeof opt.build === 'undefined') { opt.build = false; }
if (typeof opt.skipSuites === 'undefined') { opt.skipSuites = ''; }
command = opt.build ? command += ' build' : command += ' run';
return map(function (file, cb) {
// construct command
var cmd = opt.clear ? 'clear && ' + command : command;
// assign default class and/or test suite
if (opt.testSuite) { cmd += ' ' + opt.testSuite; }
if (opt.testClass) { cmd += ' ' + opt.testClass; }
// check if user supplied one or more suites to skip
if (typeof opt.skipSuites === 'object') {
if (opt.skipSuites.length > 0) {
for( var i = 0; i < opt.skipSuites.length; i++ ) {
skipCmd += ' --skip ' + opt.skipSuites[i];
}
}
} else {
if (opt.skipSuites.length > 0) {
skipCmd = ' --skip ' + opt.skipSuites;
}
}
if(counter === 0) {
counter++;
// attach any flags
if (opt.debug && ! opt.build) {
opt.flags += ' --debug ';
}
cmd += skipCmd + ' ' + opt.flags;
cmd.trim(); // clean up any space remnants
if (opt.debug) {
gutil.log(gutil.colors.yellow('\n *** Debug Cmd: ' + cmd + '***\n'));
}
exec(cmd, function (error, stdout, stderr) {
if (!opt.silent && stderr) {
gutil.log(stderr);
}
if (stdout) {
stdout = stdout.trim(); // Trim trailing cr-lf
}
if (!opt.silent && stdout) {
gutil.log(stdout);
}
if(opt.debug && error) {
gutil.log(error);
}
if (opt.notify) {
cb(error, file);
} else {
cb(null, file);
}
});
}
});
};