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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ following example:

```typescript
// file: "Target.fuzz.ts"
import "@jazzer.js/jest-runner";
import * as target from "./target";

describe("Target", () => {
Expand Down
8 changes: 2 additions & 6 deletions docs/jest-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ To introduce the `fuzz` function types globally, add the following import to
`globals.d.ts`. This could also be done in the individual test files.

```typescript
import "@jazzer.js/jest-runner/jest-extension";
import "@jazzer.js/jest-runner";
```

To provide accurate coverage reports for TypeScript fuzz tests, make sure to
Expand Down Expand Up @@ -224,12 +224,8 @@ describe("My describe", () => {
After the setup mentioned previously, Jest fuzz tests can be written in
TypeScript, just as one would expect.

**Note**: To satisfy TypeScript's type checker, add an import of
`@jazzer.js/jest-runner/jest-extension` in `globals.d.ts` or in the individual
test file.

```typescript
import "@jazzer.js/jest-runner/jest-extension";
import "@jazzer.js/jest-runner";
import * as target from "./target";

describe("Target", () => {
Expand Down
1 change: 0 additions & 1 deletion examples/jest_typescript_integration/globals.d.ts

This file was deleted.

5 changes: 1 addition & 4 deletions examples/jest_typescript_integration/integration.fuzz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

// Import the fuzz testing extension definition to compile TS code,
// or import it globally in globals.d.ts, like in this example.
// import "@jazzer.js/jest-runner/jest-extension";

import "@jazzer.js/jest-runner";
import * as target from "./target";

describe("Target", () => {
Expand Down
31 changes: 21 additions & 10 deletions packages/jest-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
* limitations under the License.
*/

import { loadConfig } from "./config";
import { cleanupJestRunnerStack } from "./errorUtils";
import { FuzzTest } from "./fuzz";
import { JazzerWorker } from "./worker";
import { registerGlobals, initFuzzing } from "@jazzer.js/core";
import {
TestRunnerOptions,
Test,
TestRunnerContext,
TestWatcher,
CallbackTestRunner,
OnTestFailure,
OnTestStart,
OnTestSuccess,
OnTestFailure,
Test,
TestRunnerContext,
TestRunnerOptions,
TestWatcher,
} from "jest-runner";

import { Config } from "@jest/types";
import { JazzerWorker } from "./worker";
import { registerGlobals, initFuzzing } from "@jazzer.js/core";
import { loadConfig } from "./config";
import { cleanupJestRunnerStack } from "./errorUtils";
import * as reports from "istanbul-reports";

class FuzzRunner extends CallbackTestRunner {
Expand Down Expand Up @@ -97,3 +97,14 @@ class CancelRun extends Error {
}

export default FuzzRunner;

// Global definition of the Jest fuzz test extension function.
// This is required to allow the Typescript compiler to recognize it.
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface It {
fuzz: FuzzTest;
}
}
}
12 changes: 0 additions & 12 deletions packages/jest-runner/jest-extension.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/jest-runner/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { inspect } from "util";
import { fuzz, FuzzerStartError, skip } from "./fuzz";
import { cleanupJestRunnerStack, removeTopFramesFromError } from "./errorUtils";
import { createScriptTransformer } from "@jest/transform";
import "./jest-extension";

function isGeneratorFunction(obj?: unknown): boolean {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"statementMap": {
"0": {
"start": { "line": 17, "column": 0 },
"end": { "line": 17, "column": 47 }
"end": { "line": 17, "column": 32 }
},
"1": {
"start": { "line": 18, "column": 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import "@jazzer.js/jest-runner/jest-extension";
import "@jazzer.js/jest-runner";
import { fuzz } from "./fuzz.js";

describe("My describe", () => {
Expand Down