-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
test.js
57 lines (46 loc) · 1.58 KB
/
test.js
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
56
57
/* eslint-env node, jest */
"use strict";
const fs = require("fs");
const path = require("path");
const Transformer = require("..");
const rootDir = path.resolve(__dirname, "..");
const casesDir = path.resolve(__dirname, "cases");
const implsDir = path.resolve(__dirname, "implementations");
const outputDir = path.resolve(__dirname, "output");
beforeAll(() => {
const transformer = new Transformer({
processCEReactions(code) {
const preSteps = this.addImport("../CEReactions", "preSteps");
const postSteps = this.addImport("../CEReactions", "postSteps");
return `
${preSteps}(globalObject);
try {
${code}
} finally {
${postSteps}(globalObject);
}
`;
},
processHTMLConstructor() {
const identifier = this.addImport("../HTMLConstructor", "HTMLConstructor");
return `
return ${identifier}.HTMLConstructor(globalObject);
`;
}
});
transformer.addSource(casesDir, implsDir);
return transformer.generate(outputDir);
});
const idlFiles = fs.readdirSync(casesDir);
for (const idlFile of idlFiles) {
test(idlFile, () => {
const outputFile = path.resolve(outputDir, path.basename(idlFile, ".webidl") + ".js");
const output = fs.readFileSync(outputFile, { encoding: "utf-8" });
expect(output).toMatchSnapshot();
});
}
test("utils.js", () => {
const input = fs.readFileSync(path.resolve(rootDir, "lib/output/utils.js"), { encoding: "utf-8" });
const output = fs.readFileSync(path.resolve(outputDir, "utils.js"), { encoding: "utf-8" });
expect(output).toBe(input);
});