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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest-transform]: add a new option to transformOptions to detect when jest runs in watch mode #11118

Closed
ahnpnl opened this issue Feb 25, 2021 · 4 comments

Comments

@ahnpnl
Copy link
Contributor

ahnpnl commented Feb 25, 2021

馃殌 Feature Proposal

A new option for transformOptions to tell transformers if Jest runs in watch mode.

Motivation

I have a scenario in ts-jest related to kulshekhar/ts-jest#943

  • First I have 2 files
// foo.ts
export function getWelcomeMessage(username: string): string {
  return `yolo ${username}`;
}
// foo.spec.ts
it(`should return a message for this username`, (): void => {
    const result = getWelcomeMessage(username);

    expect(result).toStrictEqual(`yolo C0ZEN`);
});
  • Run test in watch mode, the test passes successfully
  • Modify foo.ts to
// foo.ts
export function getWelcomeMessage(username: number): string {
  return `yolo ${username}`;
}
  • Now test is rerun, however test still passes because ts-jest doesn't know if Jest runs in watch mode to properly redo type check

Example

A new option for transformOptions can be named something like watchMode and ts-jest can use that.

Currently I'm using a workaround that I have a check process.argv.includes('--watch'), it works but not optimal.

Pitch

Allow transformers to perform certain logic depending on watch mode

cc @SimenB @thymikee

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Mar 17, 2021

@SimenB do you have any suggestions for this?

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 17, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@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 May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant