这是我的Jest配置文件的外观:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>'],
moduleDirectories: ['node_modules', 'server'],
globals: {
'ts-jest': {
tsconfig: './tsconfig.test.json',
},
},
watchPathIgnorePatterns: ['/node_modules'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
testMatch: ['/**/*.test.(ts|tsx)'],
globalSetup: './global-setup.js',
};
这是我在项目的根目录下运行jest -c jest.config.js
时得到的输出:
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\Users\xxx\Documents\xxx\xxx\xxx
432 files checked.
testMatch: /**/*.test.(ts|tsx) - 0 matches
testPathIgnorePatterns: \\node_modules\\ - 432 matches
testRegex: - 0 matches
Pattern: - 0 matches
我有一种感觉,这可能与Windows和Linux上的不同路径分隔符有关。我在Windows上运行。因此我尝试将jest.config.js
中的testMatch
更改为['\\**\\*.test.(ts|tsx)']
。这没有解决我的问题。
我在package.json
中定义了2个NPM脚本,它们生成的输出与上面的相同:
"lint-and-test": "npm run lint && npm run test"
"test": "jest --coverage --verbose"
1条答案
按热度按时间bprjcwpo1#
This has been a known issue for a while with Jest. See the Issue titled testMatch on Windows #7914 for more context.
In windows default slash for file paths look like
one\two\three\file.test.ts
, but Jest does not seem to internally convert\\
(escaped Windows style) or/
(Unix style) path separators correctly thereby resulting in not picking up any of the test files.