Jest 正则表达式匹配某些测试文件

Dan*_*zyk 3 jestjs

我在 dir 下进行了集成测试src/test/integration。所有文件的命名方式如下:foo.integration.js.

运行笑话:

jest ".*\\.integration\\.js"
Run Code Online (Sandbox Code Playgroud)

产生这个错误:

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/dangruszczyk/workspace/cef/lambda-workflow
  7 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 1 match
  testPathIgnorePatterns: /node_modules/ - 7 matches
  testRegex:  - 0 matches
Pattern: .*\.integration\.js - 0 matches
Run Code Online (Sandbox Code Playgroud)

当然这个正则表达式应该匹配src/test/integration/foo.integration.jshttps://regex101.com/r/T3WJwd/1/)。有什么线索吗?

jon*_*rpe 5

问题是 Jest 仍在应用testMatch,即您在它已确定为测试文件的文件中进行过滤,并且src/test/integration/foo.integration.js既不匹配**/__tests__/**/*.[jt]s?(x)也不匹配**/?(*.)+(spec|test).[tj]s?(x)*。

要运行这些文件,您可能最好设置testMatch

jest --testMatch='**/*.integration.js'
Run Code Online (Sandbox Code Playgroud)

这似乎不是 CLI 的记录部分,但在实践中(目前!)运行良好。

*有趣的是,文档path/to/my-test.js中显示的示例也没有......