Skip to content

Commit 0cae5d7

Browse files
authored
Merge pull request #3100 from Agoric/mfig-enable-coverage
Enable coverage reporting
2 parents 1de9ee6 + 464b464 commit 0cae5d7

46 files changed

Lines changed: 294 additions & 479 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ag-solo-xs.yml.DISABLED

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v2
1919
- uses: actions/setup-node@v1
2020
with:
21-
node-version: '12.14.1'
21+
node-version: '12.x'
2222
- name: cache node modules
2323
uses: actions/cache@v1
2424
with:

.github/workflows/test-all-packages.yml

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
node-version: ['12.14.1', '12.x', '14.x']
17+
node-version: ['12.x', '14.x']
1818
steps:
1919
- uses: actions/checkout@v2
2020
with:
@@ -117,6 +117,58 @@ jobs:
117117
name: benchmarkstats.json
118118
path: packages/swingset-runner/benchstats*.json
119119

120+
coverage:
121+
needs: build
122+
runs-on: ubuntu-latest
123+
strategy:
124+
matrix:
125+
node-version: ['14.x']
126+
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/master'}}
127+
steps:
128+
- uses: actions/setup-node@v1
129+
with:
130+
node-version: ${{ matrix.node-version }}
131+
# BEGIN-RESTORE-BOILERPLATE
132+
- name: restore built files
133+
id: built
134+
uses: actions/cache@v1
135+
with:
136+
path: .
137+
key: ${{ runner.os }}-${{ matrix.node-version }}-built-${{ github.sha }}
138+
- uses: actions/checkout@v2
139+
with:
140+
submodules: 'true'
141+
if: steps.built.outputs.cache-hit != 'true'
142+
- name: yarn install
143+
run: yarn install
144+
if: steps.built.outputs.cache-hit != 'true'
145+
- name: yarn build
146+
run: yarn build
147+
if: steps.built.outputs.cache-hit != 'true'
148+
# END-RESTORE-BOILERPLATE
149+
150+
- name: generate coverage for all tests
151+
run: 'yarn test:c8-all || :'
152+
- name: generate coverage/html reports
153+
run: yarn c8 report --reporter=html-spa --reports-dir=coverage/html --temp-directory=coverage/tmp
154+
- uses: actions/upload-artifact@v2
155+
with:
156+
name: coverage
157+
path: coverage
158+
- name: Find Netlify site ID
159+
run: |
160+
echo "NETLIFY_SITE_ID=$(cat COVERAGE_NETLIFY_SITE_ID)" >> $GITHUB_ENV
161+
162+
- uses: nwtgck/actions-netlify@v1.1
163+
with:
164+
# Production deployment if a commit to master.
165+
production-deploy: ${{ github.ref == 'refs/heads/master' }}
166+
publish-dir: coverage/html
167+
# SECURITY: we don't want to hand out the Github token to this action.
168+
# github-token: ${{ secrets.GITHUB_TOKEN }}
169+
env:
170+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
171+
120172
##################
121173
# Fast-running tests run as a group:
122174
test-quick:
@@ -125,7 +177,7 @@ jobs:
125177
runs-on: ubuntu-latest
126178
strategy:
127179
matrix:
128-
node-version: ['12.14.1', '12.x', '14.x']
180+
node-version: ['12.x', '14.x']
129181
steps:
130182
- uses: actions/setup-node@v1
131183
with:
@@ -254,7 +306,7 @@ jobs:
254306
runs-on: ubuntu-latest
255307
strategy:
256308
matrix:
257-
node-version: ['12.14.1', '12.x', '14.x']
309+
node-version: ['12.x', '14.x']
258310
steps:
259311
- uses: actions/setup-node@v1
260312
with:
@@ -320,7 +372,7 @@ jobs:
320372
runs-on: ubuntu-latest
321373
strategy:
322374
matrix:
323-
node-version: ['12.14.1', '12.x', '14.x']
375+
node-version: ['12.x', '14.x']
324376
steps:
325377
- uses: actions/setup-node@v1
326378
with:
@@ -358,7 +410,7 @@ jobs:
358410
runs-on: ubuntu-latest
359411
strategy:
360412
matrix:
361-
node-version: ['12.14.1', '12.x', '14.x']
413+
node-version: ['12.x', '14.x']
362414
steps:
363415
- uses: actions/setup-node@v1
364416
with:
@@ -405,7 +457,7 @@ jobs:
405457
runs-on: ubuntu-latest
406458
strategy:
407459
matrix:
408-
node-version: ['12.14.1', '12.x', '14.x']
460+
node-version: ['12.x', '14.x']
409461
steps:
410462
- uses: actions/setup-node@v1
411463
with:
@@ -450,7 +502,7 @@ jobs:
450502
runs-on: ubuntu-latest
451503
strategy:
452504
matrix:
453-
node-version: ['12.14.1', '12.x', '14.x']
505+
node-version: ['12.x', '14.x']
454506
steps:
455507
- uses: actions/setup-node@v1
456508
with:

COVERAGE.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Coverage reports
2+
3+
## Caveat
4+
5+
Until each module can be migrated to support Node.js's builtin ESM
6+
implementation (`nesm`), the coverage line numbers will be out-of-sync with
7+
reality.
8+
9+
In addition, we will have to implement source maps in all of our
10+
source-to-source transforms (such as `@agoric/bundle-source`,
11+
`@agoric/transform-metering`, and `@agoric/static-module-record`).
12+
13+
## Reports
14+
15+
Coverage reports for the current main branch (whose packages support `nesm`) are
16+
published by CI to: https://agoric-sdk-coverage.netlify.app
17+
18+
You can create a report in any package (including the top-level directory):
19+
20+
```sh
21+
# Get options available for coverage:
22+
yarn c8 --help
23+
# Run ava under Node.js coverage and display a summary:
24+
yarn c8 -a ava
25+
# Generate a nice, detailed HTML report:
26+
yarn c8 report --reporter=html-spa
27+
open coverage/html/index.html
28+
```
29+
30+
## Node.js ESM Support
31+
32+
With the current `patches/esm+3.2.25.diff`, it is possible to migrate packages
33+
to support both resm (`-r esm`) and nesm (Node.js ESM Support). If an
34+
`agoric-sdk` package has dependencies that support nesm, you can attempt to make
35+
it also support nesm by:
36+
37+
1. Create `ava-nesm.config.js` removing `"require": ["esm"]`:
38+
39+
```sh
40+
../../scripts/ava-nesm.cjs > ava-nesm.config.js
41+
```
42+
43+
2. Make the following changes to its `package.json` (omitting comments):
44+
45+
```js
46+
{
47+
// Enable nesm support.
48+
"type": "module",
49+
"scripts": {
50+
// The following line enables coverage generation from the top.
51+
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js"
52+
}
53+
}
54+
```
55+
56+
3. Test that both `yarn test` and `yarn test:c8` run correctly.
57+
58+
## Planned Implementation
59+
60+
Our runtime source transforms can be conditional on the `$NODE_V8_COVERAGE`
61+
environment variable, which is set by `c8`.
62+
63+
When that is nonempty, source transforms can implement special behaviour to
64+
preserve source maps for transformed code. This involves using a `//#
65+
sourceURL=...` tag to associate a unique URL to an actual existing file during
66+
`eval`. The file's contents include a `//# sourceMappingURL=...`, whether a
67+
relative URL (taken from `sourceURL`) to a `.js.map` file or inline as a `data:`
68+
URI.
69+
70+
71+
The `sourceMappingURL` source map must contain a `"sources"` property as a
72+
relative or absolute URL to the input source file.

COVERAGE_NETLIFY_SITE_ID

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
91d78371-7395-4779-8367-0c4f7088297c

golang/cosmos/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"test": "exit 0",
1515
"build:gyp": "make compile-gyp",
1616
"build:gyp-debug": "make compile-gyp GYP_DEBUG=--debug",
17-
"test:nyc": "nyc ava",
1817
"test:xs": "exit 0",
1918
"build": "exit 0",
2019
"lint-fix": "eslint --fix '**/*.js'",

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"devDependencies": {
5050
"@typescript-eslint/parser": "^4.18.0",
5151
"ava": "^3.12.1",
52+
"c8": "^7.7.2",
5253
"eslint": "^7.23.0",
5354
"eslint-config-airbnb-base": "^14.0.0",
5455
"eslint-config-jessie": "^0.0.4",
@@ -58,7 +59,6 @@
5859
"eslint-plugin-jsx-a11y": "^6.2.3",
5960
"eslint-plugin-prettier": "^3.1.2",
6061
"lerna": "^3.20.2",
61-
"nyc": "^15.1.0",
6262
"prettier": "^1.18.2",
6363
"typescript": "^4.2.3"
6464
},
@@ -75,13 +75,23 @@
7575
"lint-fix": "yarn workspaces run lint-fix",
7676
"lint-check": "yarn workspaces run lint-check",
7777
"lint": "yarn workspaces run lint-check",
78-
"test": "yarn workspaces run test",
78+
"test": "ava",
79+
"test:c8-all": "rm -rf coverage/tmp && C8_OPTIONS=\"--clean=false --temp-directory=$PWD/coverage/tmp\" lerna run test:c8",
7980
"test:xs": "yarn workspaces run test:xs",
8081
"build": "yarn workspaces run build",
8182
"postinstall": "patch-package",
8283
"patch-package": "patch-package",
8384
"build-xs-worker": "cd packages/xs-vat-worker && yarn build:xs-lin"
8485
},
86+
"ava": {
87+
"files": [
88+
"packages/*/test/**/test-*.js"
89+
],
90+
"require": [
91+
"esm"
92+
],
93+
"timeout": "30m"
94+
},
8595
"dependencies": {
8696
"patch-package": "^6.2.2"
8797
}

packages/ERTP/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"test:xs": "yarn test:xs-unit && yarn test:xs-worker",
1616
"test:xs-unit": "ava-xs",
1717
"test:xs-worker": "SWINGSET_WORKER_TYPE=xs-worker ava -c 2 test/swingsetTests/**/test-*.js",
18-
"test:nyc": "nyc ava",
1918
"pretty-fix": "prettier --write '**/*.js'",
2019
"pretty-check": "prettier --check '**/*.js'",
2120
"lint-fix": "yarn lint:eslint --fix && yarn lint:types",
@@ -57,8 +56,7 @@
5756
"@agoric/install-ses": "^0.5.13",
5857
"@agoric/swingset-vat": "^0.17.2",
5958
"ava": "^3.12.1",
60-
"esm": "^3.2.25",
61-
"nyc": "^15.1.0"
59+
"esm": "^3.2.25"
6260
},
6361
"files": [
6462
"src",

packages/SwingSet/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"devDependencies": {
3030
"@agoric/install-metering-and-ses": "^0.2.13",
3131
"@agoric/ses-ava": "^0.1.1",
32-
"ava": "^3.12.1",
33-
"nyc": "^15.1.0"
32+
"ava": "^3.12.1"
3433
},
3534
"dependencies": {
3635
"@agoric/assert": "^0.2.12",

packages/agoric-cli/.ava-unit-test.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/agoric-cli/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"scripts": {
1515
"build": "exit 0",
16-
"test": "ava --config .ava-unit-test.config.js",
16+
"test": "ava",
1717
"test:xs": "exit 0",
1818
"integration-test": "ava --config .ava-integration-test.config.js",
1919
"lint-check": "eslint '**/*.{js,jsx}'",
@@ -22,7 +22,6 @@
2222
"devDependencies": {
2323
"@agoric/swingset-vat": "^0.17.2",
2424
"ava": "^3.12.1",
25-
"nyc": "^15.1.0",
2625
"tmp": "^0.1.0"
2726
},
2827
"dependencies": {
@@ -59,6 +58,11 @@
5958
"@agoric"
6059
]
6160
},
61+
"ava": {
62+
"files": ["test/**/test-*.js"],
63+
"require": ["esm"],
64+
"timeout": "2m"
65+
},
6266
"prettier": {
6367
"trailingComma": "all",
6468
"singleQuote": true

0 commit comments

Comments
 (0)