testrunner.js
1.21 KB
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
#!/usr/bin/env node
var Mocha = require('mocha');
var path = require('path');
var fs = require('fs');
var spawn = require('child_process').spawn;
var argv = require('yargs').argv;
require('mocha-clean');
require('intelli-espower-loader');
var mocha = new Mocha({
ui: 'bdd',
reporter: argv.R || 'spec',
timeout: 20000,
grep: argv.g
});
var testDir = path.join(__dirname, 'test');
fs.readdirSync(testDir).filter(function (file) {
return /^[^_].*\.js$/.test(file);
}).forEach(function (file) {
mocha.addFile(path.join(testDir, file));
});
var server = spawn(process.execPath, [
path.join(__dirname, 'test/_server.js')
], {
detached: true
});
server.stdout.on('data', function (data) {
process.stdout.write(data);
});
server.stderr.on('data', function (data) {
if (data.toString().trim() === '%%% server ready %%%') {
// start mocha
mocha.run(function (failures) {
process.kill(server.pid);
process.exit(failures);
});
return;
}
process.stderr.write(data);
});
// Ctrl-C
var stdin = process.stdin;
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf-8');
stdin.on('data', function (key) {
if (key === '\u0003') {
process.kill(server.pid);
process.exit();
}
});