Add support for running test-js-with-node on particular files.

Fixed: #1127.
This commit is contained in:
Tomasz Kolek 2016-07-06 19:57:17 +02:00 committed by Tim Abbott
parent 3e9349df4f
commit c15695e514
4 changed files with 39 additions and 7 deletions

View File

@ -1311,7 +1311,7 @@ time debugging a test failure, e.g.:
./tools/lint-all # Runs all the linters in parallel ./tools/lint-all # Runs all the linters in parallel
./tools/test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube ./tools/test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube
./tools/test-js-with-casper 09-navigation.js ./tools/test-js-with-casper 09-navigation.js
./tools/test-js-with-node # Runs all node tests but is very fast ./tools/test-js-with-node util.js
``` ```
The above setup instructions include the first-time setup of test The above setup instructions include the first-time setup of test

View File

@ -27,7 +27,7 @@ time debugging a test failure, e.g.:
./tools/lint-all # Runs all the linters in parallel ./tools/lint-all # Runs all the linters in parallel
./tools/test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube ./tools/test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube
./tools/test-js-with-casper 09-navigation.js ./tools/test-js-with-casper 09-navigation.js
./tools/test-js-with-node # Runs all node tests but is very fast ./tools/test-js-with-node utils.js
``` ```
### Schema and initial data changes ### Schema and initial data changes

View File

@ -10,13 +10,27 @@ var _ = global._;
// Run all the JS scripts in our test directory. Tests do NOT run // Run all the JS scripts in our test directory. Tests do NOT run
// in isolation. // in isolation.
var oneFileFilter = [];
var testsDifference = [];
if (process.argv[2] ) {
oneFileFilter = process.argv
.slice(2)
.map(function (filename) {return filename.replace(/\.js$/i, '');});
}
var tests = fs.readdirSync(__dirname) var tests = fs.readdirSync(__dirname)
.filter(function (filename) { return (/\.js$/i).test(filename); }) .filter(function (filename) {return (/\.js$/i).test(filename);})
.map(function (filename) { return filename.replace(/\.js$/i, ''); }); .map(function (filename) {return filename.replace(/\.js$/i, '');});
if (oneFileFilter.length > 0) {
tests = tests.filter(function (filename) {
return oneFileFilter.indexOf(filename) !== -1;
});
testsDifference = _.difference(oneFileFilter, tests);
}
tests.sort(); tests.sort();
var dependencies = []; var dependencies = [];
var old_builtins = {}; var old_builtins = {};
@ -109,4 +123,13 @@ tests.forEach(function (filename) {
old_builtins = {}; old_builtins = {};
}); });
console.info("To see more output, open " + output_fn); if (oneFileFilter.length > 0 && testsDifference.length > 0) {
testsDifference.forEach(function (filename) {
console.log(filename + " does not exist");
});
if (oneFileFilter.length > testsDifference.length) {
console.info("To see more output, open " + output_fn);
}
} else {
console.info("To see more output, open " + output_fn);
}

View File

@ -10,8 +10,17 @@ NODEJS=$(which nodejs || which node)
if [ "$1" = "cover" ]; then if [ "$1" = "cover" ]; then
# Run a coverage test with Istanbul. # Run a coverage test with Istanbul.
istanbul cover "$INDEX_JS" istanbul cover "$INDEX_JS"
elif [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage:
`basename $0` - to run all tests
`basename $0` util.js - to run tests from util.js
`basename $0` util.js activity.js - to run tests from util.js and activity.js
"
exit 0
else else
# Normal testing, no coverage analysis. # Normal testing, no coverage analysis.
# Run the index.js test runner, which runs all the other tests. # Run the index.js test runner, which runs all the other tests.
"$NODEJS" --stack-trace-limit=100 "$INDEX_JS" "$NODEJS" --stack-trace-limit=100 "$INDEX_JS" $@
fi fi