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

Ignore/filter some tests from auto run/watcher #475

Closed
mikeburgh opened this issue Jul 2, 2019 · 5 comments
Closed

Ignore/filter some tests from auto run/watcher #475

mikeburgh opened this issue Jul 2, 2019 · 5 comments

Comments

@mikeburgh
Copy link

Environment

  1. node -v: v10.15.3
  2. npm -v: 6.4.1
  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): jest@24.8.0
  4. your vscode-jest settings if customized:
"jest.runAllTestsFirst": false,
"jest.autoEnable": false,
"jest.enableCodeLens": true,
"jest.debugCodeLens.showWhenTestStateIn": [
        "fail",
        "unknown",
        "pass"
]
  1. Operating system: OS X 10.14.5

Prerequisite

  • are you able to run jest test from command line? Yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm test

Using the following multi project config for jest:

module.exports = {
	collectCoverage: true,
	coverageDirectory: './tests/coverage/',
	projects: [
	{
		displayName: "e2e",
		preset: "jest-puppeteer",
		setupFiles: ["./tests/e2e/v5/global.js"],
		testMatch: ["<rootDir>/tests/e2e/**/*.test.js"]
	},
	{
		displayName: "js",
		testEnvironment:'jsdom',
		setupFiles: ["<rootDir>/tests/js/jest-setup.js"],
		testMatch: ["<rootDir>/tests/js/*.test.js"]
	}
]

Is there a way to disable the auto running/watcher for the e2e tests ? They are slow to run, and we find that when we make changes to the tests in the js section, the e2e tests are re run if we have runner started.

@connectdotz
Copy link
Collaborator

jest's projects setting is a bit misleading, for a given config file, it will run all projects stated there, you can't pick and choose them by name. However, you can create multiple jest config with different "projects" setting, see more discussion in this thread.

If applicable, you can also consider using vscode's multiroot workspace together with the up-coming 3.0.1 pre-release, instead of jest's multi-project setting.

@mikeburgh
Copy link
Author

Thanks for getting back to me. We are using jests multiple configs to separate out the tests and the configs for the different types (plain javascript vs end to end tests).

I am running the 3.0.1 pre release, but we cannot use the multi-project aspect as the code we are testing is all in the one root, just two different types of tests.

Open to a PR which added a setting that would enable some tests to not be automatically run on start/change?

@connectdotz
Copy link
Collaborator

connectdotz commented Jul 3, 2019

I think there might be an easier solution, why not just create a separate jest config file with the projects you want to run, customize with any one of the below:

  • "jest.pathToConfig":"newConfig.json" or
  • "jest.pathToJest": "npm test --config=newConfig.json" (not sure if you need an extra double dash) or
  • create a new script in package.json to take the new config then set your "jest.pathToJest": "npm test-lite"

This extension tries not to diverge from how jest run tests, therefore it is probably better to defer to jest's config driven approach rather than creating our own test selection logic...

@mikeburgh
Copy link
Author

Fair point, I will need to figure out how we work that into our CI, but that's probably a lot simpler than a PR to add the feature, which like you said then diverges!

Thanks for the advice and suggestion, great extension!

@mikeburgh
Copy link
Author

In case anyone else finds this, I managed to get it working by keeping the single jest config file with projects.. and added the following to scripts in package.json:
"test-lite": "jest --maxWorkers=2 --testPathPattern=/js"

Then:
"jest.pathToJest": "npm run test-lite --"

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

2 participants