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

Fix toggle not working in projects config #86

Open
samit4me opened this issue Feb 5, 2020 · 3 comments
Open

Fix toggle not working in projects config #86

samit4me opened this issue Feb 5, 2020 · 3 comments

Comments

@samit4me
Copy link

samit4me commented Feb 5, 2020

✔️
When using a basic jest config the Press F to override ESLint --fix works as expected.

module.exports = {
  runner: 'jest-runner-eslint',
  displayName: 'lint',
  testMatch: ['<rootDir>/src/**/*.js'],
  watchPlugins: ["jest-runner-eslint/watch-fix"],
};

✖️
When using a projects configuration the Press F to override ESLint --fix does not work.

module.exports = {
  projects: [
    {
      displayName: 'test',
    },
    {
      runner: 'jest-runner-eslint',
      displayName: 'lint',
      testMatch: ['<rootDir>/src/**/*.js'],
      watchPlugins: ["jest-runner-eslint/watch-fix"],
    },
  ],
};
@keplersj
Copy link

keplersj commented Feb 5, 2020

I think I've seen something similar before in jest. If you have a configuration with a unit test runner and a lint runner (like the one above), you need to specify collectCoverage for both jest and the test runner for collectCoverage to take effect. Giving you a config like the following:

module.exports = {
  collectCoverage: true,
  projects: [
    {
      displayName: 'test',
      collectCoverage: true,
    },
    {
      runner: 'jest-runner-eslint',
      displayName: 'lint',
      testMatch: ['<rootDir>/src/**/*.js'],
      watchPlugins: ["jest-runner-eslint/watch-fix"],
    },
  ],
};

Based on this, I suspect that the following should work to enable the watch plugin:

module.exports = {
  watchPlugins: ["jest-runner-eslint/watch-fix"],
  projects: [
    {
      displayName: 'test',
    },
    {
      runner: 'jest-runner-eslint',
      displayName: 'lint',
      testMatch: ['<rootDir>/src/**/*.js'],
      watchPlugins: ["jest-runner-eslint/watch-fix"],
    },
  ],
};

@samit4me
Copy link
Author

samit4me commented Feb 5, 2020

Nice, I've just tried your solution and it works. Interestingly, it also work if you only specify the watchPlugins once outside of projects, for example:

module.exports = {
  watchPlugins: ["jest-runner-eslint/watch-fix"],
  projects: [
    {
      displayName: 'test',
    },
    {
      runner: 'jest-runner-eslint',
      displayName: 'lint',
      testMatch: ['<rootDir>/src/**/*.js'],
    },
  ],
};

@cameron-martin
Copy link

I believe this is due to the distinction between global config and project config. Properties that come from the global config are only valid at the top level, whereas properties from the project config are only valid at the project level. This isn't mentioned in the docs, but can be seen in the type definitions.

AlexisPuga added a commit to AlexisPuga/precise-watcher that referenced this issue Mar 2, 2021
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

No branches or pull requests

3 participants