[test] Enable "use forget" directive in tests

This commit is contained in:
Sathya Gunasekaran
2023-03-06 19:53:54 +00:00
parent 8c24fc2be2
commit c642de322c
@@ -42,7 +42,14 @@ expect.extend({
export default function generateTestsFromFixtures(
fixturesPath: string,
transform: (input: string, file: any, options: { debug: boolean }) => string
transform: (
input: string,
file: any,
options: {
debug: boolean;
enableOnlyOnUseForgetDirective: boolean;
}
) => string
) {
const files = fs.readdirSync(fixturesPath);
const fixtures = matchInputOutputFixtures(files, fixturesPath);
@@ -75,6 +82,8 @@ export default function generateTestsFromFixtures(
let testCommand = test;
let input: string | null = null;
let debug = false;
let enableOnlyOnUseForgetDirective = false;
if (inputFile != null) {
input = fs.readFileSync(inputFile, "utf8");
const lines = input.split("\n");
@@ -85,12 +94,18 @@ export default function generateTestsFromFixtures(
if (lines[0]!.indexOf("@skip") !== -1) {
testCommand = test.skip;
}
if (lines[0]!.indexOf("@forgetDirective") !== -1) {
enableOnlyOnUseForgetDirective = true;
}
}
testCommand(basename, () => {
let receivedOutput;
if (input !== null) {
receivedOutput = transform(input, basename, { debug });
receivedOutput = transform(input, basename, {
debug,
enableOnlyOnUseForgetDirective,
});
} else {
receivedOutput = "<<input deleted>>";
}