如何 运行 在没有任何提示的情况下使用 Yarn 进行 Jest 测试?

How to run Jest tests with Yarn without any prompts?

我正在尝试 运行 我在 Team City 中的 Jest 单元测试,但我总是得到如下所示的提示。

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.

我尝试了 运行宁 yarn test a 到 运行 的所有测试。但是一旦测试完成执行,我仍然会收到相同的提示。我试过 yarn test a q 但这不起作用。我也尝试了 yarn test a --forceExityarn test a --bail 但没有任何反应,我仍然得到提示。我怎么能 运行 我所有的 Jest 测试都没有得到这个提示,因为在 运行 通过 Team City 时没有交互?任何帮助将不胜感激。

--ci

提供此选项后,Jest 将假设它在 CI 环境中 运行ning。这会更改遇到新快照时的行为。与自动存储新快照的常规行为不同,它将无法通过测试并要求 Jest 为 运行 with --updateSnapshot。 link

此外,您可以将 package.json 更改为:

"test": "CI=true react-scripts test --env=jsdom",

效果很好。

您的另一个选择是像设置任何变量一样在命令中设置 CI

CI=true yarn test

在 TeamCity 中,编辑您的配置设置,然后在旁边 select Parameters

单击 Add a new Parameter,然后在弹出的对话框中,在 Kind: select Environment variable (env.).

将名称设置为 env.CI,并将值设置为 true。单击 Save

下次您 运行 您的构建时,您的构建应该自动 运行 测试并继续。

要获得奖励积分(如果您是管理员)请转至 Administration,然后在 Projects 下编辑 。单击旁边的 Parameters 并将 env.CI 参数设置为 true,这样以后的项目就不必设置它了。

yarn test --coverage

只会 运行 一次(有覆盖范围)并且 returns 0 表示成功,1 表示失败。

以下命令对我有用。

  • CI=true yarn test