forked from tc39/proposal-change-array-by-copy
/
polyfill.test262.mjs
55 lines (49 loc) · 1.35 KB
/
polyfill.test262.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from "path";
import tape from "tape";
import Test262Stream from "test262-stream";
import NodeAgent from "eshost/lib/agents/node.js";
import { readFileSync } from "fs";
const POLYFILL = readFileSync(
new URL("./polyfill.js", import.meta.url),
"utf-8"
);
const agent = new NodeAgent({
hostPath: process.argv0,
transform(source) {
return POLYFILL + ";\n" + source;
},
});
const testsPaths = [
["Array", "toReversed"],
["Array", "toSorted"],
["Array", "toSpliced"],
["Array", "with"],
["Array", "Symbol.unscopables/change-array-by-copy.js"],
["TypedArray", "toReversed"],
["TypedArray", "toSorted"],
["TypedArray", "with"],
].map(
([constructor, method]) => `test/built-ins/${constructor}/prototype/${method}`
);
const tests = new Test262Stream(
new URL("./test262", import.meta.url).pathname,
{ paths: testsPaths }
);
for await (const test of tests) {
tape(`[${test.file}] ${test.attrs.description}`, async (t) => {
const result = await timeout(30_000, agent.evalScript(test));
if (result.error) {
t.fail(Object.assign(new Error(), result.error));
} else {
t.pass("PASSED");
}
t.end();
});
}
function timeout(time, promise) {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error("Timed out")), time);
promise.finally(() => clearTimeout(timeout));
promise.then(resolve, reject);
});
}