Add a Node.js-based test runner

There are no functional changes; you can still use the shell script
tools/test-js-with-node. It just delegates now to the new index.js to
iterate through all the other .js files in the test directory and run
them. This sets the stage for Istanbul to correctly compute test
coverage.

(imported from commit 6f521c78b7a314d010fa113f9c2c971ab999b637)
This commit is contained in:
Scott Feeney 2013-08-20 00:15:41 -04:00
parent b32219c8eb
commit 69efe2a695
2 changed files with 22 additions and 13 deletions

View File

@ -1,18 +1,10 @@
#!/bin/bash -e
cd "$(dirname "$0")"/../zerver/tests/frontend/node
cd "$(dirname "$0")"/..
STATIC_DIR=`python -c 'import os;print os.path.realpath("../../../../static")'`
export NODE_PATH=$STATIC_DIR
export NODE_PATH=static
# Run the index.js test runner, which runs all the other tests.
INDEX_JS=zerver/tests/frontend/node/index.js
NODEJS=$(which nodejs || which node)
# Run all the JS scripts in our test directory. The order that the scripts run in now
# is fairly arbitrary, as they run isolated from each other, and none of them are
# particularly slow.
for js_file in *.js
do
echo $js_file
$NODEJS $js_file
done
$NODEJS $INDEX_JS

View File

@ -0,0 +1,17 @@
var fs = require('fs');
// Run all the JS scripts in our test directory. The order that the scripts
// run in now is fairly arbitrary, as they run isolated from each other, and
// none of them are particularly slow.
var tests = fs.readdirSync(__dirname)
.filter(function (filename) { return (/\.js$/i).test(filename); })
.map(function (filename) { return filename.replace(/\.js$/i, ''); });
tests.forEach(function (filename) {
if (filename === 'index.js') {
return;
}
console.info('running tests for ' + filename);
require('./' + filename);
});