Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support having multiple test configs #428

Closed
yatki opened this issue Feb 27, 2019 · 12 comments · Fixed by #1035
Closed

Feature Request: Support having multiple test configs #428

yatki opened this issue Feb 27, 2019 · 12 comments · Fixed by #1035

Comments

@yatki
Copy link

yatki commented Feb 27, 2019

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.

@yatki
Copy link
Author

yatki commented Feb 27, 2019

Seems like we can achieve this after this #129 issue is closed. But i don't see any action on it.

@renestalder
Copy link

I have the exact same setup and would love being able to configure that.

@jsphstls
Copy link

@yatki I wonder if the issue is order is reversed, that this option could be implemented in way that closes #129.

@saeidzebardast
Copy link

Any news about this feature?

@FERNman
Copy link

FERNman commented Sep 23, 2019

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.

@wrslatz
Copy link

wrslatz commented Apr 18, 2020

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 nrwl/nx#2803 and nrwl/nx#2344

@askirmas
Copy link

askirmas commented Sep 6, 2020

Done with https://jestjs.io/docs/en/configuration#projects-arraystring--projectconfig like 3+ years ago

@connectdotz
Copy link
Collaborator

#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:

  1. create a vscode folder for each of the test folder. Then configure each folder to use its own jest.pathToJest or jest.pathToConfig
  2. try to use @askirmas suggestion of --projects to treat them as separate projects. Make sure you can run the CLI in terminal first, then customize the jest.pathToJest to use the same command.

Please let us know if any of the above works for you.

@askirmas
Copy link

askirmas commented Sep 6, 2020

@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

@askirmas
Copy link

askirmas commented Sep 6, 2020

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

@JPeer264
Copy link

JPeer264 commented Oct 1, 2021

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.

@markwalsh-liverpool
Copy link

Is there a documented way in which to configure this; if the projects differ?

@JPeer264's projects are all the same but there could be a situation in which your project setup (unit/integration etc) are different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants