test-js-with-node: Simplify failures for --coverage.

When you use nyc, its code instrumentation transforms
the code so that line numbers and columns no longer
make sense, and the long stack trace is likely to cause
more confusion than convenience.

We want to encourage a workflow where you debug your
node tests using the normal (and much quicker mode)
before running `--coverage`.
This commit is contained in:
Steve Howell 2022-01-07 19:40:15 +00:00 committed by Steve Howell
parent e17ba5260a
commit dcffa17e29
2 changed files with 8 additions and 1 deletions

View File

@ -114,7 +114,13 @@ try {
namespace.finish();
}
} catch (error) {
if (error.stack) {
if (process.env.USING_INSTRUMENTED_CODE) {
console.info(`
TEST FAILED! Before using the --coverage option please make sure that your
tests work under normal conditions.
`);
} else if (error.stack) {
console.info(short_tb(error.stack));
} else {
console.info(error);

View File

@ -312,6 +312,7 @@ def run_tests_via_node_js() -> int:
node_tests_cmd += test_files
if options.coverage:
os.environ["USING_INSTRUMENTED_CODE"] = "TRUE"
coverage_dir = os.path.join(ROOT_DIR, "var/node-coverage")
nyc = os.path.join(ROOT_DIR, "node_modules/.bin/nyc")