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 .github/workflows/prerelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.os, 'windows')
- name: install dependencies
run: npm install --ws=@jazzer.js/fuzzer
run: npm ci --ws=@jazzer.js/fuzzer
- name: build and upload prebuilds
run: >
npm run prebuild --workspace=@jazzer.js/fuzzer -- ${{ matrix.opts }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
cache: "npm"
registry-url: https://registry.npmjs.org
- name: install & build
run: npm install && npm run build
run: npm ci && npm run build
- name: publish to npm
run: npm publish --workspaces --access public
env:
Expand Down
84 changes: 79 additions & 5 deletions .github/workflows/run-all-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
node-version: 16
cache: "npm"
- name: install dependencies
run: npm install
run: npm ci
- name: install dependencies with apt
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Expand All @@ -39,26 +39,65 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
os: [windows-2019, macos-11, ubuntu-20.04]
node: [16]
include:
# Test all LTS versions on Linux
- os: ubuntu-20.04
node: 18
- os: ubuntu-20.04
node: 20
steps:
- name: checkout
uses: actions/checkout@v3
- name: node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: ${{ matrix.node }}
cache: "npm"
- name: MSVC (windows)
uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.os, 'windows')
- name: install dependencies
run: npm install
run: npm ci
- name: build project
run: npm run build
- name: build fuzzer
run: npm run build --workspace=@jazzer.js/fuzzer
- name: run all tests
run: npm run test
examples:
name: examples
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2019, macos-11, ubuntu-20.04]
node: [16]
include:
# Test all LTS versions on Linux
- os: ubuntu-20.04
node: 18
- os: ubuntu-20.04
node: 20
steps:
- name: checkout
uses: actions/checkout@v3
- name: node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "npm"
- name: MSVC (windows)
uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.os, 'windows')
- name: install dependencies
run: npm ci
- name: build project
run: npm run build
- name: build fuzzer
run: npm run build --workspace=@jazzer.js/fuzzer
- name: run all examples
run: npm run example
fuzz_tests:
name: fuzz tests
runs-on: ubuntu-20.04
Expand All @@ -71,7 +110,7 @@ jobs:
node-version: 16
cache: "npm"
- name: install dependencies
run: npm install
run: npm ci
- name: build project
run: npm run build
- name: build fuzzer
Expand All @@ -84,6 +123,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3
# Build with node.js 16
- name: node
uses: actions/setup-node@v3
with:
Expand All @@ -93,12 +133,46 @@ jobs:
run: cd end-to-end && ./package-jazzer-js.sh
- name: build example
run: cd end-to-end && npm install --save-dev *.tgz && npm run build

# Run with different node.js versions
# all in one job to avoid rebuilding
- name: "node 14"
uses: actions/setup-node@v3
with:
node-version: 14
cache: "npm"
- name: run tests
run: cd end-to-end && npx jest

- name: "node 16"
uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
- name: run tests
run: cd end-to-end && npx jest

- name: "node 18"
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
- name: run tests
run: cd end-to-end && npx jest

- name: "node 20"
uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"
- name: run tests
run: cd end-to-end && npx jest

auto-merge:
needs:
- linting
- unit_tests
- examples
- fuzz_tests
- end-to-end
permissions:
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ Jazzer.js is a coverage-guided, in-process fuzzer for the
[libFuzzer](https://llvm.org/docs/LibFuzzer.html) and brings many of its
instrumentation-powered mutation features to the JavaScript ecosystem.

Jazzer.js currently supports the following platforms:

- Linux x86_64
- macOS x86_64 and arm64
- Windows x86_64

## Quickstart

To use Jazzer.js in your own project follow these few simple steps:
Expand Down Expand Up @@ -143,6 +137,15 @@ own projects. If you are just getting started, this might be helpful.

You can watch the recording [here](https://youtu.be/KyIhxEiNnfc).

## Supported Architectures

Jazzer.js supports Node.js LTS versions on the following platforms, other
versions are best effort only:

- Linux x86_64
- macOS x86_64 and arm64
- Windows x86_64

## Credit

Jazzer.js is inspired by its namesake
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
"clean": "rimraf -g **/node_modules **/tests/**/package-lock.json **/examples/**/package-lock.json **/dist **/coverage packages/fuzzer/build packages/fuzzer/prebuilds",
"compile:watch": "tsc -b tsconfig.build.json --incremental --pretty --watch",
"test": "run-script-os",
"test:jest": "jest && npm run test --ws --if-present",
"test:coverage": "jest --coverage",
"test:default": "npm run test:jest",
"test:linux:darwin": "npm run test:jest && cd examples && sh ../scripts/run_all.sh dryRun && cd ../tests && sh ../scripts/run_all.sh fuzz",
"test:win32": "npm run test:jest && cd examples && ..\\scripts\\run_all.bat dryRun && cd ..\\tests && ..\\scripts\\run_all.bat fuzz",
"test:watch": "jest --watch",
"test:linux:darwin": "npm run test:jest && cd tests && sh ../scripts/run_all.sh fuzz",
"test:win32": "npm run test:jest && cd tests && ..\\scripts\\run_all.bat fuzz",
"test:jest": "jest && npm run test --ws --if-present",
"test:jest:coverage": "jest --coverage",
"test:jest:watch": "jest --watch",
"example": "run-script-os",
Comment thread
bertschneider marked this conversation as resolved.
"example:linux:darwin": "cd examples && sh ../scripts/run_all.sh dryRun",
"example:win32": "cd examples && ..\\scripts\\run_all.bat dryRun",
"lint": "eslint . && npm run lint --ws --if-present",
"lint:fix": "eslint . --fix && npm run lint:fix --ws --if-present",
"format": "prettier --check . && npm run format --ws --if-present",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/finding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { sep } from "path";

import { Finding, printFinding } from "./finding";
import { replaceAll } from "./utils";

describe("Finding", () => {
it("print a cleaned up finding", () => {
Expand Down Expand Up @@ -92,5 +93,5 @@ function mockPrinter() {
}

function withSystemSeparator(text: string): string {
return text.replaceAll(/\//g, sep);
return replaceAll(text, /\//g, sep);
}
16 changes: 9 additions & 7 deletions packages/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import fs from "fs";
import * as tmp from "tmp";

import { useDictionaryByParams } from "./dictionary";
import { replaceAll } from "./utils";

/**
* Jazzer.js options structure expected by the fuzzer.
Expand Down Expand Up @@ -86,12 +87,11 @@ export const defaultOptions: Options = Object.freeze({

export type KeyFormatSource = (key: string) => string;
export const fromCamelCase: KeyFormatSource = (key: string): string => key;

export const fromSnakeCase: KeyFormatSource = (key: string): string => {
return key
.toLowerCase()
.replaceAll(/(_[a-z0-9])/g, (group) =>
group.toUpperCase().replace("_", ""),
);
return replaceAll(key.toLowerCase(), /(_[a-z0-9])/g, (group) =>
group.toUpperCase().replace("_", ""),
);
};
export const fromSnakeCaseWithPrefix: (prefix: string) => KeyFormatSource = (
prefix: string,
Expand Down Expand Up @@ -201,12 +201,14 @@ function mergeOptions(
): Options {
// Deep close the default options to avoid mutation.
const options: Options = JSON.parse(JSON.stringify(defaults));
if (!input || typeof input !== "object") {
if (!options || !input || typeof input !== "object") {
return options;
}
Object.keys(input as object).forEach((key) => {
const transformedKey = transformKey(key);
if (!Object.hasOwn(options, transformedKey)) {
// Use hasOwnProperty to still support node v14.
// eslint-disable-next-line no-prototype-builtins
if (!(options as object).hasOwnProperty(transformedKey)) {
if (errorOnUnknown) {
throw new Error(`Unknown Jazzer.js option '${key}'`);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ export async function importModule(name: string): Promise<FuzzModule | void> {
return import(name);
}

export function replaceAll(
text: string,
pattern: RegExp,
replacer: string | ((substring: string) => string),
): string {
// Don't use replaceAll to support node v14.
let previous = text;
let current = previous;
do {
previous = current;
// Without explicit cast TS can not figure out that both types of replacer are valid.
current = previous.replace(pattern, replacer as string);
} while (current !== previous);
return current;
}

export function ensureFilepath(filePath: string): string {
if (!filePath || filePath.length === 0) {
throw Error("Empty filepath provided");
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2022",
"target": "ES2020",
"module": "NodeNext",
"baseUrl": "./",
"allowJs": true,
Expand Down