相关疑难解决方法(0)

以非交互模式运行CRA Jest

更新:我的用例主要是在CI上运行测试,但是重写默认的CRA Jest参数是我一般想知道的.


我正在使用Create React App附带的Jest,config 运行测试.它始终启动到交互模式:

 › Press a to run all tests.
 › Press o to only run tests related to changed files.
 › Press p to filter by a filename regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.
Run Code Online (Sandbox Code Playgroud)

但我不希望它等待我的意见.我希望它运行一次然后终止.我尝试使用--bail--no-watchman开关,但它仍然以交互模式启动.

如果我全局安装jest,并在我的项目的根目录中运行它,它执行一次并完成(就像我想要的那样).但是当我运行npm test哪个运行时react-scripts test,即使我没有通过,它也会进入监视模式--watch.

更新:我还在CRA上提出了一个问题.

reactjs jestjs redux create-react-app

37
推荐指数
2
解决办法
6445
查看次数

从命令行运行 jest 时“未找到测试”

在构建的 React 项目create-react-app中,测试文件位于他们需要测试的代码旁边的同一文件夹中,如下所示:

|- /src/path
|  |- List.tsx
|  |- List.test.tsx
Run Code Online (Sandbox Code Playgroud)

尝试运行npx jest或使用 global 时jest,我得到以下结果:

No tests found
In C:\src\path
  34 files checked.
  testMatch: **\*test.tsx,**/*test.tsx,src\**\*.test.tsx,src/**/*.test.tsx,C:\src\path\src\**\*.test.tsx,C:\src\path\src\**\*.test.tsx - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 34 matches
Pattern:  - 0 matches
Run Code Online (Sandbox Code Playgroud)

运行npm test-这在转弯运行脚本react-scripts testpackage.json-工作正常,并能够找到并运行项目中的所有测试(手表模式)。

知道如何解决这个问题吗?

环境

  • 节点: 10.15.0
  • npm: 6.4.1
  • 反应脚本: 2.1.3
  • 操作系统: Windows 10 1809 17763.316

开玩笑的配置文件

module.exports = {
  testMatch: [
    '**\\*test.tsx',
    '**/*test.tsx',
    'src\\**\\*.test.tsx',
    'src/**/*.test.tsx',
    '<rootDir>\\src\\**\\*.test.tsx',
    '<rootDir>/src/**/*.test.tsx',
    'src/.*|(.|/)(.test).tsx?$'
  ],
};
Run Code Online (Sandbox Code Playgroud)

typescript reactjs jestjs react-scripts

3
推荐指数
1
解决办法
7376
查看次数