Skip to content

Add optional test coverage reports #2517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ raw/
.idea
cli/index.generated.js
src/diagnosticMessages.generated.ts
coverage/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A convenient HTML report is generated to `coverage/`.

Other
-----

Expand Down
5 changes: 3 additions & 2 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down