Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: change WPT status files into CommonJS files #45826

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ class StatusLoader {

load() {
const dir = path.join(__dirname, '..', 'wpt');
const statusFile = path.join(dir, 'status', `${this.path}.json`);
const result = JSON.parse(fs.readFileSync(statusFile, 'utf8'));
const statusFile = path.join(dir, 'status', `${this.path}.js`);
if (!fs.existsSync(statusFile)) {
throw new Error(`Missing ${statusFile} WPT status file.`);
}
const result = require(statusFile);
this.rules.addRules(result);

const subDir = fixtures.path('wpt', this.path);
Expand Down Expand Up @@ -595,13 +598,13 @@ class WPTRunner {
`${failures.length} unexpected failures,`,
`${unexpectedPasses.length} unexpected passes`);
if (failures.length > 0) {
const file = path.join('test', 'wpt', 'status', `${this.path}.json`);
const file = path.join('test', 'wpt', 'status', `${this.path}.js`);
throw new Error(
`Found ${failures.length} unexpected failures. ` +
`Consider updating ${file} for these files:\n${failures.join('\n')}`);
}
if (unexpectedPasses.length > 0) {
const file = path.join('test', 'wpt', 'status', `${this.path}.json`);
const file = path.join('test', 'wpt', 'status', `${this.path}.js`);
throw new Error(
`Found ${unexpectedPasses.length} unexpected passes. ` +
`Consider updating ${file} for these files:\n${unexpectedPasses.join('\n')}`);
Expand Down
81 changes: 46 additions & 35 deletions test/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The tests here are drivers for running the [Web Platform Tests][].
See [`test/fixtures/wpt/README.md`][] for a hash of the last
updated WPT commit for each module being covered here.

See the json files in [the `status` folder](./status) for prerequisites,
See the WPT status files in [the `status` folder](./status) for prerequisites,
expected failures, and support status for specific tests in each module.

Currently there are still some Web Platform Tests titled `test-whatwg-*`
Expand All @@ -20,14 +20,14 @@ This folder covers the tests that have been migrated.

### 1. Create a status file

For example, to add the URL tests, add a `test/wpt/status/url.json` file.
For example, to add the URL tests, add a `test/wpt/status/url.js` file.

In the beginning, it's fine to leave an empty object `{}` in the file if
it's not yet clear how compliant the implementation is,
In the beginning, it's fine to export an empty object `module.exports = {};`
in the file if it's not yet clear how compliant the implementation is,
the requirements and expected failures can be figured out in a later step
when the tests are run for the first time.

See [Format of a status JSON file](#status-format) for details.
See [Format of a status file](#status-format) for details.

### 2. Pull the WPT files

Expand All @@ -43,6 +43,8 @@ $ git node wpt url

For example, for the URL tests, add a file `test/wpt/test-url.js`:

<!-- eslint-skip -->

```js
'use strict';

Expand Down Expand Up @@ -84,22 +86,26 @@ node test/wpt/test-url.js url-searchparams.any.js
```

If there are any failures, update the corresponding status file
(in this case, `test/wpt/status/url.json`) to make the test pass.
(in this case, `test/wpt/status/url.js`) to make the test pass.

For example, to mark `url/url-searchparams.any.js` as expected to fail,
add this to `test/wpt/status/url.json`:

```json
"url-searchparams.any.js": {
"fail": {
"expected": [
"test name in the WPT test case, e.g. second argument passed to test()"
]
}
}
add this to the `test/wpt/status/url.js` exported object:

<!-- eslint-skip -->

```js
module.exports = {
'url-searchparams.any.js': {
fail: {
expected: [
'test name in the WPT test case, e.g. second argument passed to test()',
],
},
},
};
```

See [Format of a status JSON file](#status-format) for details.
See [Format of a status file](#status-format) for details.

### 5. Commit the changes and submit a Pull Request

Expand Down Expand Up @@ -137,7 +143,7 @@ Given a module, the `WPTRunner` class in [`test/common/wpt`](../common/wpt.js)
loads:

* `.js` test files (for example, `test/common/wpt/url/*.js` for `url`)
* Status file (for example, `test/wpt/status/url.json` for `url`)
* Status file (for example, `test/wpt/status/url.js` for `url`)
* The WPT harness

Then, for each test, it creates a worker thread with the globals and mocks,
Expand All @@ -148,32 +154,37 @@ expected failures.

<a id="status-format"></a>

## Format of a status JSON file
## Format of a status file

```text
{
"something.scope.js": { // the file name
<!-- eslint-skip -->

```js
module.exports = {
'something.scope.js': { // the file name
// Optional: If the requirement is not met, this test will be skipped
"requires": ["small-icu"], // supports: "small-icu", "full-icu"
requires: ['small-icu'], // supports: 'small-icu', 'full-icu'

// Optional: the test will be skipped with the reason printed
"skip": "explain why we cannot run a test that's supposed to pass",
skip: "explaination why we cannot run a test that's supposed to pass",

// Optional: failing tests
"fail": {
"note": "You may leave an optional arbitrary note e.g. with TODOs",
"expected": [
"test name in the WPT test case, e.g. second argument passed to test()",
"another test name"
fail: {
expected: [
'test name in the WPT test case, e.g. second argument passed to test()',
'another test name',
],
"flaky": [
"flaky test name"
]
}
}
}
flaky: [
'flaky test name',
],
},
},
};
```

You may automatically format the files by running `make lint-js-fix`. The lint
panva marked this conversation as resolved.
Show resolved Hide resolved
rules are set such that adding or removing expected failures is unlikely to
conflict with other updates.

A test may have to be skipped because it depends on another irrelevant
Web API, or certain harness has not been ported in our test runner yet.
In that case it needs to be marked with `skip` instead of `fail`.
Expand Down
9 changes: 9 additions & 0 deletions test/wpt/status/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## WPT Status files linter rules

rules:
array-element-newline: [error, always]
array-bracket-newline: [error, always]
node-core/required-modules: [off]
node-core/require-common-first: [off]
quote-props: [error, as-needed]
max-len: [off]
49 changes: 49 additions & 0 deletions test/wpt/status/FileAPI/blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

module.exports = {
'Blob-constructor-dom.window.js': {
skip: 'Depends on DOM API',
},
'Blob-constructor.any.js': {
fail: {
note: 'Depends on File API',
expected: [
'A plain object with @@iterator should be treated as a sequence for the blobParts argument.',
'A plain object with @@iterator and a length property should be treated as a sequence for the blobParts argument.',
'A String object should be treated as a sequence for the blobParts argument.',
'A Uint8Array object should be treated as a sequence for the blobParts argument.',
'Getters and value conversions should happen in order until an exception is thrown.',
'Changes to the blobParts array should be reflected in the returned Blob (pop).',
'Changes to the blobParts array should be reflected in the returned Blob (unshift).',
'ToString should be called on elements of the blobParts array.',
'ArrayBuffer elements of the blobParts array should be supported.',
'Passing typed arrays as elements of the blobParts array should work.',
'Passing a Float64Array as element of the blobParts array should work.',
'Array with two blobs',
'Array with two buffers',
'Array with two bufferviews',
'Array with mixed types',
'options properties should be accessed in lexicographic order.',
'Arguments should be evaluated from left to right.',
'Passing null (index 0) for options should use the defaults.',
'Passing null (index 0) for options should use the defaults (with newlines).',
'Passing undefined (index 1) for options should use the defaults.',
'Passing undefined (index 1) for options should use the defaults (with newlines).',
'Passing object "[object Object]" (index 2) for options should use the defaults.',
'Passing object "[object Object]" (index 2) for options should use the defaults (with newlines).',
'Passing object "[object Object]" (index 3) for options should use the defaults.',
'Passing object "[object Object]" (index 3) for options should use the defaults (with newlines).',
'Passing object "/regex/" (index 4) for options should use the defaults.',
'Passing object "/regex/" (index 4) for options should use the defaults (with newlines).',
'Passing function "function() {}" (index 5) for options should use the defaults.',
'Passing function "function() {}" (index 5) for options should use the defaults (with newlines).',
],
},
},
'Blob-in-worker.worker.js': {
skip: 'Depends on Web Workers API',
},
'Blob-slice.any.js': {
skip: 'Depends on File API',
},
};
47 changes: 0 additions & 47 deletions test/wpt/status/FileAPI/blob.json

This file was deleted.

19 changes: 19 additions & 0 deletions test/wpt/status/FileAPI/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = {
'Worker-read-file-constructor.worker.js': {
skip: true,
},
'send-file-formdata-punctuation.any.js': {
skip: true,
},
'send-file-formdata-utf-8.any.js': {
skip: true,
},
'send-file-formdata.any.js': {
skip: true,
},
'send-file-formdata-controls.any.js': {
skip: true,
},
};
17 changes: 0 additions & 17 deletions test/wpt/status/FileAPI/file.json

This file was deleted.

10 changes: 10 additions & 0 deletions test/wpt/status/WebCryptoAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

module.exports = {
'algorithm-discards-context.https.window.js': {
skip: 'Not relevant in Node.js context',
},
'historical.any.js': {
skip: 'Not relevant in Node.js context',
},
};
8 changes: 0 additions & 8 deletions test/wpt/status/WebCryptoAPI.json

This file was deleted.

13 changes: 13 additions & 0 deletions test/wpt/status/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
'idlharness.any.js': {
fail: {
flaky: [
'console namespace: operation assert(optional boolean, any...)',
'console namespace: operation table(optional any, optional sequence<DOMString>)',
'console namespace: operation dir(optional any, optional object?)',
],
},
},
};
11 changes: 0 additions & 11 deletions test/wpt/status/console.json

This file was deleted.

3 changes: 3 additions & 0 deletions test/wpt/status/dom/abort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
1 change: 0 additions & 1 deletion test/wpt/status/dom/abort.json

This file was deleted.

Loading