Skip to content

Commit 6fbe511

Browse files
authored
Add isolated Node and pinned WPT development tooling (#167)
1 parent 62d45eb commit 6fbe511

22 files changed

Lines changed: 3693 additions & 146 deletions

‎.eslintrc.yml‎

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

‎.github/workflows/node.js.yml‎

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ name: nwsapi
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [master]
76
pull_request:
8-
branches:
9-
- main
7+
branches: [master]
108

119
jobs:
12-
build:
10+
node:
1311
runs-on: ubuntu-latest
14-
1512
steps:
16-
- name: Checkout repository
17-
uses: actions/checkout@v2
18-
19-
- name: Setup Node.js
20-
uses: actions/setup-node@v2
21-
with:
22-
node-version: '14'
23-
24-
- name: Install dependencies
25-
run: npm install
26-
27-
- name: Run tests
28-
run: npm testIs the NodeJS yaml configuration needed in my "nwsapi" repository ?
13+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 (2026-07-20)
14+
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 (2026-07-14)
15+
with:
16+
node-version: '26'
17+
cache: npm
18+
- run: npm ci
19+
- run: npm run lint
20+
- run: npm test
21+
- run: npm run min
22+
- run: npm run upstream:clone
23+
- run: npm run upstream:verify
24+
- run: npx playwright install --with-deps chromium
25+
- run: npm run test:upstream

‎.gitignore‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
node_modules/
2-
package-lock.json
1+
**/node_modules/
2+
/dist/nwsapi.min.js
3+
/playwright-report/
4+
/test-results/
5+
/upstream/
36
yarn.lock

‎.gitmodules‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# wpt-7aed663 sha256:9954c30501783f0c12ea5026a94cf988c8c5d2ac3ed51279cbfdd7476f92c393
2+
[submodule "upstream/wpt"]
3+
ignore = dirty
4+
ref = 7aed6630812b20e6eec2a2e40594f8dfda036e00
5+
path = upstream/wpt
6+
url = https://github.com/web-platform-tests/wpt.git
7+
branch = master
8+
shallow = true
9+
sparse-checkout = resources common dom/nodes css/selectors
10+
verify = npm run test:upstream
11+
# no-release-tag: web-platform-tests publishes no release tags; pinned by ref on master

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ Add the adapter's `css-tree` peer dependency to `package.json`:
6666
Run `npm install` or `pnpm install`. jsdom will use nwsapi for queries and stylesheet
6767
matching. The existing nwsapi factory API and selector support are unchanged.
6868

69+
## Development
70+
71+
Run the development tools with Node.js ≥ 22. This does not change the library's
72+
runtime support.
73+
CI runs lint, Node tests, the build and WPT in one Node.js 26 job.
74+
75+
```sh
76+
npm ci
77+
npm test
78+
npm run lint
79+
npm run min
80+
```
81+
82+
Node tests need no browser or WPT checkout. See [upstream testing](docs/upstream.md)
83+
for Chromium setup and known failures. `npm run clean` removes only the generated
84+
`dist/nwsapi.min.js` bundle.
85+
6986
## Supported Selectors
7087

7188
Here is a list of all the CSS2/CSS3/CSS4 [Supported selectors](https://github.com/dperini/nwsapi/wiki/CSS-supported-selectors).

‎docs/upstream.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Upstream selector tests
2+
3+
The WPT runner loads `src/nwsapi.js` before each test page and installs it
4+
as the selector engine. It checks 41 pages listed in `test/upstream/manifest.mjs`.
5+
This is a selected suite, not the complete web-platform-tests project.
6+
7+
Run with Node.js ≥ 22.
8+
9+
```sh
10+
npm ci
11+
npm run upstream:clone
12+
npm run upstream:verify
13+
npx playwright install chromium
14+
npm run test:upstream
15+
```
16+
17+
`.gitmodules` pins WPT to `7aed6630812b20e6eec2a2e40594f8dfda036e00`.
18+
The helper fetches a shallow, sparse checkout and verifies its manifest hash.
19+
The checkout is ignored, not a Git submodule. Do not edit its files.
20+
Clone and sparse-restoration commands reject paths that resolve outside the
21+
repository and refuse dirty existing checkouts before changing them.
22+
23+
Node tests run separately with `npm test`; they need neither WPT nor Chromium.
24+
The browser server binds localhost and refuses an occupied port.
25+
26+
## Baseline
27+
28+
`test/upstream/expectations.json` records failures measured against unchanged
29+
master `fe15bc3ae8f76725a13b329aad2efbe3fa75f9a4` using Chromium 151.0.7922.34.
30+
It is not the earlier aggregate branch's baseline. Pending fixes keep their
31+
regression assertions in their own PRs; a baseline entry does not replace them.
32+
33+
This baseline contains 352 expected failures, versus 336 in the aggregate.
34+
The 16 additional failures cover relative `:has()` arguments and detached
35+
elements. Their correction belongs to the relational-selector extraction.
36+
37+
Unexpected failures fail the run. Unexpected passes are reported for cleanup.
38+
To regenerate after reviewing an engine or upstream change:
39+
40+
```sh
41+
WPT_UPDATE_EXPECTATIONS=1 npm run test:upstream
42+
```
43+
44+
Review the diff before committing. Do not use baseline updates to hide regressions.
45+
Filtered updates are rejected; baseline writes use one worker.
46+
47+
Use `WPT_FILTER` for a subtest-name substring or `/regex/`, and `WPT_SECTION`
48+
for a selector-section substring. List sections with
49+
`node test/upstream/sections.mjs`.
50+
51+
## Lint baseline
52+
53+
The flat configuration checks source and new tooling. `eslint-suppressions.json`
54+
records two existing source findings: undefined `isInstanceof` in `byClass`
55+
and an unused assignment to `source`. They are not repaired by this tooling PR.
56+
Remove each suppression when its engine correction lands.

‎eslint-suppressions.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"src/nwsapi.js": {
3+
"no-undef": {
4+
"count": 1
5+
},
6+
"no-useless-assignment": {
7+
"count": 1
8+
}
9+
}
10+
}

‎eslint.config.mjs‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { defineConfig, globalIgnores } from 'eslint/config';
2+
import js from '@eslint/js';
3+
import globals from 'globals';
4+
5+
export default defineConfig([
6+
globalIgnores([
7+
'dist/',
8+
'node_modules/',
9+
'upstream/',
10+
'test-results/',
11+
'playwright-report/',
12+
// legacy browser-run suites, not lintable as modern JS
13+
'test/css3-compat/',
14+
'test/css3-escape/',
15+
'test/html5/',
16+
'test/jquery/',
17+
'test/jsvm/',
18+
'test/prototype/',
19+
'test/quirks/',
20+
'test/scope/',
21+
'test/scotch/',
22+
'test/slick/',
23+
'test/speed/',
24+
'test/w3c/',
25+
'test/W3C-Selector-tests/',
26+
'test/wpt/',
27+
'test/xml/',
28+
'build/',
29+
]),
30+
js.configs.recommended,
31+
{
32+
files: ['src/**/*.js'],
33+
languageOptions: {
34+
ecmaVersion: 'latest',
35+
sourceType: 'script',
36+
globals: {
37+
...globals.browser,
38+
...globals.commonjs,
39+
...globals.amd,
40+
NW: 'readonly',
41+
},
42+
},
43+
rules: {
44+
'no-console': 'off',
45+
'no-unused-vars': 'off',
46+
'no-cond-assign': 'off',
47+
'no-control-regex': 'off',
48+
'no-useless-escape': 'off',
49+
'no-redeclare': 'off',
50+
'no-empty': 'off',
51+
52+
'default-case': 'error',
53+
'no-duplicate-case': 'error',
54+
'radix': 'error',
55+
'no-with': 'error',
56+
},
57+
},
58+
{
59+
files: ['**/*.cjs'],
60+
languageOptions: {
61+
sourceType: 'commonjs',
62+
globals: globals.node,
63+
},
64+
},
65+
{
66+
files: ['**/*.mjs'],
67+
languageOptions: {
68+
ecmaVersion: 'latest',
69+
sourceType: 'module',
70+
globals: {
71+
...globals.nodeBuiltin,
72+
},
73+
},
74+
rules: {
75+
'no-console': 'off',
76+
},
77+
},
78+
]);

0 commit comments

Comments
 (0)