-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathinput.js
64 lines (55 loc) · 2.13 KB
/
input.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
58
59
60
61
62
63
64
const fs = require("fs");
const path = require("path");
const child_process = require("child_process");
const { bsc_exe: bsc } = require("#cli/bin_path");
const expectedDir = path.join(__dirname, "expected");
const fixtures = fs
.readdirSync(path.join(__dirname, "fixtures"))
.filter((fileName) => path.extname(fileName) === ".res");
// const runtime = path.join(__dirname, '..', '..', 'runtime')
const prefix = `${bsc} -w +A -code-action-data`;
const updateTests = process.argv[2] === "update";
function postProcessErrorOutput(output) {
output = output.trimRight();
output = output.replace(
/\/[^ ]+?jscomp\/build_tests\/editor_tooling_enhancements\//g,
"/.../"
);
return output;
}
let doneTasksCount = 0;
let atLeastOneTaskFailed = false;
fixtures.forEach((fileName) => {
const fullFilePath = path.join(__dirname, "fixtures", fileName);
const command = `${prefix} -color always ${fullFilePath}`;
console.log(`running ${command}`);
child_process.exec(command, (err, stdout, stderr) => {
doneTasksCount++;
// careful of:
// - warning test that actually succeeded in compiling (warning's still in stderr, so the code path is shared here)
// - accidentally succeeding tests (not likely in this context),
// actual, correctly erroring test case
const actualErrorOutput = postProcessErrorOutput(stderr.toString());
const expectedFilePath = path.join(expectedDir, fileName + ".expected");
if (updateTests) {
fs.writeFileSync(expectedFilePath, actualErrorOutput);
} else {
const expectedErrorOutput = postProcessErrorOutput(
fs.readFileSync(expectedFilePath, { encoding: "utf-8" })
);
if (expectedErrorOutput !== actualErrorOutput) {
console.error(
`The old and new error output for the test ${fullFilePath} aren't the same`
);
console.error("\n=== Old:");
console.error(expectedErrorOutput);
console.error("\n=== New:");
console.error(actualErrorOutput);
atLeastOneTaskFailed = true;
}
if (doneTasksCount === fixtures.length && atLeastOneTaskFailed) {
process.exit(1);
}
}
});
});