jest
jest copied to clipboard
[Bug]: Jest can't find test suits with glob patterns
Version
29.3.1
Steps to reproduce
I specified the following paths for testMatch key in jest configuration:
testMatch: [
'<rootDir>/{app,entities,features,pages,shared,widgets}/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/{app,entities,features,pages,shared,widgets}/**/*.{spec,test}.{js,jsx,ts,tsx}'
],
My Jest config file:
module.exports = async () => {
return {
roots: [
'<rootDir>/app',
'<rootDir>/entities',
'<rootDir>/features',
'<rootDir>/pages',
'<rootDir>/shared',
'<rootDir>/widgets'
],
collectCoverageFrom: [
'{app,entities,features,pages,shared,widgets}/**/*.{js,jsx,ts,tsx}',
'!{app,entities,features,pages,shared,widgets}/**/*.{d,stories,styles}.ts',
'!{app,entities,features,pages,shared,widgets}/**/index.{js,jsx,ts,tsx}',
'!app/{config,scripts}/**/*.{js,jsx,ts,tsx}'
],
setupFiles: ['react-app-polyfill/jsdom', '<rootDir>/app/config/jest/testingLibraryConfig.js'],
setupFilesAfterEnv: ['<rootDir>/app/config/jest/setupTests.ts'],
testMatch: [
'<rootDir>/{app,entities,features,pages,shared,widgets}/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/{app,entities,features,pages,shared,widgets}/**/*.{spec,test}.{js,jsx,ts,tsx}'
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': '<rootDir>/app/config/jest/babelTransform.js',
'^.+\\.css$': '<rootDir>/app/config/jest/cssTransform.js',
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '<rootDir>/app/config/jest/fileTransform.mjs'
},
transformIgnorePatterns: [
// '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
'node_modules/(?!(lodash-es)/)',
'^.+\\.module\\.(css|sass|scss)$'
],
modulePaths: [],
moduleNameMapper: {
'^react-native$': 'react-native-web',
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
'^react-app/(.*)$': '<rootDir>/$1',
'^src/(.*)$': '<rootDir>/../src/$1'
},
moduleFileExtensions: ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'],
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
resetMocks: true
};
};
This is the path of my test file:
react-app/features/FindByUIN/useFindByUINController.test.ts
The same problem happens when I am specifying paths using glob patterns for collectCoverageFrom key.
Expected behavior
I expect Jest to determine all my test suits and run them.
Actual behavior
Jest can't find any test suites located in the path determined by glob pattern on my Windows laptop. However, it is still working in the same project on the MacOS 13.0 NodeJS latest LTS (18.13.0).
Terminal output:
No tests found, exiting with code 0
Additional context
No response
Environment
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Binaries:
Node: 18.13.0 - C:\Program Files\nodejs\node.EXE
npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
npmPackages:
jest: ^29.3.1 => 29.3.1
Did you try skipping rootDir token in testMatch globs? That’s a path and because of path separators it might create different patterns in Windows and MacOS. As you know, globs must always use /.
I tried to make my testMatch globs looks this way:
testMatch: [
'/{app,entities,features,pages,shared,widgets)/**/__tests__/**/*.{js,jsx,ts,tsx}',
'/{app,entities,features,pages,shared,widgets}/**/*.{spec,test}.{js,jsx,ts,tsx}'
]
but it hadn't effect, and the error message remains the same.
Interesting. Did you check if patterns from the documentation are working on Windows?
Can you put together a minimal reproduction?
Can you put together a minimal reproduction?
I've created a repo with reproduction of this bug. In jest.config.js you can find a commented code that will make Jest work again
https://github.com/blinikar/jest-bug-reproduction
Interesting. Did you check if patterns from the documentation are working on Windows?
Yes, it works
That’s good news. If you have a working pattern, you can build yours on top. The only obvious difference I see is **/ in the beginning of the working pattern, instead of just /.
That’s good news. If you have a working pattern, you can build yours on top. The only obvious difference I see is
**/in the beginning of the working pattern, instead of just/.
I checked it works. Thank you.
But the problem is that bug still exists, because create-react-app generates config with <rootDir> in the beginning of the pattern. And it also happens only on Windows sytems.
@SimenB Looks like this is a bug in create-react-app? How do you think?
Seems like we misunderstood each other. create-react-app works fine on Windows, it uses the following configuration:
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
]
We took that base and tried to create the one that fits our needs. The main purpose was to replace src folder by the set of other folders and exclude some additional files. So, we got the following edition:
collectCoverageFrom: [
'{app,entities,features,pages,shared,widgets}/**/*.{js,jsx,ts,tsx}',
'!{app,entities,features,pages,shared,widgets}/**/*.{d,stories,styles}.ts',
'!{app,entities,features,pages,shared,widgets}/**/index.{js,jsx,ts,tsx}',
'!app/{config,scripts}/**/*.{js,jsx,ts,tsx}'
],
testMatch: [
'<rootDir>/{app,entities,features,pages,shared,widgets}/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/{app,entities,features,pages,shared,widgets}/**/*.{spec,test}.{js,jsx,ts,tsx}'
],
Seems like change is not so dramatic (the exact folder was replaced by set of folders), but it does not work with Windows.
My point is if <rootDir> does work in the first config, it should work in the second one, too, because syntax seems to be correct. So, either our team understands globs wrong, or there is a bug in the implementation that breaks the case with sets on Windows.
Thanks for the additional details. Unfortunately I don’t have access to Windows machine. Hard to say what is going on.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.