- Jest CLI 选项·续1
- --lastCommit
- --listTests
- --logHeapUsage
- --maxConcurrency=<num>
- --maxWorkers=<num>|<string>
- --noStackTrace
- --notify
- --onlyChanged
- --passWithNoTests
- --projects <path1> ... <pathN>
- --reporters
- --roots
- --runInBand
- --selectProjects <project1> ... <projectN>
- --runTestsByPath
- --setupTestFrameworkScriptFile=<file>
- --showConfig
- --silent
- --testNamePattern=<regex>
- --testLocationInResults
- --testPathPattern=<regex>
- --testPathIgnorePatterns=<regex>|[array]
- --testRunner=<path>
- --testSequencer=<path>
- --testTimeout=<number>
- --updateSnapshot
- --useStderr
- --verbose
- --version
- --watch
- --watchAll
- --watchman
Jest CLI 选项·续1
--lastCommit
Run all tests affected by file changes in the last commit made. Behaves similarly to --onlyChanged. 与 --onlyChanged 的行为相似。
--listTests
通过JSON的形式列出所有将要运行的测试并退出. 与--findRelatedTests 一起使用可以知道那个测试将要运行 This can be used together with --findRelatedTests to know which tests Jest will run.
--logHeapUsage
记录每个测试后的记录堆使用情况。 主要用来调试内存泄漏。 与 --runInBand 和 --expose-gc一起使用.
--maxConcurrency=<num>
Prevents Jest from executing more than the specified amount of tests at the same time. Prevents Jest from executing more than the specified amount of tests at the same time. Only affects tests that use test.concurrent.
--maxWorkers=<num>|<string>
别名︰ -w。 设定运行测试的最大工作池数目。 In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases.
For environments with variable CPUs available, you can use percentage based configuration: --maxWorkers=50%
--noStackTrace
禁止栈跟踪信息在测试结果输出中。
--notify
Activates notifications for test results. 特别是当你不想专心致志等待 JavaScript 测试结果时。
--onlyChanged
或: -o. 尝试确定根据当前存储库中哪些已经更改的文件来运行的测试。 只有在此刻 git/hg 存储库中运行测试,需要静态依赖关系图时有用(例如. 无动态要求)。
--passWithNoTests
允许在没有找到文件的情况下通过测试。
--projects <path1> ... <pathN>
Run tests from one or more projects, found in the specified paths; also takes path globs. This option is the CLI equivalent of the projects configuration option. Note that if configuration files are found in the specified paths, all projects specified within those configuration files will be run. This option is the CLI equivalent of the projects configuration option. Note that if configuration files are found in the specified paths, all projects specified within those configuration files will be run.
--reporters
Run tests with specified reporters. Run tests with specified reporters. Reporter options are not available via CLI. Example with multiple reporters: Example with multiple reporters:
jest --reporters="default" --reporters="jest-junit"
--roots
A list of paths to directories that Jest should use to search for files in.
--runInBand
Alias: -i. 或: -i. 仅在当前的进程中连续运行所有测试,而非通过创建的子进程的工作池来运行测试。 This can be useful for debugging.
--selectProjects <project1> ... <projectN>
Run only the tests of the specified projects. Run only the tests of the specified projects. Jest uses the attribute displayName in the configuration to identify each project. If you use this option, you should provide a displayName to all your projects. If you use this option, you should provide a displayName to all your projects.
--runTestsByPath
Run only the tests that were specified with their exact paths.
Note: The default regex matching works fine on small runs, but becomes slow if provided with multiple patterns and/or against a lot of tests. This option replaces the regex matching logic and by that optimizes the time it takes Jest to filter specific test files This option replaces the regex matching logic and by that optimizes the time it takes Jest to filter specific test files
--setupTestFrameworkScriptFile=<file>
指定一个模块的路径,在每一个测试执行前设置测试框架。 注意:运行测试期间,由设置脚本导入的文件不会被mocked。
--showConfig
输出Jest配置,然后退出。
--silent
阻止所有测试通过控制台输出信息。
--testNamePattern=<regex>
别名︰ -t。 Run only tests with a name that matches the 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 jest -t=auth.
Note: The regex is matched against the full name, which is a combination of the test name and all its surrounding describe blocks.
--testLocationInResults
Adds a location field to test results. Useful if you want to report the location of a test in a reporter. Useful if you want to report the location of a test in a reporter.
请注意 column 是从 0 开始,而 line 不是。
{ "column": 4, "line": 5}
--testPathPattern=<regex>
在运行测试前,匹配的regexp模式字符串的测试文件路径。 On Windows, you will need to use / as a path separator or escape \ as \.
--testPathIgnorePatterns=<regex>|[array]
A single or array of regexp pattern strings that are tested against all tests paths before executing the test. 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.
To pass as an array use escaped parentheses and space delimited regexps such as (/node_modules/ /tests/e2e/). Alternatively, you can omit parentheses by combining regexps into a single regexp like /node_modules/|/tests/e2e/. These two examples are equivalent.
--testRunner=<path>
允许你指定自定义测试运行程序。
--testSequencer=<path>
Lets you specify a custom test sequencer. Lets you specify a custom test sequencer. Please refer to the documentation of the corresponding configuration property for details.
--testTimeout=<number>
Default timeout of a test in milliseconds. Default value: 5000.
--updateSnapshot
或: -u. 在运行测试中使用这个参数来重新录制每个失败测试的快照。 还可以和测试套件模式或 --testNamePattern 一起使用,从而重新录制的快照。
--useStderr
转移所有输出到stderr(标准错误输出).
--verbose
层次显示测试套件中每个测试的结果。
--version
Alias: -v. Print the version and exit.
--watch
监视文件更改,并重新运行与已更改的文件相关的测试。 当文件发生更改时,如果你想要重新运行所有测试,可以使用 --watchAll 选项。
--watchAll
监视文件的更改并在任何更改时重新运行所有测试。 若果你是想要重新运行仅基于已更改文件的测试,那么请使用 --watch 选项。
Use --watchAll=false to explicitly disable the watch mode. Note that in most CI environments, this is automatically handled for you. Note that in most CI environments, this is automatically handled for you.
--watchman
Whether to use watchman for file crawling. Defaults to true. Disable using --no-watchman.
