-
Notifications
You must be signed in to change notification settings - Fork 34
Support Jest fuzz tests written in TypeScript #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f2d4e4c
Add vscode directory to prettier ignore
bertschneider 8ad0400
Use Jest script transformer to load test modules
bertschneider 5d3c214
Forward input source maps to transformers
bertschneider d40c040
Provide Jest fuzz test type declarations for tests
bertschneider 54295db
Add TypeScript code coverage test
bertschneider effba1d
Add TypeScript example
bertschneider c6667cd
Update TypeScript documentation
bertschneider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ build | |
| coverage | ||
| node_modules | ||
| .idea | ||
| .vscode | ||
| compile_commands.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "includes": ["target"], | ||
| "excludes": ["node_modules"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Jest Typscript Integration Example | ||
|
|
||
| Detailed documentation on the Jest integration is available in the main | ||
| [Jazzer.js](https://github.com/CodeIntelligenceTesting/jazzer.js/blob/main/docs/jest-integration.md) | ||
| documentation. | ||
|
|
||
| ## Quickstart | ||
|
|
||
| To use the [Jest](https://jestjs.io/) integration install the | ||
| `@jazzer.js/jest-runner` and `ts-jest` packages then configure `jest-runner` as | ||
| a dedicated test runner in `package.json` or `jest.config.{ts|js}`. | ||
|
|
||
| The example below shows how to configure the Jazzer.js Jest integration in | ||
| combination with the normal Jest runner. | ||
|
|
||
| ```json | ||
| "jest": { | ||
| "projects": [ | ||
| { | ||
| "displayName": "Jest", | ||
| "preset": "ts-jest", | ||
| }, | ||
| { | ||
| "displayName": { | ||
| "name": "Jazzer.js", | ||
| "color": "cyan", | ||
| }, | ||
| "preset": "ts-jest", | ||
| "runner": "@jazzer.js/jest-runner", | ||
| "testEnvironment": "node", | ||
| "testMatch": ["<rootDir>/*.fuzz.[jt]s"], | ||
| }, | ||
| ], | ||
| "coveragePathIgnorePatterns": ["/node_modules/", "/dist/"], | ||
| "modulePathIgnorePatterns": ["/node_modules", "/dist/"], | ||
| } | ||
| ``` | ||
|
|
||
| Further configuration can be specified in `.jazzerjsrc`, like in any other | ||
| project, in the following format: | ||
|
|
||
| ```json | ||
| { | ||
| "includes": ["*"], | ||
| "excludes": ["node_modules"], | ||
| [...] | ||
| } | ||
| ``` | ||
|
|
||
| Write a Jest fuzz test like: | ||
|
|
||
| ```typescript | ||
| // file: jazzerjs.fuzz.ts | ||
| import "@jazzer.js/jest-runner/jest-extension"; | ||
| describe("My describe", () => { | ||
| it.fuzz("My fuzz test", (data: Buffer) => { | ||
| target.fuzzMe(data); | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| **Note:** the `import` statement extends `jest`'s `It` interface to include the | ||
| `fuzz` property and is necessary for TypeScript to compile the test file. | ||
bertschneider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import "@jazzer.js/jest-runner/jest-extension"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2023 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * 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 * as target from "./target"; | ||
|
|
||
| describe("Target", () => { | ||
oetr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it.fuzz("executes sync methods", (data: Buffer) => { | ||
| target.fuzzMe(data); | ||
| }); | ||
|
|
||
| it.fuzz("executes async methods", async (data: Buffer) => { | ||
| await target.asyncFuzzMe(data); | ||
| }); | ||
|
|
||
| it.fuzz( | ||
| "executes methods with a done callback", | ||
| (data: Buffer, done: (e?: Error) => void) => { | ||
| target.callbackFuzzMe(data, done); | ||
| } | ||
| ); | ||
| }); | ||
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright 2023 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* eslint no-undef: 0 */ | ||
|
|
||
| import * as target from "./target"; | ||
|
|
||
| describe("My describe", () => { | ||
| it("My normal Jest test", () => { | ||
| expect(1).toEqual(1); | ||
| }); | ||
|
|
||
| it("My done callback Jest test", (done) => { | ||
| expect(1).toEqual(1); | ||
| done(); | ||
| }); | ||
|
|
||
| it("My async Jest test", async () => { | ||
| expect(1).toEqual(1); | ||
| }); | ||
|
|
||
| it("Test target function", () => { | ||
| const data = Buffer.from("a"); | ||
| target.fuzzMe(data); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { Config } from "jest"; | ||
|
|
||
| const config: Config = { | ||
| verbose: true, | ||
| projects: [ | ||
| { | ||
| displayName: "Jest", | ||
| preset: "ts-jest", | ||
| }, | ||
| { | ||
| displayName: { | ||
| name: "Jazzer.js", | ||
| color: "cyan", | ||
| }, | ||
| preset: "ts-jest", | ||
| runner: "@jazzer.js/jest-runner", | ||
| testEnvironment: "node", | ||
| testMatch: ["<rootDir>/*.fuzz.[jt]s"], | ||
| }, | ||
| ], | ||
| coveragePathIgnorePatterns: ["/node_modules/", "/dist/"], | ||
| modulePathIgnorePatterns: ["/node_modules", "/dist/"], | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "jest_typescript_integration", | ||
| "version": "1.0.0", | ||
| "description": "An example showing how Jazzer.js integrates with Jest and TypeScript", | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dryRun": "jest", | ||
| "fuzz": "JAZZER_FUZZ=1 jest --coverage", | ||
| "coverage": "jest --coverage" | ||
| }, | ||
| "devDependencies": { | ||
| "@jazzer.js/jest-runner": "file:../../packages/jest-runner", | ||
| "@types/jest": "^29.4.0", | ||
| "jest": "^29.4.1", | ||
| "ts-jest": "^29.0.5", | ||
| "ts-node": "^10.9.1", | ||
| "typescript": "^4.9.5" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.