My file structure is something like:
Product/
|- httpdocs/
|- jest.config.js
|- modules/
|- modules1/
|- jest.config.js
|- modules2/
|- jest.config.js
|- modules3/
|- jest.config.js
In each jest.config.js under the modules I have some configuration for that specific module like: setupFiles: ['<rootDir>/testHelpers/setup.js'].
In my top jest.config.js (under httpdocs) I have defined my different projects:
projects: [
'<rootDir>/modules/module1',
'<rootDir>/modules/module2',
'<rootDir>/modules/module3'
]
When I run jest under httpdocs, the tests fail because the setupfiles (and other configuration) are ignored inside my module/jest.config.js files.
When I run jest under module1, all the tests succeed
Am I doing something wrong or does the option projects not work like this?
-------- EDIT 1 --------
So I restructered my configs like @cimenx suggested.
Product/
|- jest.config.js
|- httpdocs/
|- modules/
|- modules1/
|- foo/
|- bar/
|- foobar.js
|- foobar.test.js
|- modules2/
|- ...
my jest.config.js file looks like this:
module.exports = {
rootDir: './httpdocs/modules',
testPathIgnorePatterns: ['/node_modules/', '/smsc/'],
projects: [
{
displayName: 'module1',
testMatch: ['<rootDir>/module1/*.test.js']
},
{
displayName: 'module2',
testMatch: ['<rootDir>/module2/*.test.js']
}
]
};
At the moment the issue is that jest cannot find any tests inside my modules.
-------- SOLUTION --------
While I was writing my EDIT 1, I tried some other configs...
Apparently my <rootDir> is always the directory where my jest.config.js file is in.
The solution for me was to write the whole path from the config file to the modules without the option rootDir: './some/path'
module.exports = {
projects: [
{
displayName: 'module1',
testMatch: ['<rootDir>/httpdocs/modules/module1/**/*.test.js']
},
{
displayName: 'module2',
testMatch: ['<rootDir>/httpdocs/modules/module2/**/*.test.js']
}
]
};
Thanks for the help!