Skip to content

Commit e8589ef

Browse files
committed
test: Use the ES modules directly
This avoids the need for the generated CJS files and use of rollup in testing. Thanks to https://remysharp.com/2019/08/16/build-free-code-and-testing-es-module-imports and avajs/ava#2417 (comment) :-).
1 parent 3e08100 commit e8589ef

7 files changed

+28
-41
lines changed

.eslintrc.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"node": true
66
},
77
"extends": "eslint:recommended",
8-
"overrides": [{
9-
"files": ["test/rollup.config.js"],
10-
"parserOptions": {
11-
"sourceType": "module"
8+
"overrides": [
9+
{
10+
"files": ["test/test*.js"],
11+
"parserOptions": {
12+
"sourceType": "module"
13+
}
1214
}
13-
}],
15+
],
1416
"parserOptions": {
1517
"ecmaVersion": 2018
1618
},

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"start:edge": "npm run start:_core -- --source-dir build/edge --target chromium --chromium-binary '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'",
1414
"start:firefox": "npm run start:_core -- --source-dir build/firefox",
1515
"start:opera": "npm run start:_core -- --source-dir build/opera --target chromium --chromium-binary /Applications/Opera.app/Contents/MacOS/opera",
16-
"pretest": "eslint . && rollup -c test/rollup.config.js",
17-
"test": "npx nyc --exclude 'test/test*js' --reporter text --reporter html ava && npm run test:css",
16+
"pretest": "eslint .",
17+
"test": "npx nyc --reporter text --reporter html ava && npm run test:css",
1818
"test:css": "npx stylelint --config .stylelintrc.json src/**/*.css",
1919
"version": "standard-version --tag-prefix="
2020
},
@@ -23,12 +23,15 @@
2323
"pre-commit": "npm run build:all"
2424
}
2525
},
26+
"esm": { "cjs": true },
2627
"ava": {
2728
"files": [
2829
"!test/generated-*.js",
2930
"!test/rollup.config.js"
30-
]
31+
],
32+
"require": ["esm"]
3133
},
34+
"nyc": { "require": ["esm"] },
3235
"devDependencies": {
3336
"addons-linter": "^2.1.0",
3437
"archiver-promise": "~1.0",
@@ -37,6 +40,7 @@
3740
"deepmerge": "~4.2",
3841
"dependency-tree": "^7.2.1",
3942
"eslint": "^7.5.0",
43+
"esm": "^3.2.25",
4044
"fs-extra": "^9.0.1",
4145
"husky": "^4.2.5",
4246
"jsdom": "^16.3.0",

test/rollup.config.js

-22
This file was deleted.

test/testContrastChecker.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict'
2-
const test = require('ava')
3-
const ContrastChecker = require('./generated-contrast-checker.js')
1+
import test from 'ava'
2+
import ContrastChecker from '../src/code/contrastChecker'
43

54
const contrastChecker = new ContrastChecker()
65

test/testLandmarksFinder.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
'use strict'
2-
const test = require('ava')
3-
const jsdom = require('jsdom')
4-
const pssst = require('page-structural-semantics-scanner-tests')
5-
const LandmarksFinder = require('./generated-landmarks-finder')
1+
import test from 'ava'
2+
import jsdom from 'jsdom'
3+
import pssst from 'page-structural-semantics-scanner-tests'
4+
import LandmarksFinder from '../src/code/landmarksFinder'
65

76
const { JSDOM } = jsdom
87
const checks = pssst.getFullPageTestsInline()

test/testMigrationManager.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-prototype-builtins */
2-
'use strict'
3-
const test = require('ava')
4-
const MigrationManager = require('./generated-migration-manager.js')
2+
import test from 'ava'
3+
import MigrationManager from '../src/code/migrationManager'
54

65
// The purpose of the migration manager is to delete obsolete user settings, or
76
// rename existing user settings to their current names. Landmarks ships with

0 commit comments

Comments
 (0)