Skip to main content

runCLI Options

Jest

Deviation

The Jest packages exports runCLI, which is the main entrypoint to run Jest Roblox tests. In your entrypoint script, import runCLI from the Jest package. A basic entrypoint script can look like the following:

spec.lua
local Packages = script.Parent.YourProject.Packages
local runCLI = require(Packages.Dev.Jest).runCLI

local processServiceExists, ProcessService = pcall(function()
return game:GetService("ProcessService")
end)

local status, result = runCLI(Packages.Project, {
verbose = false,
ci = false
}, { Packages.Project }):awaitStatus()

if status == "Rejected" then
print(result)
end

if status == "Resolved" and result.results.numFailedTestSuites == 0 and result.results.numFailedTests == 0 then
if processServiceExists then
ProcessService:ExitAsync(0)
end
end

if processServiceExists then
ProcessService:ExitAsync(1)
end

return nil

The first argument to runCLI is the root directory of your project, the second argument is a list of options, and the third argument is a list of projects (directories with a jest.config.lua) for Jest Roblox to discover.

Options

Reference

ci [boolean]

Jest Aligned

When this option is provided, Jest Roblox will assume it is running in a CI environment. This changes the behavior when a new snapshot is encountered. Instead of the regular behavior of storing a new snapshot automatically, it will fail the test and require Jest Roblox to be run with updateSnapshot.

clearMocks [boolean]

Jest Aligned

Automatically clear mock calls, instances, contexts and results before every test. Equivalent to calling jest.clearAllMocks() before each test. This does not remove any mock implementation that may have been provided.

debug [boolean]

Jest Aligned

Print debugging info about your Jest config.

expand [boolean]

Jest Aligned

Use this flag to show full diffs and errors instead of a patch.

json [boolean]

Jest Aligned

Prints the test results in JSON. This mode will send all other test output and user messages to stderr.

listTests [boolean]

Jest Aligned

Lists all test files that Jest Roblox will run given the arguments, and exits.

noStackTrace [boolean]

Jest Aligned

Disables stack trace in test results output.

passWithNoTests [boolean]

Jest Aligned

Allows the test suite to pass when no files are found.

resetMocks [boolean]

Jest Aligned

Automatically reset mock state before every test. Equivalent to calling jest.resetAllMocks() before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation.

showConfig [boolean]

Jest Aligned

Print your Jest config and then exits.

testMatch [array<string>]

Jest API Change

The glob patterns Jest uses to detect test files. Please refer to the testMatch configuration for details.

testNamePattern [regex]

Jest Aligned

Run only tests with a name that matches the regex. For example, suppose you want to run only tests related to authorization which will have names like "GET /api/posts with auth", then you can use testNamePattern = "auth".

tip

The regex is matched against the full name, which is a combination of the test name and all its surrounding describe blocks.

testPathIgnorePatterns [array<regex>]

Jest API Change

An array of regexp pattern strings that are tested against all tests paths before executing the test. Contrary to testPathPattern, it will only run those tests with a path that does not match with the provided regexp expressions.

testPathPattern [regex]

Jest Aligned

A regexp pattern string that is matched against all tests paths before executing the test.

testTimeout [number>]

Jest Aligned

Default timeout of a test in milliseconds. Default value: 5000.

updateSnapshot [boolean]

Jest Aligned

Use this flag to re-record every snapshot that fails during this test run. Can be used together with a test suite pattern or with testNamePattern to re-record snapshots.

verbose [boolean]

Jest Aligned

Display individual test results with the test suite hierarchy.