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]: Allow option to detect if jest is currently running in watch mode #12271

Closed
billyvg opened this issue Jan 27, 2022 · 3 comments · Fixed by #12461
Closed

[Feature]: Allow option to detect if jest is currently running in watch mode #12271

billyvg opened this issue Jan 27, 2022 · 3 comments · Fixed by #12461

Comments

@billyvg
Copy link

billyvg commented Jan 27, 2022

🚀 Feature Proposal

Add a way to detect (in a jest environment and possibly elsewhere) for when jest is running in "watch" mode.

Motivation

We have a custom jest environment where we are instrumenting our tests and we'd like to be able to disable the feature in watch mode. Currently you can check process.argv for --watch, but this doesn't work if you call jest.run(<argv>) outside of CLI.

Example

I would expect it to be available in the environment's constructor:

class CustomEnvironment extends JsdomEnvironment {
    constructor(...args) {
      super(...args);
      const [config, context] = args;
      if (context.watchMode) { ... }
    }
}

Pitch

This feature belongs in core because it's already an option in core and just needs to be exposed.

@SimenB
Copy link
Member

SimenB commented Jan 28, 2022

Right, we only pass you projectConfig, not globalConfig (which has watch: true). Sounds like something we could change for the next major (i.e. constructor({projectConfig, globalConfig}) rather than constructor(projectConfig))

@SimenB
Copy link
Member

SimenB commented Feb 24, 2022

billyvg added a commit to getsentry/sentry that referenced this issue Mar 7, 2022
A few reasons for this change:

* The behavior of `yarn test` was a bit unclear, there were a few conditions where it would not run in "watch" mode (CI, pre-commit, exporting coverage stats)
* We were having issues in "watch" mode due to `jest-sentry-environment`. Our wrapper script called `jest` via node API w/ "watch" mode as an arg, while `jest-sentry-environment` checked the global `process.argv` for "watch" mode. This is because the run options are not passed to the jest environment, and there is no other way to determine "watch" mode. (Note: this is fixed in v28 of jest, but it is currently in pre-release: jestjs/jest#12271).

Now instead of running "watch" mode depending on the runtime environment, add an explicit task `test-watch` to run `jest` in "watch" mode.
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants