Skip to content

Commit a632e0e

Browse files
committed
Restructure more tests
1 parent 4c51af3 commit a632e0e

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

test/elements/consistency.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Test the consistency of elements extracts with IDL extracts.
3-
*
3+
*
44
* The tests run against the curated and package views of the data. An extract
55
* that passes a test in the curated view may fail the same test in the package
66
* view because of some missing IDL definition in that view.
77
*/
88

9-
import { describe, it, before } from 'node:test';
9+
import { describe, it } from 'node:test';
1010
import { strict as assert } from 'node:assert';
1111
import path from 'node:path';
1212
import { fileURLToPath } from 'node:url';
@@ -26,37 +26,36 @@ const views = [
2626
];
2727

2828
views.forEach(({ name, folder }) => {
29-
describe(`The ${name} view of elements extracts`, () => {
30-
before(async () => {
31-
// Create a set of well-known interfaces
32-
const allIdl = await idl.parseAll({ folder: path.join(folder, 'idl') });
33-
const interfaces = new Set();
34-
for (const [shortname, ast] of Object.entries(allIdl)) {
35-
for (const dfn of ast) {
36-
if (dfn.name) {
37-
interfaces.add(dfn.name);
38-
}
29+
describe(`The ${name} view of elements extracts`, async () => {
30+
let allIdl;
31+
try {
32+
allIdl = await idl.parseAll({ folder: path.join(folder, 'idl') });
33+
} catch (err) {
34+
it('contains valid JSON data', () => {throw err;});
35+
}
36+
const interfaces = new Set();
37+
for (const [shortname, ast] of Object.entries(allIdl)) {
38+
for (const dfn of ast) {
39+
if (dfn.name) {
40+
interfaces.add(dfn.name);
3941
}
4042
}
43+
}
4144

42-
const allElements = await elements.listAll({ folder: path.join(folder, 'elements') });
43-
for (const [shortname, data] of Object.entries(allElements)) {
44-
describe(`The elements extract for ${shortname} in the ${name} view`, () => {
45-
for (const el of data.elements) {
46-
if (!el.interface) {
47-
continue;
48-
}
49-
it(`links to a well-known interface for "${el.name}"`, () => {
50-
assert(interfaces.has(el.interface), `Unknown interface "${el.interface}"`);
51-
});
45+
const allElements = await elements.listAll({ folder: path.join(folder, 'elements') });
46+
for (const [shortname, data] of Object.entries(allElements)) {
47+
describe(`The elements extract for ${shortname} in the ${name} view`, () => {
48+
for (const el of data.elements) {
49+
if (!el.interface) {
50+
continue;
5251
}
53-
});
54-
}
55-
});
56-
57-
// Dummy test needed for "before" to run and register late tests
58-
// (test will fail if before function throws, e.g. because data is invalid)
59-
it('contains valid JSON data', () => {});
52+
it(`links to a well-known interface for "${el.name}"`, () => {
53+
assert(interfaces.has(el.interface), `Unknown interface "${el.interface}"`);
54+
});
55+
}
56+
});
57+
}
6058
});
59+
6160
});
6261

test/events/all.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Test individual events extracts.
3-
*
3+
*
44
* The tests run against the curated view of the extracts.
5-
*
5+
*
66
* Note: the tests are not run against the `@webref/events` package view of
77
* the data because that view is a strict subset of the curated view.
88
*/
99

10-
import { describe, it, before } from 'node:test';
10+
import { describe, it } from 'node:test';
1111
import { strict as assert } from 'node:assert';
1212
import path from 'node:path';
1313
import { fileURLToPath } from 'node:url';
@@ -30,9 +30,14 @@ function report(msg, event) {
3030
(event.href ? ` href=${event.href}` : '');
3131
}
3232

33-
before(async () => {
33+
describe("the events data", async () => {
3434
// Create a set of well-known interfaces and an inheritance chain
35-
const allIdl = await idl.parseAll({ folder: path.join(curatedFolder, 'idl') });
35+
let allIdl;
36+
try {
37+
allIdl = await idl.parseAll({ folder: path.join(curatedFolder, 'idl') });
38+
} catch (err) {
39+
it('contains data that can be parsed with webidl2.js', () => {throw err;});
40+
}
3641
const parsedInterfaces = [];
3742
const mixins = new Set();
3843
for (const [shortname, ast] of Object.entries(allIdl)) {

0 commit comments

Comments
 (0)