Skip to content

Commit 4801750

Browse files
Add optional test coverage reports (#2517)
Co-authored-by: JesseCodeBones <[email protected]>
1 parent 99b7196 commit 4801750

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

.c8rc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"reporter": ["html", "text"],
3+
"reportsDirectory": "./coverage",
4+
"src": ["src"],
5+
"exclude": [
6+
"std/**/*",
7+
"tests/**/*",
8+
"dist/**/*",
9+
"bin/asinit.js",
10+
"lib/**/*",
11+
"scripts/**/*",
12+
"src/glue/wasm/**/*",
13+
"util/browser/**/*"
14+
],
15+
"clean": true,
16+
"exclude-after-remap": true
17+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ raw/
99
.idea
1010
cli/index.generated.js
1111
src/diagnosticMessages.generated.ts
12+
coverage/

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"lint": "eslint --max-warnings 0 --ext js . && eslint --max-warnings 0 --ext ts .",
7171
"build": "node scripts/build",
7272
"watch": "node scripts/build --watch",
73+
"coverage": "npx c8 -- npm test",
7374
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform",
7475
"test:parser": "node --enable-source-maps tests/parser",
7576
"test:compiler": "node --enable-source-maps --no-warnings tests/compiler",

tests/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ Features
116116

117117
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.
118118

119+
Coverage
120+
--------
121+
122+
An optional code coverage report can be generated by running
123+
124+
```
125+
$> npm install c8
126+
$> npm run coverage
127+
```
128+
129+
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/`.
130+
119131
Other
120132
-----
121133

tests/compiler.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,9 @@ function evaluateResult(failedTests, skippedTests) {
492492
}
493493
}
494494

495-
// Run tests in parallel if requested
496-
if (args.parallel && coreCount > 2) {
495+
// Run tests in parallel if requested (except with coverage)
496+
const isCoverage = process.env.NODE_V8_COVERAGE != null;
497+
if (!isCoverage && args.parallel && coreCount > 2) {
497498
if (cluster.isWorker) {
498499
process.on("message", msg => {
499500
if (msg.cmd != "run") throw Error("invalid command: " + JSON.stringify(msg));

0 commit comments

Comments
 (0)