Skip to content

Commit 93e26f3

Browse files
committed
Add all webidl interfaces to the same test context
1 parent b6ca097 commit 93e26f3

File tree

1 file changed

+67
-52
lines changed

1 file changed

+67
-52
lines changed

test/harness/index.test.js

+67-52
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ function createSandbox(setupScripts) {
1919
// eslint-disable-next-line global-require
2020
return require(p);
2121
}
22+
if (p.startsWith("../implementations/")) {
23+
return class Stub {};
24+
}
2225

2326
const resolved = path.resolve(__dirname, "../output", p);
2427
const src = readFileSync(resolved, { encoding: "utf8" });
@@ -34,15 +37,7 @@ function createSandbox(setupScripts) {
3437
return sandbox;
3538
}
3639

37-
async function testInterface(name, setupScripts) {
38-
const idlToTest = await fs.readFile(
39-
path.join(__dirname, `../cases/${name}.webidl`),
40-
{
41-
encoding: "utf8"
42-
}
43-
);
44-
45-
const sandbox = createSandbox(setupScripts);
40+
async function prepareInterface({ name, content }, idlArray, sandbox) {
4641
vm.runInContext(
4742
`
4843
Object.defineProperty(self, '${name}', {
@@ -54,47 +49,7 @@ async function testInterface(name, setupScripts) {
5449
sandbox
5550
);
5651

57-
const prom = new Promise((resolve, reject) => {
58-
const errors = [];
59-
60-
sandbox.add_result_callback(test => {
61-
if (test.status === 1) {
62-
errors.push(
63-
`Failed in "${test.name}": \n${test.message}\n\n${test.stack}`
64-
);
65-
} else if (test.status === 2) {
66-
errors.push(
67-
`Timeout in "${test.name}": \n${test.message}\n\n${test.stack}`
68-
);
69-
} else if (test.status === 3) {
70-
errors.push(
71-
`Uncompleted test "${test.name}": \n${test.message}\n\n${test.stack}`
72-
);
73-
}
74-
});
75-
76-
sandbox.add_completion_callback((tests, harnessStatus) => {
77-
if (harnessStatus.status === 2) {
78-
errors.push(new Error(`test harness should not timeout`));
79-
}
80-
81-
if (errors.length === 1) {
82-
reject(new Error(errors[0]));
83-
} else if (errors.length) {
84-
reject(
85-
new Error(`${errors.length} errors in test:\n\n${errors.join("\n")}`)
86-
);
87-
} else {
88-
resolve();
89-
}
90-
});
91-
});
92-
93-
const idlArray = new sandbox.IdlArray();
94-
idlArray.add_idls(idlToTest);
95-
96-
idlArray.test();
97-
await prom;
52+
idlArray.add_idls(content);
9853
}
9954

10055
describe("IDL Harness", () => {
@@ -114,7 +69,67 @@ describe("IDL Harness", () => {
11469
);
11570
});
11671

117-
test("URL.js", async () => {
118-
await testInterface("URL", setupScripts);
72+
const files = ["URL", "Unscopable"];
73+
test(`IDLHarness.js`, async () => {
74+
const idlSources = await Promise.all(
75+
files.map(async f => ({
76+
name: f.replace(/\.webidl$/, ""),
77+
content: await fs.readFile(
78+
path.join(__dirname, `../cases/${f}.webidl`),
79+
{
80+
encoding: "utf8"
81+
}
82+
)
83+
}))
84+
);
85+
const sandbox = createSandbox(setupScripts);
86+
87+
const idlArray = new sandbox.IdlArray();
88+
idlSources.forEach(source => {
89+
prepareInterface(source, idlArray, sandbox);
90+
});
91+
92+
const prom = new Promise((resolve, reject) => {
93+
const errors = [];
94+
95+
sandbox.add_result_callback(test => {
96+
if (test.status === 1) {
97+
errors.push(
98+
`Failed in "${test.name}": \n${test.message}\n\n${test.stack}`
99+
);
100+
} else if (test.status === 2) {
101+
errors.push(
102+
`Timeout in "${test.name}": \n${test.message}\n\n${test.stack}`
103+
);
104+
} else if (test.status === 3) {
105+
errors.push(
106+
`Uncompleted test "${test.name}": \n${test.message}\n\n${
107+
test.stack
108+
}`
109+
);
110+
}
111+
});
112+
113+
sandbox.add_completion_callback((tests, harnessStatus) => {
114+
if (harnessStatus.status === 2) {
115+
errors.push(new Error(`test harness should not timeout`));
116+
}
117+
118+
if (errors.length === 1) {
119+
reject(new Error(errors[0]));
120+
} else if (errors.length) {
121+
reject(
122+
new Error(
123+
`${errors.length} errors in test:\n\n${errors.join("\n")}`
124+
)
125+
);
126+
} else {
127+
resolve();
128+
}
129+
});
130+
});
131+
132+
idlArray.test();
133+
await prom;
119134
});
120135
});

0 commit comments

Comments
 (0)