From 25338ee38ff2c471ff7df9b018eceb7fbefa830e Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 22 Sep 2022 15:27:17 +0200 Subject: [PATCH 1/3] Add optional test coverage reports --- .c8rc.json | 17 +++++++++++++++++ .gitignore | 1 + package.json | 1 + tests/compiler.js | 5 +++-- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .c8rc.json diff --git a/.c8rc.json b/.c8rc.json new file mode 100644 index 0000000000..fde64f42b6 --- /dev/null +++ b/.c8rc.json @@ -0,0 +1,17 @@ +{ + "reporter": ["html", "text"], + "reportsDirectory": "./coverage", + "src": ["src"], + "exclude": [ + "std/**/*", + "tests/**/*", + "dist/**/*", + "bin/asinit.js", + "lib/**/*", + "scripts/**/*", + "src/glue/wasm/**/*", + "util/browser/**/*" + ], + "clean": true, + "exclude-after-remap": true +} diff --git a/.gitignore b/.gitignore index 98a3ba835b..3166d113d2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ raw/ .idea cli/index.generated.js src/diagnosticMessages.generated.ts +coverage/ diff --git a/package.json b/package.json index bc3bd45d64..6c93b22e33 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "lint": "eslint --max-warnings 0 --ext js . && eslint --max-warnings 0 --ext ts .", "build": "node scripts/build", "watch": "node scripts/build --watch", + "coverage": "npx c8 -- npm test", "test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform", "test:parser": "node --enable-source-maps tests/parser", "test:compiler": "node --enable-source-maps --no-warnings tests/compiler", diff --git a/tests/compiler.js b/tests/compiler.js index 84cf0928f7..5280a3e47a 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -492,8 +492,9 @@ function evaluateResult(failedTests, skippedTests) { } } -// Run tests in parallel if requested -if (args.parallel && coreCount > 2) { +// Run tests in parallel if requested (except with coverage) +const isCoverage = process.env.NODE_V8_COVERAGE != null; +if (!isCoverage && args.parallel && coreCount > 2) { if (cluster.isWorker) { process.on("message", msg => { if (msg.cmd != "run") throw Error("invalid command: " + JSON.stringify(msg)); From 2362eb70faa93aa78e5d14e8076241039697dc78 Mon Sep 17 00:00:00 2001 From: dcode Date: Fri, 23 Sep 2022 17:09:38 +0200 Subject: [PATCH 2/3] document --- tests/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/README.md b/tests/README.md index 3bbaef5656..b6e82e50a8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -116,6 +116,18 @@ Features Tests for experimental features (usually enabled via the `--enable` CLI flag) are disabled by default. To enable a feature, set the `ASC_FEATURES` environment variable to a comma-separated list of feature names (see [`features.json`](./features.json)). You can also set `ASC_FEATURES="*"` to enable all features. +Coverage +-------- + +An optional code coverage report can be generated by running + +``` +$> npm install c8 +$> npm run coverage +``` + +Code coverage runs the tests with [c8](https://github.com/bcoe/c8) using the JS variant of the compiler. It is expected that Wasm-only branches show as untaken. Make sure to enable all (relevant) [features](#features). + Other ----- From e41e8835d7a1486676cb6e19a78540e2dcffe1bc Mon Sep 17 00:00:00 2001 From: dcode Date: Fri, 23 Sep 2022 17:11:28 +0200 Subject: [PATCH 3/3] mention HTML report --- tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index b6e82e50a8..0163048a04 100644 --- a/tests/README.md +++ b/tests/README.md @@ -126,7 +126,7 @@ $> npm install c8 $> npm run coverage ``` -Code coverage runs the tests with [c8](https://github.com/bcoe/c8) using the JS variant of the compiler. It is expected that Wasm-only branches show as untaken. Make sure to enable all (relevant) [features](#features). +Code coverage runs the tests with [c8](https://github.com/bcoe/c8) using the JS variant of the compiler. It is expected that Wasm-only branches show as untaken. Make sure to enable all (relevant) [features](#features). A convenient HTML report is generated to `coverage/`. Other -----