-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathrun-test.js
More file actions
88 lines (76 loc) · 2.4 KB
/
run-test.js
File metadata and controls
88 lines (76 loc) · 2.4 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { FULL_TEST } from "./constants.js";
import { replacePlaceholders } from "./replace-placeholders.js";
import { format } from "./run-prettier.js";
import * as testAstCompare from "./test-ast-compare.js";
import * as testBom from "./test-bom.js";
import * as testEndOfLine from "./test-end-of-line.js";
import * as testFormat from "./test-format.js";
import * as testSecondFormat from "./test-second-format.js";
import * as testBytecodeCompare from "./test-bytecode-compare.js";
import * as testAntlrFormat from "./test-antlr-format.js";
import * as testVariantCoverage from "./test-variant-coverage.js";
import { shouldThrowOnFormat } from "./utilities.js";
async function testFixture(fixture) {
const { name, context } = fixture;
const { stringifiedOptions, parsers } = context;
const title = `${name}${
stringifiedOptions ? ` - ${stringifiedOptions}` : ""
}`;
describe(title, () => {
const testCases = parsers.map((parser) => getTestCase(fixture, parser));
for (const testCase of testCases) {
const testTitle =
testCase.expectFail || testCase.formatOptions.parser !== testCase.parser
? `[${testCase.parser}] format`
: "format";
test(testTitle, async () => {
await testFormat.run(testCase);
if (!FULL_TEST) {
return;
}
await Promise.all(
[
testAntlrFormat.run,
testVariantCoverage.run,
testSecondFormat.run,
testAstCompare.run,
testBom.run,
testBytecodeCompare.run,
]
.map((test) => test(testCase))
.join(
["\r\n", "\r"].map((eol) => testEndOfLine.run(testCase, eol)),
),
);
});
}
});
}
function getTestCase(fixture, parser) {
const { code: originalText, context, filepath } = fixture;
const { text: code, options: formatOptions } = replacePlaceholders(
originalText,
{
printWidth: 80,
...context.options,
filepath,
parser,
},
);
const expectFail = shouldThrowOnFormat(fixture, formatOptions);
let promise;
return {
context,
parser,
filepath,
originalText,
code,
formatOptions,
expectFail,
expectedOutput: fixture.output,
isEmpty: code.trim() === "",
runFormat: () =>
promise === undefined ? (promise = format(code, formatOptions)) : promise,
};
}
export { testFixture };