Registry / testing / rescript-test

rescript-test

JSON →
library8.0.0jsnpmunverified

rescript-test is a lightweight and performant test framework designed specifically for ReScript projects. Currently at version 8.0.0, it provides a native ReScript API for writing unit and integration tests, leveraging ReScript's type system for robust assertions. It integrates directly into the ReScript build pipeline, running compiled `.bs.js` files. The framework offers core testing primitives like `test`, `testAsync`, and flexible `assertion` functions, alongside utilities for setup/teardown and optional DOM simulation via JSDOM. It aims to provide a straightforward, type-safe testing experience tailored for the ReScript ecosystem, differentiating itself from general JavaScript test runners by its deep integration with ReScript's language features. It appears to be actively maintained, with updates typically correlating with ReScript compiler releases.

testing
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The `retest` command-line interface (CLI) is the primary way to execute tests written with `rescript-test`. The actual testing API (`test`, `assertion`, etc.) is consumed directly within ReScript source files (`.res`) using `open Test` and does not expose direct JavaScript module imports for these functions. Attempting to import or require it in JavaScript code will result in module not found errors for the testing API itself.

npx retest 'test/**/*.bs.js'

Within ReScript source files, the `Test` module is made available via `open Test` at the top of your test file, similar to importing a namespace in other languages. This exposes functions like `test`, `assertion`, `throws`, etc., for use in your ReScript code.

open Test

Demonstrates how to install `rescript-test`, configure `bsconfig.json`, write a basic ReScript test file with custom assertions, and execute it using the `retest` CLI.

yarn add --dev rescript-test # Add to bsconfig.json: # { # "bs-dev-dependencies": [ # "rescript-test" # ] # } # Create test/MyTest.res // test/MyTest.res open Test let intEqual = (~message=?, a: int, b: int) => assertion(~message?, ~operator="intEqual", (a, b) => a === b, a, b) test("Basic integer equality", () => { let actual = 1 + 1 let expected = 2 intEqual(~message="1 + 1 should be 2", actual, expected) }) test("Async operation test", () => { // In a real scenario, this would involve a Promise or callback // For simplicity, showing a synchronous pass. pass() }) # Run the tests npx retest 'test/**/*.bs.js'
Debug
Known footguns
breakingThis package is a ReScript-native testing framework and requires the ReScript compiler (version ^12.0.1 or higher) as a peer dependency. Using it with significantly older ReScript versions will lead to compilation errors or unexpected runtime behavior.
breakingThe `retest` CLI requires Node.js version 20.0.0 or higher. Running it with older Node.js versions will result in execution failures.
gotchaThe `rescript-test` API (e.g., `test`, `assertion`) is designed for use within ReScript source files (`.res`). There are no direct JavaScript module exports for these testing utilities. Attempts to `import` or `require` them directly in JavaScript or TypeScript files will fail.
gotchaTo enable DOM testing functionality, the `--with-dom` flag must be explicitly passed to the `retest` CLI. This feature relies on `jsdom` which is an optional peer dependency; ensure it's installed if you intend to use DOM testing.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
4
ahrefsbot
3
script
1
bingbot
1
Resources