[test] Enable "use forget" directive in tests
Sathya Gunasekaran committed
Mar 6, 2023 at 19:53 UTC
c642de322cf3892cdec4544b42ce5c3527180871
1 file changed
+17
-2
compiler/forget/src/__tests__/test-utils/generateTestsFromFixtures.ts
+17
-2
@@ -42,7 +42,14 @@ expect.extend({
42
43
export default function generateTestsFromFixtures(
44
fixturesPath: string,
45
- transform: (input: string, file: any, options: { debug: boolean }) => string
45
+ transform: (
46
+ input: string,
47
+ file: any,
48
+ options: {
49
+ debug: boolean;
50
+ enableOnlyOnUseForgetDirective: boolean;
51
+ }
52
+ ) => string
53
) {
54
const files = fs.readdirSync(fixturesPath);
55
const fixtures = matchInputOutputFixtures(files, fixturesPath);
@@ -75,6 +82,8 @@ export default function generateTestsFromFixtures(
82
let testCommand = test;
83
let input: string | null = null;
84
let debug = false;
85
+ let enableOnlyOnUseForgetDirective = false;
86
+
87
if (inputFile != null) {
88
input = fs.readFileSync(inputFile, "utf8");
89
const lines = input.split("\n");
@@ -85,12 +94,18 @@ export default function generateTestsFromFixtures(
94
if (lines[0]!.indexOf("@skip") !== -1) {
95
testCommand = test.skip;
96
}
97
+ if (lines[0]!.indexOf("@forgetDirective") !== -1) {
98
+ enableOnlyOnUseForgetDirective = true;
99
+ }
100
}
101
102
testCommand(basename, () => {
103
let receivedOutput;
104
if (input !== null) {
93
- receivedOutput = transform(input, basename, { debug });
105
+ receivedOutput = transform(input, basename, {
106
+ debug,
107
+ enableOnlyOnUseForgetDirective,
108
+ });
109
} else {
110
receivedOutput = "<<input deleted>>";
111
}