runCLI Options
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:
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
ci
[boolean]clearMocks
[boolean]debug
[boolean]expand
[boolean]json
[boolean]listTests
[boolean]noStackTrace
[boolean]passWithNoTests
[boolean]resetMocks
[boolean]showConfig
[boolean]testMatch
[array<string>]testNamePattern
[regex]testPathIgnorePatterns
[array<regex>]testPathPattern
[regex]testTimeout
[number>]updateSnapshot
[boolean]verbose
[boolean]
Reference
ci
[boolean]
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]
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]
Print debugging info about your Jest config.
expand
[boolean]
Use this flag to show full diffs and errors instead of a patch.
json
[boolean]
Prints the test results in JSON. This mode will send all other test output and user messages to stderr.
listTests
[boolean]
Lists all test files that Jest Roblox will run given the arguments, and exits.
noStackTrace
[boolean]
Disables stack trace in test results output.
passWithNoTests
[boolean]
Allows the test suite to pass when no files are found.
resetMocks
[boolean]
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]
Print your Jest config and then exits.
testMatch
[array<string>]
The glob patterns Jest uses to detect test files. Please refer to the testMatch
configuration for details.
testNamePattern
[regex]
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"
.
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>]
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]
A regexp pattern string that is matched against all tests paths before executing the test.
testTimeout
[number>]
Default timeout of a test in milliseconds. Default value: 5000.
updateSnapshot
[boolean]
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]
Display individual test results with the test suite hierarchy.