JEST.JS(1)
β¨ JEST.JS(1) β¨
User Commands Β· JEST.JS(1)
okay bestie, sit DOWN because we are talking about jest.js and it's literally the moment. this is the man page, the whole thing, and i'm giving you the tour π
π NAME π
jest.js β Delightful JavaScript Testing
like... the name says delightful. they weren't playing. π¦
π SYNOPSIS π
jest.js [--config=<pathToConfigFile>] [TestPathPattern]
that's the whole vibe check right there. config path optional, test path pattern optional, chaos mandatory. π
β¨ OPTIONS β¨
okay this is the long part and i am NOT skipping a single one, we're doing all of them, hydrate first π
-h,--helpβ Show help[boolean]--versionβ Show version number[boolean]--allβ the literal opposite ofonlyChanged. ifonlyChangedis set by default, running jest with--allforces Jest to run all the tests instead of just the ones related to changed files.[boolean]--automockβ Automock all files by default.[boolean]-b,--bailβ Exit the test suite immediately afternnumber of failing tests.[boolean]--cacheβ Whether to use the transform cache. disable the cache using--no-cache.[boolean]--cacheDirectoryβ The directory where Jest should store its cached dependency information.[string]--changedFilesWithAncestorβ Runs tests related to the current changes and the changes made in the last commit. Behaves similarly to--onlyChanged.[boolean]--changedSinceβ Runs tests related to the changes since the provided branch. if the current branch has diverged from the given branch, then only changes made locally will be tested. Behaves similarly to--onlyChanged.[string]--ciβ Whether to run Jest in continuous integration (CI) mode. this option is on by default in most popular CI environments. it will prevent snapshots from being written unless explicitly requested.[boolean]--clearCacheβ Clears the configured Jest cache directory and then exits. the default directory can be found by callingjest --showConfig.[boolean]--clearMocksβ Automatically clear mock calls, instances, contexts and results before every test. Equivalent to callingjest.clearAllMocks()before each test.[boolean]--collectCoverageβ Alias for--coverage.[boolean]--collectCoverageFromβ A glob pattern relative to<rootDir>matching the files that coverage info needs to be collected from.[string]--colorβ Forces test results output color highlighting (even if stdout is not a TTY). Set to false if you would like to have no colors.[boolean]--colorsβ Alias for--color.[boolean]-c,--configβ The path to a jest config file specifying how to find and execute tests. If norootDiris set in the config, the directory containing the config file is assumed to be therootDirfor the project. This can also be a JSON encoded value which Jest will use as configuration.[string]--coverageβ Indicates that test coverage information should be collected and reported in the output.[boolean]--coverageDirectoryβ The directory where Jest should output its coverage files.[string]--coveragePathIgnorePatternsβ An array of regexp pattern strings that are matched against all file paths before executing the test. If the file path matches any of the patterns, coverage information will be skipped.[array]--coverageProviderβ Select between Babel and V8 to collect coverage.[choices: "babel", "v8"]--coverageReportersβ A list of reporter names that Jest uses when writing coverage reports. Any istanbul reporter can be used.[array]--coverageThresholdβ A JSON string with which will be used to configure minimum threshold enforcement for coverage results.[string]--debugβ Print debugging info about your jest config.[boolean]--detectLeaksβ EXPERIMENTAL: Detect memory leaks in tests. After executing a test, it will try to garbage collect the global object used, and fail if it was leaked.[boolean]--detectOpenHandlesβ Print out remaining open handles preventing Jest from exiting at the end of a test run. ImpliesrunInBand.[boolean]--envβ The test environment used for all tests. This can point to any file or node module. Examples:jsdom,nodeorpath/to/my-environment.js.[string]--errorOnDeprecatedβ Make calling deprecated APIs throw helpful error messages.[boolean]-e,--expandβ Use this flag to show full diffs instead of a patch.[boolean]--filterβ Path to a module exporting a filtering function. This method receives a list of tests which can be manipulated to exclude tests from running. Especially useful when used in conjunction with a testing infrastructure to filter known broken tests.[string]--findRelatedTestsβ Find related tests for a list of source files that were passed in as arguments. Useful for pre-commit hook integration to run the minimal amount of tests necessary.[boolean]--forceExitβ Force Jest to exit after all tests have completed running. This is useful when resources set up by test code cannot be adequately cleaned up.[boolean]--globalSetupβ The path to a module that runs before All Tests.[string]--globalTeardownβ The path to a module that runs after All Tests.[string]--globalsβ A JSON string with map of global variables that need to be available in all test environments.[string]--hasteβ A JSON string with map of variables for the haste module system.[string]--ignoreProjectsβ Ignore the tests of the specified projects. Jest uses the attributedisplayNamein the configuration to identify each project.[array]--initβ Generate a basic configuration file.[boolean]--injectGlobalsβ Should Jest inject global variables or not.[boolean]--jsonβ Prints the test results in JSON. This mode will send all other test output and user messages to stderr.[boolean]--lastCommitβ Run all tests affected by file changes in the last commit made. Behaves similarly to--onlyChanged.[boolean]--listTestsβ Lists all tests Jest will run given the arguments and exits. Most useful in a CI system together with--findRelatedTeststo determine the tests Jest will run based on specific files.[boolean]--logHeapUsageβ Logs the heap usage after every test. Useful to debug memory leaks. Use together with--runInBandand--expose-gcin node.[boolean]--maxConcurrencyβ Specifies the maximum number of tests that are allowed to run concurrently. This only affects tests usingtest.concurrent.[number]-w,--maxWorkersβ Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. (its usually best not to override this default)[string]--moduleDirectoriesβ An array of directory names to be searched recursively up from the requiring module's location.[array]--moduleFileExtensionsβ An array of file extensions your modules use. If you require modules without specifying a file extension, these are the extensions Jest will look for.[array]--moduleNameMapperβ A JSON string with a map from regular expressions to module names or to arrays of module names that allow to stub out resources, like images or styles with a single module.[string]--modulePathIgnorePatternsβ An array of regexp pattern strings that are matched against all module paths before those paths are to be considered "visible" to the module loader.[array]--modulePathsβ An alternative API to setting theNODE_PATHenv variable,modulePathsis an array of absolute paths to additional locations to search when resolving modules.[array]--noStackTraceβ Disables stack trace in test results output.[boolean]--notifyβ Activates notifications for test results.[boolean]--notifyModeβ Specifies when notifications will appear for test results.[string]-o,--onlyChangedβ Attempts to identify which tests to run based on which files have changed in the current repository. Only works if you're running tests in a git or hg repository at the moment.[boolean]-f,--onlyFailuresβ Run tests that failed in the previous execution.[boolean]--openHandlesTimeoutβ Print a warning about probable open handles if Jest does not exit cleanly after this number of milliseconds.0to disable.[number]--outputFileβ Write test results to a file when the--jsonoption is also specified.[string]--passWithNoTestsβ Will not fail if no tests are found (for example while using--testPathPattern.)[boolean]--presetβ A preset that is used as a base for Jest's configuration.[string]--prettierPathβ The path to the "prettier" module used for inline snapshots.[string]--projectsβ A list of projects that use Jest to run all tests of all projects in a single instance of Jest.[array]--randomizeβ Shuffle the order of the tests within a file. In order to choose the seed refer to the--seedCLI option.[boolean]--reportersβ A list of custom reporters for the test suite.[array]--resetMocksβ Automatically reset mock state before every test. Equivalent to callingjest.resetAllMocks()before each test.[boolean]--resetModulesβ If enabled, the module registry for every test file will be reset before running each individual test.[boolean]--resolverβ A JSON string which allows the use of a custom resolver.[string]--restoreMocksβ okay so imagine never having to remember cleanup again π§Ό Before every single test Jest automatically restores mock state and implementation. It's lowkey just callingjest.restoreAllMocks()before each test, but you don't have to write it.[boolean]--rootDirβ the root directory Jest should scan for tests and modules within. The whole search party starts here π[string]--rootsβ a list of paths to directories Jest should use to search for files in. Plural energy, multiple vibes β¨[array]-i,--runInBandβ runs all tests serially in the current process instead of spawning a worker pool of child processes to run tests. Genuinely useful for debugging, but ngl those use cases are pretty rare π[boolean]--runTestsByPathβ used when the patterns you provide are exact file paths. This skips the whole "turn it into a regular expression and match it against literally every single file" thing. Straight to the point, no detours π―[boolean]--runnerβ lets you use a custom runner instead of Jest's default test runner. Main character runner energy, your choice π[string]--seedβ sets a seed value that a test file can retrieve viajest.getSeed(). If you don't specify this option, Jest randomly generates the value for you. The seed value must be between-0x80000000and0x7fffffffinclusive.[number]--selectProjectsβ run the tests of the specified projects. Jest uses thedisplayNameattribute in the configuration to identify each project. Pick your faves π[array]--setupFilesβ a list of paths to modules that run some code to configure or set up the testing environment before each test. The pre-game ritual π§[array]--setupFilesAfterEnvβ a list of paths to modules that run some code to configure or set up the testing framework before each test. Yeah, it's after env, not before. Different slot, different job π[array]--shardβ shards tests and executes only the selected shard. Format is"current/all", and it's 1-based, so for example"3/5". Splitting the workload like a queen π[string]--showConfigβ prints your jest config and then exits. One and done, no tests run π¨οΈ[boolean]--showSeedβ prints the seed value in the test report summary. See--seedfor how to set this value.[boolean]--silentβ prevents tests from printing messages through the console. π€« nothing but the results, bestie[boolean]--skipFilterβ disables the filter provided by--filter. Super handy for CI jobs, or for local enforcement when you're fixing tests.[boolean]--snapshotSerializersβ a list of paths to snapshot serializer modules Jest should use for snapshot testing. πΈ[array]--testEnvironmentβ alias for--env. Same thing, different name π¦[string]--testEnvironmentOptionsβ a JSON string with options that will be passed to thetestEnvironment. Which options are relevant depends on the environment β so like, read the room (the environment) πΈ[string]--testFailureExitCodeβ the exit code of thejestcommand if the test run failed.[string]--testLocationInResultsβ addslocationinformation to the test results. Now you know exactly where it went down π[boolean]--testMatchβ the glob patterns Jest uses to detect test files.[array]-t,--testNamePatternβ run only the tests with a name that matches the regex pattern. Cherry-pick your faves π[string]--testPathIgnorePatternsβ an array of regexp pattern strings that are matched against all test paths before executing the test. If the test path matches any of the patterns, it gets skipped. Not invited, not coming π«[array]--testPathPatternβ a regexp pattern string that's matched against all test paths before executing the test.[array]--testRegexβ a string, or an array of string regexp patterns, that Jest uses to detect test files.[array]--testResultsProcessorβ allows the use of a custom results processor. This processor must be a node module that exports a function expecting the result object as its first argument.[string]--testRunnerβ lets you specify a custom test runner. The default isjest-circus/runner. You can hand it a path to a custom test runner:<rootDir>/path/to/testRunner.js.[string]--testSequencerβ lets you specify a custom test sequencer. The default is@jest/test-sequencer. A path to a custom test sequencer can be provided:<rootDir>/path/to/testSequencer.js[string]--testTimeoutβ sets the default timeouts of test cases. Clock's ticking bestie β°[number]--transformβ a JSON string which maps from regular expressions to paths to transformers.[string]--transformIgnorePatternsβ an array of regexp pattern strings that are matched against all source file paths before transformation.[array]--unmockedModulePathPatternsβ an array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them.[array]-u,--updateSnapshotβ use this flag to re-record snapshots. You can pair it with a test suite pattern or with--testNamePatternto re-record snapshots only for the tests matching the pattern. Careful with this one, it literally rewrites your recorded truth π[boolean]--useStderrβ diverts all output to stderr. Everything. All of it. π°[boolean]--verboseβ displays individual test results with the test suite hierarchy. The full breakdown, no summary crumbs π[boolean]--watchβ watches files for changes and reruns tests related to the changed files. If you want to re-run all tests whenever a file changes, use the--watchAlloption instead.[boolean]--watchAllβ watches files for changes and reruns all tests. If you want to re-run only the tests related to the changed files, use the--watchoption instead.[boolean]--watchPathIgnorePatternsβ an array of regexp pattern strings that are matched against all paths before triggering a test re-run in watch mode. If the test path matches any of the patterns, it will be skipped.[array]--watchmanβ whether to use watchman for file crawling. Disable it with--no-watchman.[boolean]--workerThreadsβ whether to use worker threads for parallelization. Child processes are what's used by default, so this is you switching up the whole setup π§΅[boolean]
Documentation, aka the sacred texts: https://jestjs.io/
That's the whole page, bestie, we ate and left zero crumbs π«Ά This was jest.js version 29.6.2-dev, dated December 2023, filed under JEST.JS(1). Go write some tests, you're gonna slay πβ¨
π¦ where this page comes from
- debian trixie: jest 29.6.2~ds1+~cs73.45.28-5 Β· MIT
- ubuntu noble: jest 29.6.2~ds1+~cs73.45.28-5 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms