Skip to content

Commit bdc29df

Browse files
committed
Fix default includes/excludes in Jest integration
The Jest integration should also use the same default include/exclude pattern as the standalone version. Any "cleanup" or translation of the settings has to be applied for both cases.
1 parent 2412c64 commit bdc29df

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

fuzztests/instrument.fuzz.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ describe("instrument", () => {
3333

3434
const check = shouldInstrumentFn(includes, excludes);
3535

36-
const includeAll = includes.some((e) => e === "");
37-
const excludeAll = excludes.some((e) => e === "");
36+
const includeAll = includes.some((e) => e === "*");
37+
const excludeAll = excludes.some((e) => e === "*");
3838

3939
if (excludeAll) {
4040
expect(check).toBeFalsy();

packages/core/cli.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,8 @@ yargs(process.argv.slice(2))
160160
startFuzzing({
161161
fuzzTarget: ensureFilepath(args.fuzzTarget),
162162
fuzzEntryPoint: args.fuzzFunction,
163-
includes: args.instrumentation_includes.map((include: string) =>
164-
// empty string matches every file
165-
include === "*" ? "" : include
166-
),
167-
excludes: args.instrumentation_excludes.map((exclude: string) =>
168-
// empty string matches every file
169-
exclude === "*" ? "" : exclude
170-
),
163+
includes: args.instrumentation_includes,
164+
excludes: args.instrumentation_excludes,
171165
dryRun: args.dry_run,
172166
sync: args.sync,
173167
fuzzerOptions: args.corpus.concat(args._),

packages/instrumentor/instrument.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ describe("shouldInstrument check", () => {
3333
expect(check("/something/else")).toBeFalsy();
3434
});
3535

36-
it("should include everything with emptystring", () => {
37-
const check = shouldInstrumentFn([""], []);
36+
it("should include everything with *", () => {
37+
const check = shouldInstrumentFn(["*"], []);
3838
expect(check("include")).toBeTruthy();
3939
expect(check("/something/else")).toBeTruthy();
4040
});
4141

42+
it("should include nothing with emtpy string", () => {
43+
const emtpyInclude = shouldInstrumentFn(["include", ""], []);
44+
expect(emtpyInclude("include")).toBeTruthy();
45+
expect(emtpyInclude("/something/else")).toBeFalsy();
46+
const emtpyExclude = shouldInstrumentFn(["include"], [""]);
47+
expect(emtpyExclude("include")).toBeTruthy();
48+
expect(emtpyExclude("/something/else")).toBeFalsy();
49+
});
50+
4251
it("should exclude with precedence", () => {
43-
const check = shouldInstrumentFn(["include"], [""]);
52+
const check = shouldInstrumentFn(["include"], ["*"]);
4453
expect(check("/some/package/include/files")).toBeFalsy();
4554
});
4655
});

packages/instrumentor/instrument.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ export function shouldInstrumentFn(
9393
includes: string[],
9494
excludes: string[]
9595
): FilePredicate {
96+
const cleanup = (settings: string[]) =>
97+
settings
98+
.filter((setting) => setting)
99+
.map((setting) => (setting === "*" ? "" : setting)); // empty string matches every file
100+
const cleanedIncludes = cleanup(includes);
101+
const cleanedExcludes = cleanup(excludes);
96102
return (filepath: string) => {
97103
const included =
98-
includes.find((include) => filepath.includes(include)) !== undefined;
104+
cleanedIncludes.find((include) => filepath.includes(include)) !==
105+
undefined;
99106
const excluded =
100-
excludes.find((exclude) => filepath.includes(exclude)) !== undefined;
107+
cleanedExcludes.find((exclude) => filepath.includes(exclude)) !==
108+
undefined;
101109
return included && !excluded;
102110
};
103111
}

0 commit comments

Comments
 (0)