带有 jest.config.js 的 Jest cli testPathIgnorePatterns 结果未找到测试

mum*_*bot 3 jestjs

我想运行结合 cli 和 jest.config.js 的 jest,所以我可以使用相同的配置,但在运行时稍作改动

jest --config=jest.config.js
Run Code Online (Sandbox Code Playgroud)

结果是

Test Suites: 1 failed, 163 passed, 164 total
Tests:       8 skipped, 1685 passed, 1693 total
Snapshots:   87 passed, 87 total
Time:        34.719s, estimated 44s
Run Code Online (Sandbox Code Playgroud)

尽管

jest --config=jest.config.js --testPathIgnorePatterns=[ignore]
Run Code Online (Sandbox Code Playgroud)

结果是

752 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 164 matches
  testPathIgnorePatterns: [ignore] - 0 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches
error Command failed with exit code 1.
Run Code Online (Sandbox Code Playgroud)

如果我修改配置

modulePathIgnorePatterns: [
'<rootDir>/src/.*/__mocks__',
'<rootDir>/node_modules',
'<rootDir>/.*/ignore',
],
Run Code Online (Sandbox Code Playgroud)

结果是

Test Suites: 163 passed, 163 total
Tests:       8 skipped, 1685 passed, 1693 total
Snapshots:   87 passed, 87 total
Time:        31.417s
Run Code Online (Sandbox Code Playgroud)

mum*_*bot 10

文档指出testPathIgnorePatterns是一个数组。shell 中的数组以逗号或空格分隔。

这有效:

jest --config=jest.config.js --testPathIgnorePatterns=ignore
Run Code Online (Sandbox Code Playgroud)

就像:

jest --config=jest.config.js --testPathIgnorePatterns=ignore,ignoreThisAsWell
Run Code Online (Sandbox Code Playgroud)

  • 从 JS 到 shell 的上下文切换有时会让我头晕:( (3认同)