Skip to content

Commit d4ba342

Browse files
committed
Jest support: List fuzz test names if 'JAZZER_LIST_FUZZTEST_NAMES' is set
Futhermore will filter the list by regex if 'JAZZER_LIST_FUZZTEST_NAMES_PATTERN' is set.
1 parent ff15b22 commit d4ba342

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

packages/jest-runner/fuzz.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ export const skip: (globals: Global.Global) => FuzzTest =
4949

5050
export type JestTestMode = "skip" | "only" | "standard";
5151

52+
function printTestNameIfRequested(testStatePath: string[]) {
53+
const full_name: string = testStatePath.join(" ");
54+
if (process.env.JAZZER_LIST_FUZZTEST_NAMES) {
55+
if (
56+
process.env.JAZZER_LIST_FUZZTEST_NAMES_PATTERN == undefined ||
57+
full_name.match(process.env.JAZZER_LIST_FUZZTEST_NAMES_PATTERN)
58+
) {
59+
if (process.env.JAZZER_LIST_FUZZTEST_NAMES == "short") {
60+
const short_name: string = testStatePath.pop() || "";
61+
console.log(short_name);
62+
} else if (process.env.JAZZER_LIST_FUZZTEST_NAMES == "split") {
63+
const split_name: string = testStatePath.join(" / ");
64+
console.log(split_name);
65+
} else {
66+
console.log(full_name);
67+
}
68+
}
69+
}
70+
}
71+
5272
export function fuzz(
5373
globals: Global.Global,
5474
testFile: string,
@@ -72,6 +92,9 @@ export function fuzz(
7292
// only the requested tests are executed.
7393
const testStatePath = currentTestStatePath(toTestName(name), state);
7494
const testNamePattern = originalTestNamePattern();
95+
96+
printTestNameIfRequested(testStatePath);
97+
7598
const skip =
7699
testStatePath !== undefined &&
77100
testNamePattern != undefined &&

tests/jest_integration/integration.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,66 @@ describe("Jest integration", () => {
354354
});
355355
});
356356
});
357+
358+
describe("List all fuzz tests", () => {
359+
const listFuzzTestNamesTestBuilder = new FuzzTestBuilder()
360+
.dir(projectDir)
361+
.listFuzzTestNames()
362+
.jestTestFile(jestTestFile + ".js");
363+
364+
it("lists fuzz tests", () => {
365+
const listFuzzTestNames = listFuzzTestNamesTestBuilder.build();
366+
367+
listFuzzTestNames.execute();
368+
369+
expect(listFuzzTestNames.stdout).toContain(
370+
"Jest Integration execute sync test",
371+
);
372+
expect(listFuzzTestNames.stdout).toContain(
373+
"Run mode skip and standard standard test",
374+
);
375+
});
376+
377+
it("filters fuzz tests by name", () => {
378+
const listFuzzTestNames = listFuzzTestNamesTestBuilder
379+
.listFuzzTestNamesPattern("sync test")
380+
.build();
381+
382+
listFuzzTestNames.execute();
383+
384+
expect(listFuzzTestNames.stdout).toContain(
385+
"Jest Integration execute sync test",
386+
);
387+
expect(listFuzzTestNames.stdout).not.toContain(
388+
"Run mode skip and standard standard test",
389+
);
390+
});
391+
392+
it("filters fuzz tests by describe name", () => {
393+
const listFuzzTestNames = listFuzzTestNamesTestBuilder
394+
.listFuzzTestNamesPattern("Jest")
395+
.build();
396+
397+
listFuzzTestNames.execute();
398+
399+
expect(listFuzzTestNames.stdout).toContain(
400+
"Jest Integration execute sync test",
401+
);
402+
expect(listFuzzTestNames.stdout).not.toContain(
403+
"Run mode skip and standard standard test",
404+
);
405+
});
406+
407+
it("prints nothing else on stdout", () => {
408+
const listFuzzTestNames = listFuzzTestNamesTestBuilder
409+
.listFuzzTestNamesPattern("__NOT_AN_ACTUAL_TESTNAME__")
410+
.build();
411+
412+
listFuzzTestNames.execute();
413+
414+
expect(listFuzzTestNames.stdout).toBe("");
415+
});
416+
});
357417
});
358418

359419
// Deflake the "timeout after N seconds" test to be more tolerant to small variations of N (+-1).

0 commit comments

Comments
 (0)