@@ -47,8 +47,8 @@ export class Instrumentor {
47
47
private readonly includes : string [ ] = [ "*" ] ,
48
48
private readonly excludes : string [ ] = [ "node_modules" ] ,
49
49
private readonly customHooks : string [ ] = [ ] ,
50
- private readonly collectSourceCodeCoverage = false ,
51
- private readonly dryRun = false ,
50
+ private readonly shouldCollectSourceCodeCoverage = false ,
51
+ private readonly isDryRun = false ,
52
52
private readonly idStrategy : EdgeIdStrategy = new MemorySyncIdStrategy ( )
53
53
) { }
54
54
@@ -62,7 +62,7 @@ export class Instrumentor {
62
62
instrument ( code : string , filename : string ) : string {
63
63
const transformations : PluginItem [ ] = [ ] ;
64
64
65
- const shouldInstrumentFile = this . shouldInstrument ( filename ) ;
65
+ const shouldInstrumentFile = this . shouldInstrumentForFuzzing ( filename ) ;
66
66
67
67
if ( shouldInstrumentFile ) {
68
68
transformations . push ( codeCoverage ( this . idStrategy ) , compareHooks ) ;
@@ -72,14 +72,14 @@ export class Instrumentor {
72
72
transformations . push ( functionHooks ( filename ) ) ;
73
73
}
74
74
75
- if ( shouldInstrumentFile ) {
76
- this . idStrategy . startForSourceFile ( filename ) ;
77
- }
78
-
79
75
if ( this . shouldCollectCodeCoverage ( filename ) ) {
80
76
transformations . push ( sourceCodeCoverage ( filename ) ) ;
81
77
}
82
78
79
+ if ( shouldInstrumentFile ) {
80
+ this . idStrategy . startForSourceFile ( filename ) ;
81
+ }
82
+
83
83
const transformedCode =
84
84
this . transform ( filename , code , transformations ) ?. code || code ;
85
85
@@ -156,17 +156,28 @@ export class Instrumentor {
156
156
delete require . cache [ require . resolve ( module ) ] ;
157
157
} ) ;
158
158
}
159
- shouldInstrument (
159
+ shouldInstrumentForFuzzing ( filepath : string ) : boolean {
160
+ return (
161
+ ! this . isDryRun &&
162
+ Instrumentor . doesMatchFilters ( filepath , this . includes , this . excludes )
163
+ ) ;
164
+ }
165
+
166
+ private shouldCollectCodeCoverage ( filepath : string ) : boolean {
167
+ return (
168
+ this . shouldCollectSourceCodeCoverage &&
169
+ ( Instrumentor . doesMatchFilters ( filepath , this . includes , this . excludes ) ||
170
+ Instrumentor . doesMatchFilters ( filepath , this . customHooks , [ "nothing" ] ) )
171
+ ) ;
172
+ }
173
+
174
+ private static doesMatchFilters (
160
175
filepath : string ,
161
- dryRun = this . dryRun ,
162
- includes = this . includes ,
163
- excludes = this . excludes
176
+ includes : string [ ] ,
177
+ excludes : string [ ]
164
178
) : boolean {
165
- if ( dryRun ) {
166
- return false ;
167
- }
168
- const cleanedIncludes = this . cleanup ( includes ) ;
169
- const cleanedExcludes = this . cleanup ( excludes ) ;
179
+ const cleanedIncludes = Instrumentor . cleanup ( includes ) ;
180
+ const cleanedExcludes = Instrumentor . cleanup ( excludes ) ;
170
181
const included =
171
182
cleanedIncludes . find ( ( include ) => filepath . includes ( include ) ) !==
172
183
undefined ;
@@ -176,20 +187,7 @@ export class Instrumentor {
176
187
return included && ! excluded ;
177
188
}
178
189
179
- shouldCollectCodeCoverage ( filepath : string ) : boolean {
180
- const shouldCoverCustomHooks = this . shouldInstrument (
181
- filepath ,
182
- false ,
183
- this . customHooks ,
184
- [ "nothing" ]
185
- ) ;
186
- return (
187
- this . collectSourceCodeCoverage &&
188
- ( shouldCoverCustomHooks || this . shouldInstrument ( filepath , false ) )
189
- ) ;
190
- }
191
-
192
- cleanup ( settings : string [ ] ) : string [ ] {
190
+ private static cleanup ( settings : string [ ] ) : string [ ] {
193
191
return settings
194
192
. filter ( ( setting ) => setting )
195
193
. map ( ( setting ) => ( setting === "*" ? "" : setting ) ) ; // empty string matches every file
0 commit comments