From dcffa17e292d51f6baf70a4b1006750659a9d842 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 7 Jan 2022 19:40:15 +0000 Subject: [PATCH] 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`. --- frontend_tests/zjsunit/index.js | 8 +++++++- tools/test-js-with-node | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index 46f81cc86a..98dfa25c99 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -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); diff --git a/tools/test-js-with-node b/tools/test-js-with-node index f7b808dd1d..ce0107cd1d 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -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")