Skip to content

Commit 7664be7

Browse files
oetrbertschneider
authored andcommitted
Add coverage flag to the internal test helper
1 parent 8932c04 commit 7664be7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/helpers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class FuzzTest {
4040
jestTestFile;
4141
jestTestNamePattern;
4242
jestRunInFuzzingMode;
43+
coverage;
4344

4445
constructor(
4546
sync,
@@ -53,6 +54,7 @@ class FuzzTest {
5354
jestTestFile,
5455
jestTestName,
5556
jestRunInFuzzingMode,
57+
coverage,
5658
) {
5759
this.sync = sync;
5860
this.runs = runs;
@@ -65,6 +67,7 @@ class FuzzTest {
6567
this.jestTestFile = jestTestFile;
6668
this.jestTestNamePattern = jestTestName;
6769
this.jestRunInFuzzingMode = jestRunInFuzzingMode;
70+
this.coverage = coverage;
6871
}
6972

7073
execute() {
@@ -78,6 +81,7 @@ class FuzzTest {
7881
for (const bugDetector of this.disableBugDetectors) {
7982
options.push("--disable_bug_detectors=" + bugDetector);
8083
}
84+
if (this.coverage) options.push("--coverage");
8185
options.push("--");
8286
options.push("-runs=" + this.runs);
8387
if (this.forkMode) options.push("-fork=" + this.forkMode);
@@ -101,6 +105,7 @@ class FuzzTest {
101105
const cmd = "npx";
102106
const options = [
103107
"jest",
108+
this.coverage ? "--coverage" : "",
104109
this.jestTestFile,
105110
'--testNamePattern="' + this.jestTestNamePattern + '"',
106111
];
@@ -145,6 +150,7 @@ class FuzzTestBuilder {
145150
_jestTestFile = "";
146151
_jestTestName = "";
147152
_jestRunInFuzzingMode = false;
153+
_coverage = false;
148154

149155
/**
150156
* @param {boolean} sync - whether to run the fuzz test in synchronous mode.
@@ -241,6 +247,11 @@ class FuzzTestBuilder {
241247
return this;
242248
}
243249

250+
coverage(coverage) {
251+
this._coverage = coverage;
252+
return this;
253+
}
254+
244255
build() {
245256
if (this._jestTestFile === "" && this._fuzzEntryPoint === "") {
246257
throw new Error("fuzzEntryPoint or jestTestFile are not set.");
@@ -262,6 +273,7 @@ class FuzzTestBuilder {
262273
this._jestTestFile,
263274
this._jestTestName,
264275
this._jestRunInFuzzingMode,
276+
this._coverage,
265277
);
266278
}
267279
}

0 commit comments

Comments
 (0)