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 of onlyChanged. if onlyChanged is set by default, running jest with --all forces 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 after n number 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 calling jest --showConfig. [boolean]
  • --clearMocks β€” Automatically clear mock calls, instances, contexts and results before every test. Equivalent to calling jest.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 no rootDir is set in the config, the directory containing the config file is assumed to be the rootDir for 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. Implies runInBand. [boolean]
  • --env β€” The test environment used for all tests. This can point to any file or node module. Examples: jsdom, node or path/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 attribute displayName in 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 --findRelatedTests to 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 --runInBand and --expose-gc in node. [boolean]
  • --maxConcurrency β€” Specifies the maximum number of tests that are allowed to run concurrently. This only affects tests using test.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 the NODE_PATH env variable, modulePaths is 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. 0 to disable. [number]
  • --outputFile β€” Write test results to a file when the --json option 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 --seed CLI option. [boolean]
  • --reporters β€” A list of custom reporters for the test suite. [array]
  • --resetMocks β€” Automatically reset mock state before every test. Equivalent to calling jest.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 calling jest.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 via jest.getSeed(). If you don't specify this option, Jest randomly generates the value for you. The seed value must be between -0x80000000 and 0x7fffffff inclusive. [number]
  • --selectProjects β€” run the tests of the specified projects. Jest uses the displayName attribute 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 --seed for 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 the testEnvironment. Which options are relevant depends on the environment β€” so like, read the room (the environment) 🌸 [string]
  • --testFailureExitCode β€” the exit code of the jest command if the test run failed. [string]
  • --testLocationInResults β€” adds location information 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 is jest-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 --testNamePattern to 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 --watchAll option 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 --watch option 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