Skip to content

Commit 856abbe

Browse files
committed
refactor: update COVERAGE.md to accommodate ava-nesm.config.js
1 parent 3192156 commit 856abbe

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
# END-RESTORE-BOILERPLATE
149149

150150
- name: generate coverage for all tests
151-
run: yarn test:all-c8
151+
run: 'yarn test:c8-all || :'
152152
- name: generate coverage/html reports
153153
run: yarn c8 report --reporter=html-spa --reports-dir=coverage/html --temp-directory=coverage/tmp
154154
- uses: actions/upload-artifact@v2

COVERAGE.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Caveat
44

55
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
6+
implementation (`nesm`), the coverage line numbers will be out-of-sync with
77
reality.
88

99
In addition, we will have to implement source maps in all of our
@@ -12,7 +12,7 @@ source-to-source transforms (such as `@agoric/bundle-source`,
1212

1313
## Reports
1414

15-
Coverage reports for the current main branch (whose packages support `NESM`) are
15+
Coverage reports for the current main branch (whose packages support `nesm`) are
1616
published by CI to: https://agoric-sdk-coverage.netlify.app
1717

1818
You can create a report in any package (including the top-level directory):
@@ -27,34 +27,33 @@ yarn c8 report --reporter=html-spa
2727
open coverage/html/index.html
2828
```
2929

30-
## NESM Support
30+
## Node.js ESM Support
3131

3232
With the current `patches/esm+3.2.25.diff`, it is possible to migrate packages
33-
to support both RESM (`-r esm`) and NESM. If an `agoric-sdk` package has
34-
dependencies that support NESM, you can attempt to make it also support NESM by:
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:
3536

36-
1. Make the following changes to its `package.json` (omitting comments):
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):
3744

3845
```json
3946
{
40-
// Enable NESM support.
47+
// Enable nesm support.
4148
"type": "module",
4249
"scripts": {
4350
// The following line enables coverage generation from the top.
44-
"test:c8": "c8 $C8_OPTIONS ava",
45-
},
46-
"devDependencies": {
47-
// Remove:
48-
// "esm": "^3.2.25"
49-
}
50-
"ava": {
51-
// Remove:
52-
// "require": ["esm"]
51+
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
5352
}
5453
}
5554
```
5655

57-
2. Test that it runs correctly with both `yarn test` and `yarn test:c8`.
56+
3. Test that both `yarn test` and `yarn test:c8` run correctly.
5857

5958
## Planned Implementation
6059

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"lint-check": "yarn workspaces run lint-check",
7777
"lint": "yarn workspaces run lint-check",
7878
"test": "ava",
79-
"test:all-c8": "rm -rf coverage/tmp && C8_OPTIONS=\"--clean=false --temp-directory=$PWD/coverage/tmp\" lerna run test:c8 || :",
79+
"test:c8-all": "rm -rf coverage/tmp && C8_OPTIONS=\"--clean=false --temp-directory=$PWD/coverage/tmp\" lerna run test:c8",
8080
"test:xs": "yarn workspaces run test:xs",
8181
"build": "yarn workspaces run build",
8282
"postinstall": "patch-package",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
"files": [
3+
"test/**/test-*.js"
4+
],
5+
"timeout": "2m"
6+
};

packages/swing-store-simple/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"scripts": {
1414
"build": "exit 0",
1515
"test": "ava",
16-
"test:c8": "c8 $C8_OPTIONS ava",
16+
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
1717
"test:xs": "exit 0",
1818
"lint-fix": "eslint --fix '**/*.js'",
1919
"lint-check": "eslint '**/*.js'"
@@ -22,7 +22,8 @@
2222
"n-readlines": "^1.0.0"
2323
},
2424
"devDependencies": {
25-
"ava": "^3.12.1"
25+
"ava": "^3.12.1",
26+
"esm": "^3.2.25"
2627
},
2728
"publishConfig": {
2829
"access": "public"
@@ -31,6 +32,9 @@
3132
"files": [
3233
"test/**/test-*.js"
3334
],
35+
"require": [
36+
"esm"
37+
],
3438
"timeout": "2m"
3539
},
3640
"eslintConfig": {

scripts/ava-nesm.cjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/env node
2+
const fs = require('fs');
3+
const packageJson = fs.readFileSync('package.json', 'utf-8');
4+
const package = JSON.parse(packageJson);
5+
const { ava: avaConfig } = package;
6+
if (avaConfig.require) {
7+
const newRequire = avaConfig.require.filter(m => m !== 'esm');
8+
if (newRequire.length) {
9+
avaConfig.require = newRequire;
10+
} else {
11+
delete avaConfig.require;
12+
}
13+
}
14+
process.stdout.write(`\
15+
export default ${JSON.stringify(avaConfig, undefined, 2)};
16+
`);

0 commit comments

Comments
 (0)