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

This extension makes "jest --watch" run tests with every modification (not just on save) #123

Closed
david-tejada opened this issue Oct 1, 2022 · 7 comments

Comments

@david-tejada
Copy link

I think the title is pretty explanatory. It makes the extension unusable if I have "jest --watch" running. Any idea why this could be happening?

@spence-s
Copy link
Collaborator

spence-s commented Oct 1, 2022

Nothing I can think of directly related with the extension.

It could be that you have auto save turned on? Make sure it's turned off in your workspace as well as your global settings. "files.autosave" I think is the setting.

You could try some testing by disabling the "xo.format.enable" flag.

I run test watchers on the cli all the time with this extension running. I wouldn't think jest is any different.

Do you have a jest related extension running the tests or is it just the cli watcher?

A minimal repro example set up would be helpful.

@david-tejada
Copy link
Author

Both "files.autosave" and "xo.format.enable" are off.

The tests are run through an npm script that just calls "jest --watch".

I will see if I can create a minimal example where it happens.

@david-tejada
Copy link
Author

I have a minimal repro example here: https://github.com/david-tejada/xo-jest-issue

Running npm run test and simply modifying (without saving) example.test.ts makes jest check for changes in the tests. You can add a new expect line below so that it doesn't show "No tests found since last commit" and you can see that the tests actually run.

A have disabled all extensions except for this one.

Let me know if you get the same results or I'll have to check if there's something wrong with my environment.

@spence-s
Copy link
Collaborator

spence-s commented Oct 1, 2022

I won't be able to test this until tomorrow, however, using ts w no tsconfig, or a ts config which doesn't directly reference the test file in "files" or "include" options, will trigger xo to create a temp tsconfig in node_modules on every modification. This is the likely culprit.

You can get around this by adding a tsconfig which includes the test in the "include" or "files" options so xo doesn't have to create a temp one, Or you can configure jest to not trigger on changes within node_modules which probably sounds like the better option.

Xo needs a tsconfig and try's to not bug you about it if you don't have one is the reason for this behavior. It's only indirectly related to the extension in that the extension runs xo, but I'm sure it would trigger if you run xo cli at the same time just watch is on.

@david-tejada
Copy link
Author

david-tejada commented Oct 1, 2022

I think you're onto something here. I actually have a tsconfig in the repo where I noticed the issue. I think the issue appeared after installing this package and setting up Typescript by adding the files entry to tsconfig. If I remove that line the issue goes away. I still have to figure out how to set it up so that it doesn't happen. I have tried some combinations of include and exclude without luck.

Jest actually ignores node_modules by default and I have even set it explicitly but this keeps happening.

You're right that running xo directly from the cli has the same effect.

@spence-s
Copy link
Collaborator

spence-s commented Oct 1, 2022

Ok I see!

Unfortunately, this isn't a bug but just an inconvenience with using jest watch + ts + xo all working appropriately.

I think your best setup option is this:

In your root dir:

|- tsconfig.json
|- tsconfig.xo.json
|- package.json (OR any other valid xo config, but we'll assume package.json for simplicity)

The contents of you tsconfig.xo.json

{
  // extend your normal tsconfig setup
  "extends": "./tsconfig.json"
  // include every ts file in the project, including test files
  "include": ["**/*.ts"],
 // overwrite any downstream excludes so that xo will never have to write a temp tsconfig
  "exclude": []
}

In package.json (or other xo config)

"xo" : {
  "parserOptions": {
      "project": "./tsconfig.xo.json"
  }
}

Now xo will never have to write a temp file to lint ts files correctly and your issue should be solved.

Going to close this issue since it is not a bug. Feel free to ping back here if you have anymore trouble though. Happy to help.

@spence-s spence-s closed this as completed Oct 1, 2022
@david-tejada
Copy link
Author

That worked like a charm! Thanks a lot!

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