Skip to content

Commit 399e7d0

Browse files
committed
Implement testRunner.js.
We need a convenient way to invoke nodeunit multiple times in independent processes. This testRunner runs the standard tests in the `test` and `test8` directory in on process, and then runs each of the files in testAsyncOptions, each in their own process. Perhaps I could have done this with a script, but it's unclear to me whether a shell style script would work on Windows. I expect this should be portable across all platforms.
1 parent 7280eb9 commit 399e7d0

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
"nan": "1.4.1"
3232
},
3333
"devDependencies": {
34-
"async": "~0.1.22",
34+
"async": "0.9.0",
35+
"chalk": "^1.0.0",
3536
"nodeunit": "0.9.0",
36-
"when": "~3.6.4"
37+
"when": "3.6.4"
3738
},
3839
"scripts": {
3940
"test": "nodeunit test test8",

testRunner.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// testRunner.js
2+
3+
// This is a custom test runner. All tests are run with nodeunit, but in separate
4+
// processes, which allows us to test java with different configuration options.
5+
6+
var async = require('async');
7+
var chalk = require('chalk');
8+
var childProcess = require('child_process');
9+
var glob = require('glob');
10+
var path = require('path');
11+
12+
var tests = glob.sync(path.join('testAsyncOptions', '*.js'));
13+
14+
tests.unshift('test test8'); // Arrange to run the primary tests first, in a single process
15+
16+
function runTest(testArgs, done) {
17+
var cmd = 'node_modules/.bin/nodeunit ' + testArgs;
18+
childProcess.exec(cmd, function (error, stdout, stderr) {
19+
// It appears that nodeunit merges error output into the stdout
20+
// so these three lines are probably useless.
21+
var errText = stderr.toString();
22+
if (errText !== '')
23+
console.error(chalk.bold.red(errText));
24+
25+
process.stdout.write(stdout.toString());
26+
done(error);
27+
});
28+
}
29+
30+
async.eachSeries(tests, runTest, function(err) {
31+
if (err) {
32+
console.error(chalk.bold.red(err));
33+
process.exit(1);
34+
}
35+
});

0 commit comments

Comments
 (0)