Testing¶
The plugin provides integrated test running for ReScript projects that use Jest or Vitest. Tests are run against the compiled JavaScript output, with results displayed in IntelliJ’s standard test runner UI and file paths mapped back to the original .res source files.
Supported Test Frameworks¶
Native
Framework |
Detection Method |
Default Command |
|---|---|---|
Jest |
|
|
Vitest |
|
|
Custom |
Manual configuration |
User-defined |
The plugin automatically detects which framework your project uses. If both are present, Vitest takes priority.
Built-in framework detection means you can start running tests immediately without any manual plugin configuration — just install your preferred test framework and the plugin handles the rest.
Jest Configuration¶
To use Jest with ReScript, you need the following setup:
1. Install dependencies:
{
"devDependencies": {
"jest": "^29.0.0",
"jest-teamcity": "^1.9.0",
"@glennsl/rescript-jest": "^0.11.0"
}
}
The jest-teamcity reporter is required for the plugin to parse test results and display them in the test tree UI. Without it, test output appears as plain console text without structured results.
2. Configure Jest for ReScript:
Create a jest.config.js (or jest.config.ts) that points to the compiled JavaScript output:
{
"testMatch": ["**/lib/js/test/**/*_test.bs.js", "**/lib/js/test/**/*Test.bs.js"],
"moduleDirectories": ["node_modules"],
"transform": {}
}
Key points for the Jest configuration:
testMatch – Point to the compiled
.bs.jsfiles in thelib/js/directory, not the.ressource files. Jest runs JavaScript, so it needs the compiled output.transform – Set to
{}(empty object) to disable all transforms. ReScript already compiles to JavaScript, so no additional transpilation is needed.moduleDirectories – Ensure
node_modulesis included for dependency resolution.
The exact path under lib/ depends on your rescript.json configuration. Common patterns include:
|
Compiled output path |
|---|---|
|
|
|
|
|
|
Vitest Configuration¶
To use Vitest with ReScript, you need the following setup:
1. Install dependencies:
{
"devDependencies": {
"vitest": "^1.0.0"
}
}
Vitest has built-in TeamCity reporter support, so no additional reporter package is needed.
2. Configure Vitest for ReScript:
Create a vitest.config.ts (or vitest.config.js):
{
"test": {
"include": ["lib/js/test/**/*_test.bs.js", "lib/js/test/**/*Test.bs.js"],
"passWithNoTests": true
}
}
Key points for the Vitest configuration:
include – Similar to Jest, point to the compiled JavaScript files in
lib/js/.passWithNoTests – Recommended to avoid failures when no tests match (e.g., during initial setup).
Vitest is invoked with the
runflag (npx vitest run) to execute tests once and exit, rather than entering watch mode.
Running Tests¶
Native
From the Editor¶
Open a ReScript test file (
.res)Right-click on a test function
Select Run to execute the test
From Run Configurations¶
Run → Edit Configurations → + → ReScript Test
Select the test framework (Jest, Vitest, or Custom)
Optionally set a test file path and test name filter
Set the working directory (defaults to the project root)
Click Run
Configuration Options¶
Option |
Description |
|---|---|
Framework |
Jest, Vitest, or Custom |
Working directory |
Project root where |
Test file path |
Path to a specific test file (leave empty to run all tests) |
Test name |
Filter tests by name (uses the |
Additional arguments |
Extra CLI flags passed to the test runner |
Test Auto-Detection¶
Native
The plugin uses two mechanisms to detect test files and frameworks:
Framework Detection¶
The RescriptTestFrameworkDetector identifies which test framework your project uses by examining:
package.jsondependencies – Checks bothdependenciesanddevDependenciesforvitestorjest. Ifvitestis found, it takes priority overjest.Configuration files – If
package.jsondetection fails, the detector looks for framework-specific config files in the project root:
Config file |
Framework |
|---|---|
|
Vitest |
|
Vitest |
|
Vitest |
|
Jest |
|
Jest |
|
Jest |
Test File Detection¶
The plugin automatically recognizes files as test files based on their naming convention. A .res or .resi file is treated as a test file if its name (without extension) ends with any of these suffixes:
_test(e.g.,Math_test.res)Test(e.g.,MathTest.res)_spec(e.g.,Math_spec.res)Spec(e.g.,MathSpec.res)
When you right-click on a file matching this pattern, the plugin offers to create a ReScript Test run configuration automatically, pre-filled with the detected framework and file path.
Automatic detection of test frameworks and test files eliminates manual configuration — the plugin recognizes your testing setup and offers the right run options out of the box.
See also
Run & Build covers run configurations for building the ReScript project.
Test Results¶
Native
Test results are displayed in the standard IntelliJ test runner UI (SMTestRunner).
Test Tree Structure¶
The test results panel displays a hierarchical tree:
Root – The test run
Test Suite – Corresponds to a
describeblock (or a test file)Test Case – Individual test (
testoritblock)
Each node shows:
Pass/fail indicator – Green checkmark for passing tests, red cross for failures
Test name – The name string from your
test()orit()callDuration – Execution time for each test
Output – Stdout/stderr captured during the test
TeamCity Reporter Integration¶
The plugin relies on TeamCity-format reporters to parse test results into the structured tree UI:
Jest: Uses the
jest-teamcityreporter. The plugin automatically adds--reporters=default --reporters=jest-teamcityto the Jest command line.Vitest: Uses the built-in
teamcityreporter. The plugin automatically adds--reporter=default --reporter=teamcityto the Vitest command line.
The default reporter is included alongside the TeamCity reporter so that human-readable output still appears in the console.
How It Works¶
You write tests in
.resfiles using your test framework’s bindings (e.g.,@glennsl/rescript-jest)The ReScript compiler compiles your test
.resfiles to JavaScript in thelib/folderThe plugin runs the compiled
.jsfiles with Jest or Vitest, including TeamCity reportersTest output is parsed by IntelliJ’s SMTestRunner into a structured test tree
File paths in test results are mapped back to the original
.ressource files
// src/test/Math_test.res
open Jest
describe("Math utilities", () => {
test("addition", () => {
expect(MathUtils.add(1, 2))->toBe(3)
})
test("multiplication", () => {
expect(MathUtils.multiply(3, 4))->toBe(12)
})
})
The plugin bridges the gap between ReScript source files and compiled JavaScript test execution, so you work entirely in .res files while the testing infrastructure handles the compilation and path mapping transparently.
Troubleshooting¶
Tests Fail with “Module not found”¶
Cause: The ReScript compiler has not compiled the test files before the test runner executes.
Solution: Run a ReScript Build (or ensure Build (Watch) is running) before executing tests. The test runner executes the compiled JavaScript, so the .bs.js files must exist in the lib/ directory.
# Compile first, then run tests
npx rescript build
npx jest
Tip
Keep a Build (Watch) run configuration running during development. This ensures compiled output is always up to date when you run tests.
Test Tree Shows Plain Text Instead of Structured Results¶
Cause: The TeamCity reporter is not installed or not configured.
Solution:
For Jest: Install
jest-teamcityas a dev dependency (npm install --save-dev jest-teamcity)For Vitest: Ensure you are using Vitest 1.0 or later, which includes the built-in TeamCity reporter
The plugin adds the reporter flags automatically, but the reporter package must be installed in your project.
“package.json not found” Error¶
Cause: The working directory in the run configuration does not contain a package.json file.
Solution: Set the Working directory in the run configuration to your project root (the directory containing package.json and rescript.json). This is typically auto-detected, but may need manual adjustment in monorepo setups.
Framework Not Detected¶
Cause: The test framework is not listed in package.json dependencies.
Solution: Ensure jest or vitest appears in either dependencies or devDependencies in your package.json. Alternatively, select the framework manually in the run configuration, or use the Custom framework option with a user-defined command.
Note
Test running requires that your ReScript project is properly configured with a test framework and that the ReScript compiler has already compiled the test files. The plugin does not automatically trigger a ReScript build before running tests.
These troubleshooting tips address the most common test setup issues, saving you from debugging the build pipeline when the fix is usually a missing dependency or a stale compilation.