Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion end-to-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.2.2"
}
}
1 change: 0 additions & 1 deletion end-to-end/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "node",
"allowJs": true,
"rootDir": ".",
"outDir": "./dist",
Expand Down
2 changes: 1 addition & 1 deletion examples/jest_typescript_integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.2.2"
}
}
1 change: 0 additions & 1 deletion examples/jest_typescript_integration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "node",
"allowJs": true,
"rootDir": ".",
"outDir": "./dist",
Expand Down
2 changes: 1 addition & 1 deletion examples/js-yaml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@jazzer.js/core": "file:../../packages/core",
"@types/js-yaml": "^4.0.5",
"typescript": "^4.7.4"
"typescript": "^5.2.2"
},
"dependencies": {
"js-yaml": "^4.1.0"
Expand Down
1 change: 0 additions & 1 deletion examples/js-yaml/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"rootDir": ".",
Expand Down
48 changes: 48 additions & 0 deletions packages/jest-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import type { JestEnvironment } from "@jest/environment";
import { TestResult } from "@jest/test-result";
import { Config } from "@jest/types";
import * as libCoverage from "istanbul-lib-coverage";
import * as reports from "istanbul-reports";
import Runtime from "jest-runtime";

Expand Down Expand Up @@ -71,6 +72,7 @@ export default async function jazzerTestRunner(
testPath,
sendMessageToJest,
).then((result: TestResult) => {
includeImplicitElseBranches(environment.global.__coverage__);
return cleanupTestResultDetails(result);
});
}
Expand All @@ -90,6 +92,52 @@ function cleanupTestResultDetails(result: TestResult) {
return result;
}

/**
* Coverage fix from https://github.com/vitest-dev/vitest/pull/2275
* In our tests this seems to only affect the coverage of TypeScript files,
* hence including the fix in jest-runner should be sufficient.
*
* Original comment:
* Work-around for #1887 and #2239 while waiting for https://github.com/istanbuljs/istanbuljs/pull/706
* Goes through all files in the coverage map and checks if branchMap's have
* if-statements with implicit else. When finds one, copies source location of
* the if-statement into the else statement.
*/
export function includeImplicitElseBranches(
coverageMapData: libCoverage.CoverageMapData,
) {
if (!coverageMapData) {
return;
}
function isEmptyCoverageRange(range: libCoverage.Range) {
return (
range.start === undefined ||
range.start.line === undefined ||
range.start.column === undefined ||
range.end === undefined ||
range.end.line === undefined ||
range.end.column === undefined
);
}
const coverageMap = libCoverage.createCoverageMap(coverageMapData);
for (const file of coverageMap.files()) {
const fileCoverage = coverageMap.fileCoverageFor(file);
for (const branchMap of Object.values(fileCoverage.branchMap)) {
if (branchMap.type === "if") {
const lastIndex = branchMap.locations.length - 1;
if (lastIndex > 0) {
const elseLocation = branchMap.locations[lastIndex];
if (elseLocation && isEmptyCoverageRange(elseLocation)) {
const ifLocation = branchMap.locations[0];
elseLocation.start = { ...ifLocation.start };
elseLocation.end = { ...ifLocation.end };
}
}
}
}
}
}

// Global definition of the Jest fuzz test extension function.
// This is required to allow the Typescript compiler to recognize it.
declare global {
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@jazzer.js/jest-runner",
"version": "2.0.0",
"description": "",
"description": "Jazzer.js Jest runner",
"homepage": "https://github.com/CodeIntelligenceTesting/jazzer.js#readme",
"author": "Code Intelligence",
"license": "Apache-2.0",
Expand All @@ -20,6 +20,10 @@
"cosmiconfig": "^8.3.6",
"istanbul-reports": "^3.1.6"
},
"peerDependencies": {
"@types/jest": "29.*",
"jest": "29.*"
},
"devDependencies": {
"@types/tmp": "^0.2.4",
"tmp": "^0.2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@
"start": { "line": 24, "column": 1 },
"end": { "line": 26, "column": 2 }
},
{ "start": {}, "end": {} }
{
"start": { "line": 24, "column": 1 },
"end": { "line": 26, "column": 2 }
}
],
"line": 24
}
Expand Down Expand Up @@ -164,7 +167,10 @@
"start": { "line": 19, "column": 1 },
"end": { "line": 21, "column": 2 }
},
{ "start": {}, "end": {} }
{
"start": { "line": 19, "column": 1 },
"end": { "line": 21, "column": 2 }
}
],
"line": 19
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@
"start": { "line": 24, "column": 1 },
"end": { "line": 26, "column": 2 }
},
{ "start": {}, "end": {} }
{
"start": { "line": 24, "column": 1 },
"end": { "line": 26, "column": 2 }
}
],
"line": 24
}
Expand Down Expand Up @@ -173,7 +176,10 @@
"start": { "line": 19, "column": 1 },
"end": { "line": 21, "column": 2 }
},
{ "start": {}, "end": {} }
{
"start": { "line": 19, "column": 1 },
"end": { "line": 21, "column": 2 }
}
],
"line": 19
}
Expand Down
2 changes: 1 addition & 1 deletion tests/code_coverage/sample_fuzz_test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@jazzer.js/jest-runner": "file:../../../packages/jest-runner",
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
"typescript": "^5.2.2"
},
"jest": {
"projects": [
Expand Down
19 changes: 9 additions & 10 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ class FuzzTestBuilder {
* @param {boolean} logTestOutput - whether to print the output of the fuzz test to the console.
* True if parameter is undefined.
*/
logTestOutput(logTestOutput) {
this._logTestOutput = logTestOutput === undefined ? true : logTestOutput;
logTestOutput(logTestOutput = true) {
this._logTestOutput = logTestOutput;
return this;
}

Expand All @@ -270,18 +270,17 @@ class FuzzTestBuilder {
/**
* @param {boolean} verbose - set verbose/debug output in fuzz test.
*/
verbose(verbose) {
this._verbose = verbose === undefined ? true : verbose;
verbose(verbose = true) {
this._verbose = verbose;
return this;
}

/**
* @param {boolean} listFuzzTestNames - whether to list all fuzz test names on the console.
* True if parameter is undefined.
*/
listFuzzTestNames(listFuzzTestNames) {
this._listFuzzTestNames =
listFuzzTestNames === undefined ? true : listFuzzTestNames;
listFuzzTestNames(listFuzzTestNames = true) {
this._listFuzzTestNames = listFuzzTestNames;
if (this._listFuzzTestNames) {
this.jestTestName("__NOT_AN_ACTUAL_TESTNAME__");
}
Expand Down Expand Up @@ -425,7 +424,7 @@ class FuzzTestBuilder {
return this;
}

coverage(coverage) {
coverage(coverage = true) {
this._coverage = coverage;
return this;
}
Expand All @@ -435,8 +434,8 @@ class FuzzTestBuilder {
return this;
}

asJson(asJson) {
this._asJson = asJson === undefined ? true : asJson;
asJson(asJson = true) {
this._asJson = asJson;
return this;
}

Expand Down
Loading