vscode-jest
vscode-jest copied to clipboard
Feature Request: Support having multiple test configs
Expected Behavior
I have a project that in test folder I have unit, integration and functional tests. Each test folder has its own configuration and setup files.
It would be great to have possibility to map different configuration for different test folders.
Example:
{
jest.instances: {
"test/unit/*": "jest --config=./test/unit/config.js",
"test/integration/*": "jest --config=./test/integration/config.js",
"test/functional/*": "jest --config=./test/functional/config.js",
}
}
So this way, for the test files under test/unit folder, extension will execute the corresponding command.
Actual Behavior
It doesn't support this at the moment.
Seems like we can achieve this after this https://github.com/jest-community/vscode-jest/issues/129 issue is closed. But i don't see any action on it.
I have the exact same setup and would love being able to configure that.
@yatki I wonder if the issue is order is reversed, that this option could be implemented in way that closes #129.
Any news about this feature?
I have a very similar problem. In my opinion, the best way to solve this would be to take the config file closest to the current test file as the responsible config file.
I think this could potentially help with monorepo projects where the CLI is configured to run jest using jest.config.js files in subdirectories.
See https://github.com/nrwl/nx/issues/2803 and https://github.com/nrwl/nx/issues/2344
Done with https://jestjs.io/docs/en/configuration#projects-arraystring--projectconfig like 3+ years ago
#129 basically supports vscode's multiroot workspaces, which can be used for monorepo project (each package can be configured as a folder).
I can see a few possible ways to do this today:
- create a vscode folder for each of the test folder. Then configure each folder to use its own
jest.pathToJestorjest.pathToConfig - try to use @askirmas suggestion of
--projectsto treat them as separate projects. Make sure you can run the CLI in terminal first, then customize thejest.pathToJestto use the same command.
Please let us know if any of the above works for you.
@connectdotz I have some issues settings 'propagation' in multiroot mode. But additional thing to check for 1st point - in launch options use some vscode path variable that points to current (sub) workspace, not root/main
If jest config is not common for all subprojects, then their all other configs should be different - extensions, settings, launches. So rather natural to supply them own 'scope' with workspace
Following (as @askirmas suggested) works out of the box with jest. I adapted everything according to @yatki's needs:
const createProject = (type) => ({
transform: {
'^.+\\.(t|j)sx?$': 'ts-jest',
},
globals: {
'ts-jest': {
isolatedModules: true,
},
},
displayName: type,
preset: 'ts-jest',
globalSetup: `./__setup__/${type}/jest.global-setup.ts`,
setupFilesAfterEnv: [`./__setup__/${type}/jest.setup-after-env.ts`],
testRegex: `(/test/${type}/.*| (\\.| /)(test|spec))\\.[jt]sx?$`,
});
module.exports = {
projects: [
createProject('unit'),
createProject('integration'),
createProject('functional'),
],
};
With that config debug works just as expected on each folder.