From c15695e5146aa3285cd7c0632ca42958784cefeb Mon Sep 17 00:00:00 2001 From: Tomasz Kolek Date: Wed, 6 Jul 2016 19:57:17 +0200 Subject: [PATCH] Add support for running test-js-with-node on particular files. Fixed: #1127. --- README.dev.md | 2 +- docs/testing.md | 2 +- frontend_tests/node_tests/index.js | 31 ++++++++++++++++++++++++++---- tools/test-js-with-node | 11 ++++++++++- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.dev.md b/README.dev.md index 6b35c86e07..91664be8a9 100644 --- a/README.dev.md +++ b/README.dev.md @@ -1311,7 +1311,7 @@ time debugging a test failure, e.g.: ./tools/lint-all # Runs all the linters in parallel ./tools/test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube ./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 diff --git a/docs/testing.md b/docs/testing.md index 89a636e8d2..098d47d640 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -27,7 +27,7 @@ time debugging a test failure, e.g.: ./tools/lint-all # Runs all the linters in parallel ./tools/test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube ./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 diff --git a/frontend_tests/node_tests/index.js b/frontend_tests/node_tests/index.js index 1e51f062ed..5d8ac7251c 100644 --- a/frontend_tests/node_tests/index.js +++ b/frontend_tests/node_tests/index.js @@ -10,13 +10,27 @@ var _ = global._; // Run all the JS scripts in our test directory. Tests do NOT run // 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) - .filter(function (filename) { return (/\.js$/i).test(filename); }) - .map(function (filename) { return filename.replace(/\.js$/i, ''); }); - + .filter(function (filename) {return (/\.js$/i).test(filename);}) + .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(); + var dependencies = []; var old_builtins = {}; @@ -109,4 +123,13 @@ tests.forEach(function (filename) { 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); +} diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 536dec74be..db998efb90 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -10,8 +10,17 @@ NODEJS=$(which nodejs || which node) if [ "$1" = "cover" ]; then # Run a coverage test with Istanbul. 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 # Normal testing, no coverage analysis. # 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