-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
88 lines (74 loc) · 2.17 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
/*
*
* gulpfile.js */
var gulp = require('gulp'),
sys = require('sys'),
child_process = require('child_process'),
fs = require('fs');
gulp.task('mocha-clean', [], function (cb) {
"use strict";
fs.exists('spec/mocha-phantomjs/tests', function (exists) {
if (!exists) {
fs.mkdir('spec/mocha-phantomjs/tests', function (error) {
return error ? cb(error) :
(fs.exists('spec/mocha-phantomjs/tests/mocha-bundle.js') &&
fs.unlink('spec/mocha-phantomjs/tests/mocha-bundle.js',
function (error) {
cb(error);
}));
});
} else {
if (fs.exists('spec/mocha-phantomjs/tests/mocha-bundle.js')) {
fs.unlink('spec/mocha-phantomjs/tests/mocha-bundle.js',
function (error) {
cb(error);
});
} else {
cb();
}
}
});
});
gulp.task('mocha-bundle', ['mocha-clean'], function (cb) {
"use strict";
/*
* Can't seem to get browserifying multiple input files working
* with gulp in a nice way...neither can anybody else apparently:
*
* https://github.com/gulpjs/plugins/issues/47
*
* This solution is a bit of a sledgehammer, but at least it works.
*/
var exec = child_process.exec;
exec('node node_modules/browserify/bin/cmd.js' +
' spec/tests/*.js' +
' -o spec/mocha-phantomjs/tests/mocha-bundle.js',
function (error, stdout, stderr) {
sys.print('stdout: ' + stdout + '\n');
sys.print('stderr: ' + stderr + '\n');
cb(error);
});
});
gulp.task('mocha', ['mocha-bundle'], function (cb) {
"use strict";
var spawn = child_process.spawn,
address = 'localhost',
port = '8081',
http,
mocha_phantomjs;
http = spawn('node_modules/http-server/bin/http-server',
[ '-a', address, '-p', port], {
stdio: "inherit"
});
mocha_phantomjs =
spawn('node_modules/mocha-phantomjs/bin/mocha-phantomjs',
['http://' + address + ':' + port + '/spec/mocha-phantomjs'], {
stdio: "inherit"
});
mocha_phantomjs.on('close', function (code) {
http.kill(code ? 'SIGTERM' : 'SIGHUP');
});
http.on('close', function (code) {
cb(code);
});
});