Skip to content

Commit

Permalink
test: remove old behaviour from WPT runner
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jun 16, 2022
1 parent 5057cac commit 2804b84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
34 changes: 8 additions & 26 deletions test/common/wpt.js
Expand Up @@ -147,8 +147,7 @@ class WPTTestSpec {
* 'test.any.js'
* @param {StatusRule[]} rules
*/
constructor(mod, filename, rules, version) {
this.version = version;
constructor(mod, filename, rules) {
this.module = mod;
this.filename = filename;

Expand All @@ -161,17 +160,8 @@ class WPTTestSpec {
this.requires.add(req);
}
}
switch (this.version) {
case 1:
if (item.fail) {
this.failReasons.push(item.fail);
}
break;
case 2:
default:
if (Array.isArray(item.fail?.expected)) {
this.failReasons.push(...item.fail.expected);
}
if (Array.isArray(item.fail?.expected)) {
this.failReasons.push(...item.fail.expected);
}
if (item.skip) {
this.skipReasons.push(item.skip);
Expand Down Expand Up @@ -270,15 +260,15 @@ class StatusLoader {
load() {
const dir = path.join(__dirname, '..', 'wpt');
const statusFile = path.join(dir, 'status', `${this.path}.json`);
const { '$version': version, ...result } = JSON.parse(fs.readFileSync(statusFile, 'utf8'));
const result = JSON.parse(fs.readFileSync(statusFile, 'utf8'));
this.rules.addRules(result);

const subDir = fixtures.path('wpt', this.path);
const list = this.grep(subDir);
for (const file of list) {
const relativePath = path.relative(subDir, file);
const match = this.rules.match(relativePath);
this.specs.push(new WPTTestSpec(this.path, relativePath, match, version));
this.specs.push(new WPTTestSpec(this.path, relativePath, match));
}
this.loaded = true;
}
Expand Down Expand Up @@ -479,7 +469,7 @@ class WPTRunner {
}
}
inspect.defaultOptions.depth = Infinity;
// sorts the rules to have consistent output
// Sorts the rules to have consistent output
console.log(JSON.stringify(Object.keys(this.results).sort().reduce(
(obj, key) => {
obj[key] = this.results[key];
Expand Down Expand Up @@ -606,18 +596,10 @@ class WPTRunner {

fail(filename, test, status) {
const spec = this.specMap.get(filename);
let expected;
switch (spec.version) {
case 1:
expected = !!(spec.failReasons.length);
break;
case 2:
default:
expected = spec.failReasons.includes(test.message || reason);
}
const expected = spec.failReasons.includes(test.message || status);
if (expected) {
console.log(`[EXPECTED_FAILURE][${status.toUpperCase()}] ${test.name}`);
console.log(test.message || reason);
console.log(test.message || status);
} else {
console.log(`[UNEXPECTED_FAILURE][${status.toUpperCase()}] ${test.name}`);
}
Expand Down
14 changes: 11 additions & 3 deletions test/wpt/README.md
Expand Up @@ -91,7 +91,11 @@ add this to `test/wpt/status/url.json`:

```json
"url-searchparams.any.js": {
"fail": "explain why the test fails, ideally with links"
"fail": {
"expected": [
"exhibited error message"
]
}
}
```

Expand Down Expand Up @@ -155,8 +159,12 @@ expected failures.
// Optional: the test will be skipped with the reason printed
"skip": "explain why we cannot run a test that's supposed to pass",
// Optional: the test will be skipped with the reason printed
"fail": "explain why we the test is expected to fail"
// Optional: tests failing with this message are expected
"fail": {
"expected": [
"exhibited error message"
]
}
}
}
```
Expand Down

0 comments on commit 2804b84

Please sign in to comment.