Skip to content

Commit 69b870d

Browse files
committed
Run tests with real ECAMAScript modules
Compile to ECMAScript module syntax for tests. - Replace nyt with c8 - Replace optimal-select with @medv/finder - Replace custom babel-register with babel-register-esm
1 parent 6b1e40b commit 69b870d

12 files changed

+100
-395
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.d.ts
22
!/packages/**/src/**/*.d.ts
33
*.d.ts.map
4-
.nyc_output
54
coverage
65
docs
76
node_modules

.mocharc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
module.exports = {
2424
extension: ['.ts'],
2525
ignore: ['node_modules'],
26-
require: ['./babel-register.js', 'global-jsdom/register'],
26+
loader: 'babel-register-esm',
27+
require: ['global-jsdom/register'],
2728
timeout: 5000,
2829
watchFiles: [
2930
'./test/**/*.ts',

babel-register.js

-26
This file was deleted.

babel.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ module.exports = (api) => {
3232
// Use minimal syntax fixes where possible
3333
// Note: This setting may become the default in Babel 8.
3434
bugfixes: true,
35-
// Transform module syntax if necessary.
36-
modules: TEST ? 'commonjs' : false,
35+
// Do not transform module syntax.
36+
modules: false,
3737
};
3838

3939
// Options for the @babel/typescript preset.

nyc.config.js

-29
This file was deleted.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"build:js": "lerna exec --parallel -- babel -d lib -s -x .ts --env-name production --root-mode upward src",
2020
"build:misc": "lerna exec --parallel -- cp ../../DISCLAIMER-WIP ../../LICENSE ../../NOTICE ../../README.md .",
2121
"build:types": "tsc --build",
22-
"clean": "tsc --build --clean && lerna exec -- rimraf DISCLAIMER-WIP LICENSE NOTICE README.md lib && rimraf .nyc_output coverage docs web/dist *.tsbuildinfo",
22+
"clean": "tsc --build --clean && lerna exec -- rimraf DISCLAIMER-WIP LICENSE NOTICE README.md coverage docs lib web/dist",
2323
"docs": "tsc --build && typedoc",
2424
"lint": "eslint .",
2525
"prepublishOnly": "yarn run build",
2626
"publish": "lerna publish",
2727
"publish:ci": "yarn run publish --canary --exact --force-publish '*' --no-verify-access --yes minor",
2828
"start": "yarn run web:server",
29-
"test": "cross-env BABEL_ENV=test nyc mocha packages/**/*.test.ts",
29+
"test": "cross-env BABEL_ENV=test c8 -r html -r text mocha packages/**/*.test.ts",
30+
"test:watch": "cross-env BABEL_ENV=test mocha -p -w packages/**/*.test.ts",
3031
"validate": "cross-env BABEL_ENV=test mocha test/**/*.test.ts",
3132
"web:build": "webpack --config=web/webpack.config.js --mode development",
3233
"web:server": "webpack-dev-server --config=web/webpack.config.js --hot --mode development"
@@ -38,7 +39,6 @@
3839
"@babel/plugin-transform-runtime": "^7.13.10",
3940
"@babel/preset-env": "^7.13.12",
4041
"@babel/preset-typescript": "^7.13.0",
41-
"@babel/register": "^7.13.14",
4242
"@types/mocha": "^9.0.0",
4343
"@types/node-fetch": "^2.5.7",
4444
"@types/resolve": "^1.17.0",
@@ -49,6 +49,8 @@
4949
"babel-plugin-istanbul": "^6.0.0",
5050
"babel-plugin-module-resolver": "^4.0.0",
5151
"babel-plugin-preserve-comment-header": "^1.0.1",
52+
"babel-register-esm": "^1.2.1",
53+
"c8": "^7.10.0",
5254
"concurrently": "^5.3.0",
5355
"cross-env": "^6.0.3",
5456
"eslint": "^7.5.0",
@@ -65,7 +67,6 @@
6567
"lint-staged": "^10.0.2",
6668
"mocha": "^9.1.3",
6769
"node-fetch": "^2.5.0",
68-
"nyc": "^15.0.0",
6970
"prettier": "^2.0.5",
7071
"resolve": "^1.15.0",
7172
"rimraf": "^3.0.0",

packages/dom/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@apache-annotator/selector": "^0.2.0",
1818
"@babel/runtime-corejs3": "^7.13.10",
19-
"optimal-select": "^4.0.1"
19+
"@medv/finder": "^2.1.0"
2020
},
2121
"engines": {
2222
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0"

packages/dom/src/css.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* under the License.
2121
*/
2222

23-
import optimalSelect from 'optimal-select';
23+
import { finder } from '@medv/finder';
2424
import type { CssSelector, Matcher } from '@apache-annotator/selector';
2525
import { ownerDocument } from './owner-document.js';
2626
import { toRange } from './to-range.js';
@@ -112,9 +112,9 @@ export function createCssSelectorMatcher(
112112
*/
113113
export async function describeCss(
114114
element: HTMLElement,
115-
scope: Node = element.ownerDocument,
115+
scope: Element = element.ownerDocument.documentElement,
116116
): Promise<CssSelector> {
117-
const selector = optimalSelect(element, { root: scope });
117+
const selector = finder(element, { root: scope });
118118
return {
119119
type: 'CssSelector',
120120
value: selector,

packages/dom/src/optimal-select.d.ts

-31
This file was deleted.

test/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

tsconfig.base.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
34
"composite": true,
45
"declaration": true,
56
"declarationMap": true,
67
"downlevelIteration": true,
78
"emitDeclarationOnly": true,
8-
"esModuleInterop": true,
99
"forceConsistentCasingInFileNames": true,
1010
"isolatedModules": true,
1111
"lib": [
1212
"dom",
1313
"dom.iterable",
1414
"es2020"
1515
],
16+
"module": "es2020",
1617
"moduleResolution": "node",
1718
"noPropertyAccessFromIndexSignature": true,
1819
"skipLibCheck": true,

0 commit comments

Comments
 (0)