Skip to content

Commit 83b06cb

Browse files
Restructure tests to drop calls to "before" (#1552)
1 parent 98dfc26 commit 83b06cb

File tree

3 files changed

+168
-164
lines changed

3 files changed

+168
-164
lines changed

test/css/all.js

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* 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';
@@ -28,158 +28,158 @@ const cssValues = [
2828
{ type: 'value space', prop: 'values', value: 'value' }
2929
];
3030

31-
describe(`The curated view of CSS extracts`, () => {
32-
before(async () => {
33-
const all = await css.listAll({ folder: curatedFolder });
34-
const baseProperties = {};
35-
const basePropertiesInDeltaSpecs = {};
36-
const extendedProperties = {};
37-
const selectors = {};
38-
const valuespaces = {};
31+
describe(`The curated view of CSS extracts`, async () => {
32+
let all;
33+
try {
34+
all = await css.listAll({ folder: curatedFolder });
35+
} catch (err) {
36+
it('contains valid JSON data', () => {throw err;});
37+
}
38+
const baseProperties = {};
39+
const basePropertiesInDeltaSpecs = {};
40+
const extendedProperties = {};
41+
const selectors = {};
42+
const valuespaces = {};
3943

40-
for (const [shortname, data] of Object.entries(all)) {
41-
describe(`The CSS extract for ${shortname} in the curated view`, () => {
42-
it('contains a link to the underlying spec', async () => {
43-
assert(data);
44-
assert(data.spec);
45-
assert(data.spec.title);
46-
});
44+
for (const [shortname, data] of Object.entries(all)) {
45+
describe(`The CSS extract for ${shortname} in the curated view`, () => {
46+
it('contains a link to the underlying spec', async () => {
47+
assert(data);
48+
assert(data.spec);
49+
assert(data.spec.title);
50+
});
4751

48-
const spec = index.results.find(s => s.nightly?.url === data.spec.url);
49-
for (const { type, prop, value } of cssValues) {
50-
for (const desc of data[prop]) {
51-
const name = desc.name;
52-
if ((type === 'property') && (spec.seriesComposition !== 'delta') && !desc.newValues) {
53-
if (!baseProperties[name]) {
54-
baseProperties[name] = [];
55-
}
56-
baseProperties[name].push({ spec: data.spec, dfn: desc });
57-
}
58-
else if ((type === 'property') && (spec.seriesComposition === 'delta') && !desc.newValues) {
59-
if (!basePropertiesInDeltaSpecs[name]) {
60-
basePropertiesInDeltaSpecs[name] = [];
61-
}
62-
basePropertiesInDeltaSpecs[name].push({ spec: data.spec, dfn: desc });
63-
}
64-
else if ((type === 'extended property') && desc[value]) {
65-
if (!extendedProperties[name]) {
66-
extendedProperties[name] = [];
67-
}
68-
extendedProperties[name].push({ spec: data.spec, dfn: desc });
52+
const spec = index.results.find(s => s.nightly?.url === data.spec.url);
53+
for (const { type, prop, value } of cssValues) {
54+
for (const desc of data[prop]) {
55+
const name = desc.name;
56+
if ((type === 'property') && (spec.seriesComposition !== 'delta') && !desc.newValues) {
57+
if (!baseProperties[name]) {
58+
baseProperties[name] = [];
6959
}
70-
else if ((type === 'selector') && (spec.seriesComposition !== 'delta')) {
71-
if (!selectors[name]) {
72-
selectors[name] = [];
73-
}
74-
selectors[name].push({ spec: data.spec, dfn: desc });
60+
baseProperties[name].push({ spec: data.spec, dfn: desc });
61+
}
62+
else if ((type === 'property') && (spec.seriesComposition === 'delta') && !desc.newValues) {
63+
if (!basePropertiesInDeltaSpecs[name]) {
64+
basePropertiesInDeltaSpecs[name] = [];
7565
}
76-
else if ((type === 'value space') && (spec.seriesComposition !== 'delta')) {
77-
if (!valuespaces[name]) {
78-
valuespaces[name] = [];
79-
}
80-
valuespaces[name].push({ spec: data.spec, dfn: desc });
66+
basePropertiesInDeltaSpecs[name].push({ spec: data.spec, dfn: desc });
67+
}
68+
else if ((type === 'extended property') && desc[value]) {
69+
if (!extendedProperties[name]) {
70+
extendedProperties[name] = [];
8171
}
82-
if (!desc[value]) {
83-
continue;
72+
extendedProperties[name].push({ spec: data.spec, dfn: desc });
73+
}
74+
else if ((type === 'selector') && (spec.seriesComposition !== 'delta')) {
75+
if (!selectors[name]) {
76+
selectors[name] = [];
8477
}
85-
if (type === 'descriptor') {
86-
for (const dfn of desc[value]) {
87-
it(`defines a valid ${type} "${dfn.name}" for at-rule "${name}"`, () => {
88-
assert.strictEqual(dfn.for, name);
89-
assert.doesNotThrow(() => {
90-
const ast = definitionSyntax.parse(dfn.value);
91-
assert(ast.type);
92-
}, `Invalid definition value: ${dfn.value}`);
93-
});
94-
}
78+
selectors[name].push({ spec: data.spec, dfn: desc });
79+
}
80+
else if ((type === 'value space') && (spec.seriesComposition !== 'delta')) {
81+
if (!valuespaces[name]) {
82+
valuespaces[name] = [];
9583
}
96-
else {
97-
it(`defines a valid ${type} "${name}"`, () => {
84+
valuespaces[name].push({ spec: data.spec, dfn: desc });
85+
}
86+
if (!desc[value]) {
87+
continue;
88+
}
89+
if (type === 'descriptor') {
90+
for (const dfn of desc[value]) {
91+
it(`defines a valid ${type} "${dfn.name}" for at-rule "${name}"`, () => {
92+
assert.strictEqual(dfn.for, name);
9893
assert.doesNotThrow(() => {
99-
const ast = definitionSyntax.parse(desc[value]);
94+
const ast = definitionSyntax.parse(dfn.value);
10095
assert(ast.type);
101-
}, `Invalid definition value: ${desc[value]}`);
102-
});
103-
};
104-
105-
// All CSS values should link back to the spec, except:
106-
// - properties that extend a base property
107-
// - at-rulesdefined elsewhere (and present only because the spec
108-
// defines new descriptors for them)
109-
// - properties in delta specs that completely override the base
110-
// definition - currently enforced more restrictively as
111-
// "the 'contain' property in css-contain-3", to better track such
112-
// occurrences that should remain an exception to the exception rule!
113-
if (!desc.newValues &&
114-
(prop !== 'atrules' || desc.value || desc.prose) &&
115-
!(prop === 'properties' && name === 'contain' && spec.shortname === 'css-contain-3')) {
116-
it(`has a link back to the spec for ${type} "${name}"`, () => {
117-
assert(desc.href);
118-
assert(desc.href.includes('#'));
96+
}, `Invalid definition value: ${dfn.value}`);
11997
});
12098
}
99+
}
100+
else {
101+
it(`defines a valid ${type} "${name}"`, () => {
102+
assert.doesNotThrow(() => {
103+
const ast = definitionSyntax.parse(desc[value]);
104+
assert(ast.type);
105+
}, `Invalid definition value: ${desc[value]}`);
106+
});
107+
};
121108

122-
if (desc.values) {
123-
for (const value of desc.values) {
124-
if (!value.value) {
125-
continue;
126-
}
127-
it(`defines a valid value "${value.name}" for ${type} "${name}"`, () => {
128-
assert.doesNotThrow(() => {
129-
const ast = definitionSyntax.parse(value.value);
130-
assert(ast.type);
131-
}, `Invalid definition value: ${value.value}`);
132-
});
109+
// All CSS values should link back to the spec, except:
110+
// - properties that extend a base property
111+
// - at-rulesdefined elsewhere (and present only because the spec
112+
// defines new descriptors for them)
113+
// - properties in delta specs that completely override the base
114+
// definition - currently enforced more restrictively as
115+
// "the 'contain' property in css-contain-3", to better track such
116+
// occurrences that should remain an exception to the exception rule!
117+
if (!desc.newValues &&
118+
(prop !== 'atrules' || desc.value || desc.prose) &&
119+
!(prop === 'properties' && name === 'contain' && spec.shortname === 'css-contain-3')) {
120+
it(`has a link back to the spec for ${type} "${name}"`, () => {
121+
assert(desc.href);
122+
assert(desc.href.includes('#'));
123+
});
124+
}
133125

134-
it(`has a link back to the spec for value "${value.name}" for ${type} "${name}"`, () => {
135-
assert(value.href);
136-
assert(value.href.includes('#'));
137-
});
126+
if (desc.values) {
127+
for (const value of desc.values) {
128+
if (!value.value) {
129+
continue;
138130
}
131+
it(`defines a valid value "${value.name}" for ${type} "${name}"`, () => {
132+
assert.doesNotThrow(() => {
133+
const ast = definitionSyntax.parse(value.value);
134+
assert(ast.type);
135+
}, `Invalid definition value: ${value.value}`);
136+
});
137+
138+
it(`has a link back to the spec for value "${value.name}" for ${type} "${name}"`, () => {
139+
assert(value.href);
140+
assert(value.href.includes('#'));
141+
});
139142
}
140143
}
141144
}
142-
});
143-
}
144-
145-
describe(`Looking at CSS properties, the curated view`, () => {
146-
for (const [name, dfns] of Object.entries(baseProperties)) {
147-
it(`contains only one "${name}" property definition`, () => {
148-
assert.strictEqual(dfns.length, 1,
149-
`defined in ${dfns.map(d => d.spec.title).join(', ')} (${dfns.map(d => d.spec.url).join(', ')})`);
150-
});
151145
}
152146
});
147+
}
153148

154-
describe(`Looking at CSS selectors, the curated view`, () => {
155-
for (const [name, dfns] of Object.entries(selectors)) {
156-
it(`contains only one "${name}" selector definition`, () => {
157-
assert.strictEqual(dfns.length, 1,
158-
`defined in ${dfns.map(d => d.spec.title).join(', ')} (${dfns.map(d => d.spec.url).join(', ')})`);
159-
});
160-
}
161-
});
149+
describe(`Looking at CSS properties, the curated view`, () => {
150+
for (const [name, dfns] of Object.entries(baseProperties)) {
151+
it(`contains only one "${name}" property definition`, () => {
152+
assert.strictEqual(dfns.length, 1,
153+
`defined in ${dfns.map(d => d.spec.title).join(', ')} (${dfns.map(d => d.spec.url).join(', ')})`);
154+
});
155+
}
156+
});
157+
158+
describe(`Looking at CSS selectors, the curated view`, () => {
159+
for (const [name, dfns] of Object.entries(selectors)) {
160+
it(`contains only one "${name}" selector definition`, () => {
161+
assert.strictEqual(dfns.length, 1,
162+
`defined in ${dfns.map(d => d.spec.title).join(', ')} (${dfns.map(d => d.spec.url).join(', ')})`);
163+
});
164+
}
165+
});
162166

163167

164-
describe(`Looking at extended CSS properties, the curated view`, () => {
165-
for (const [name, dfns] of Object.entries(extendedProperties)) {
166-
it(`contains a base definition for the "${name}" property`, () => {
167-
assert(baseProperties[name] || basePropertiesInDeltaSpecs[name], 'no base definition found');
168-
});
169-
}
170-
});
168+
describe(`Looking at extended CSS properties, the curated view`, () => {
169+
for (const [name, dfns] of Object.entries(extendedProperties)) {
170+
it(`contains a base definition for the "${name}" property`, () => {
171+
assert(baseProperties[name] || basePropertiesInDeltaSpecs[name], 'no base definition found');
172+
});
173+
}
174+
});
171175

172-
describe(`Looking at CSS valuespaces, the curated view`, () => {
173-
for (const [name, dfns] of Object.entries(valuespaces)) {
174-
it(`contains only one "${name}" valuespace definition`, () => {
175-
assert.strictEqual(dfns.length, 1,
176-
`defined in ${dfns.map(d => d.spec.title).join(', ')} (${dfns.map(d => d.spec.url).join(', ')})`);
177-
});
178-
}
179-
});
176+
describe(`Looking at CSS valuespaces, the curated view`, () => {
177+
for (const [name, dfns] of Object.entries(valuespaces)) {
178+
it(`contains only one "${name}" valuespace definition`, () => {
179+
assert.strictEqual(dfns.length, 1,
180+
`defined in ${dfns.map(d => d.spec.title).join(', ')} (${dfns.map(d => d.spec.url).join(', ')})`);
181+
});
182+
}
180183
});
181184

182-
// Dummy test needed for "before" to run and register late tests
183-
// (test will fail if before function throws, e.g. because data is invalid)
184-
it('contains valid JSON data', () => {});
185185
});

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

0 commit comments

Comments
 (0)