-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
124 lines (111 loc) · 4.35 KB
/
gulpfile.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
112
113
114
115
116
117
118
119
120
121
122
123
124
var
// Built in packages.
spawn = require('child_process').spawn,
// Generic npm packages.
async = require('async'),
del = require('del'),
index = require('serve-index'),
// The gulp related plugins.
gulp = require('gulp'),
serve = require('gulp-serve'),
tap = require('gulp-tap'),
// The port on which the local server should serve up the reports on.
port = 3333,
// The folder contetnts that needs to be deleted each time the tests start
del_files_reportsDir = 'Reports/Cross_Device_Specs_Reports/*',
// The folder in which the generated reports should be saved to.
reportsDir = 'Reports/Cross_Device_Specs_Reports/',
// A `glob` for where the Galen test suites can be found.
suitesGlob = 'Suites/Cross_Devices/CGU_Suite.test';
// Clean out the directory where the reports will be saved to. This is done so
// as not to pollute the reports directory with old/potentially unwanted files.
gulp.task('clean', function (done) {
del([del_files_reportsDir], function (err) {
if (err) {
throw err;
}
done();
});
});
// This is the task that will kick off running all the Galen test suites.
gulp.task('test', ['clean'], function (done) {
var
// Here we create an empty Array to store vinyl File Objects.
files = [],
// Here we define a simple utility Function that we will call to
// execute the Galen specs.
galen = function galen (file, callback) {
spawn('galen', [
'test',
file.path,
'--htmlreport',
reportsDir + '/' + file.relative.replace(/\.test/, '')
], {'stdio' : 'inherit'}).on('close', function (code) {
callback(code === 0);
});
};
// Here we source our suites and immediately pass them to `gulp-tap`. The
// `gulp-tap` plugin allows you to "tap into" each file that is streamed
// into the pipe. We use this functionality to build up the `files` Array
// and populate it with vinyl File Objects.
//
// Once `gulp-tap` has finished
// doing its thing, we listen to the `end` event and then pass off the built
// up `files` Array to `async.mapSeries`.
//
// This will sequentially iterate through the Array perform the first
// callback and then when all items in the Array have been iterated over, it
// will perform the next callback.
//
// The next callback executes the `done()` handler that tells gulp that we
// are finished with this task and that we are good to continue with
// whichever task in next in the queue.
gulp.src([suitesGlob])
.pipe(tap(function (file) {
files.push(file);
}))
.on('end', function () {
async.rejectSeries(files, function (file, finished) {
galen(file, finished);
}, function (errors) {
if (errors && errors.length > 0) {
done("Galen reported failed tests: " + (errors.map(function(f) {
return f.relative;
}).join(", ")));
}
else {
done();
}
});
});
});
// Here we define a task to serve up the generated reports. This allows the
// generated HTML to be easily viewed in the browser, simply navigate to
// `http://localhost:[port]`. The value for the port is defined at the top of
// this file.
//
// This task requires that the `test` task is run first. This is so Galen can
// generate the required reports and present us with the files to display.
gulp.task('serve', ['test'], serve({
'middleware' : function (req, res, next) {
index(reportsDir, {
'filter' : false,
'hidden' : true,
'icons' : true,
'stylesheet' : false,
'template' : false,
'view' : 'details'
})(req, res, next);
},
'port' : port,
'root' : reportsDir
}));
// And lastly, we define a `default` task to kick off if `gulp` is called with
// no additional arguments.
//
// If this happens, we then kick off the `serve` task which will in turn kick
// off the `test` task.
//
// Once this is all complete you can navigate to localhost in your browser and
// see the results of the tests.
gulp.task('default', ['serve']);