Skip to content

Commit f249e1f

Browse files
committed
test(jest-runner): keep corpus lookup off tmp parents
Mock the parent directory walk for the missing package.json case so the corpus test stays independent of tmp ancestors on the local machine. Type the readdirSync mock explicitly so TypeScript keeps compiling the test.
1 parent 7db8c66 commit f249e1f

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

packages/jest-runner/corpus.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,28 @@ describe("Corpus", () => {
9595

9696
it("throw error if no package.json was found", () => {
9797
const fuzzTest = mockFuzzTest({ generatePackageJson: false });
98-
expect(() => new Corpus(fuzzTest, [])).toThrow();
98+
const originalReaddirSync = (directoryPath: fs.PathLike): string[] =>
99+
fs.readdirSync(directoryPath);
100+
const readdirSync = jest.spyOn(fs, "readdirSync");
101+
readdirSync.mockImplementation(((directoryPath: fs.PathLike) => {
102+
if (typeof directoryPath === "string") {
103+
const fuzzTestDir = path.dirname(fuzzTest);
104+
if (
105+
directoryPath === fuzzTestDir ||
106+
directoryPath === path.dirname(fuzzTestDir) ||
107+
directoryPath === path.parse(fuzzTestDir).root
108+
) {
109+
return [];
110+
}
111+
}
112+
return originalReaddirSync(directoryPath);
113+
}) as unknown as typeof fs.readdirSync);
114+
115+
try {
116+
expect(() => new Corpus(fuzzTest, [])).toThrow();
117+
} finally {
118+
readdirSync.mockRestore();
119+
}
99120
});
100121
});
101122
});

0 commit comments

Comments
 (0)