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

Watch mode unresponsive to monorepo dependency changes #2532

Open
luxaritas opened this issue Dec 19, 2022 · 10 comments
Open

Watch mode unresponsive to monorepo dependency changes #2532

luxaritas opened this issue Dec 19, 2022 · 10 comments

Comments

@luxaritas
Copy link

luxaritas commented Dec 19, 2022

Describe the bug

I'm attempting to use Vitest in a monorepo, and noticed there are issues getting vitest to re-run tests in watch mode when in-repo dependencies change. I've identified a few specific limitations (if these should be split out into separate issues, let me know):

  1. **/dist/** needs to be excluded from watchExclude. This is fine, however I'd expect the default behavior to be smart enough to handle a monorepo where packages are built separately and imported into the package being tested
  2. deps.inline has to be set to true for changes to be picked up. Again, this is a reasonable workaround, but since vite "just works" for HMR and watch mode to work correctly, I wouldn't expect it to be necessary for vitest.
  3. When rebuilding the dependency with Vite, tests are not rerun - even though if I manually change the file in dist, they are. Additionally, building with Vite then trying to change the file in dist (without restarting the test watcher) also does not cause a test rerun. I tried tweaking the chokidar options via vite's server.watch parameter (namely awaitWriteFinish and atomic) as that seemed like it could affect this, but there was no change in behavior.

Reproduction

Reproduce via https://stackblitz.com/edit/vitest-dev-vitest-fttlzd (ensure you have two terminals available). Stop any watch processes and reset file states between tests.

    1. Run turbo run --cwd packages/packageb build:watch in one terminal
    2. Change packages/packagea/src/lib.ts
    3. Run turbo run --cwd packages/packagea build in the other terminal
    4. Note packages/packageb/dist/index.js is updated accordingly
    1. Run turbo run --cwd packages/packageb test in one terminal
    2. Change packages/packagea/dist/src/lib.ts
    3. Note the test watcher updates accordingly
    1. Run turbo run --cwd packages/packageb test in one terminal
    2. Change packages/packagea/src/lib.ts
    3. Run turbo run --cwd packages/packagea build in the other terminal
    4. Note the test watcher does not update
    1. Comment out deps: { inline: true }, (and/or watchExclude: [],) in packages/packageb/vite.config.ts
    2. Run turbo run --cwd packages/packageb test in one terminal
    3. Change packages/packagea/dist/src/lib.ts
    4. Note the test watcher does not update

Also note that if you run test 3 then 2 without stopping the test watcher, 2 will also fail to update.

System Info

System:
  OS: Linux 5.0 undefined
  CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 0 Bytes / 0 Bytes
  Shell: 1.0 - /bin/jsh
Binaries:
  Node: 16.14.2 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
  vite: 4.0.2 => 4.0.2 
  vitest: 0.26.0 => 0.26.0


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@luxaritas
Copy link
Author

luxaritas commented Jan 1, 2023

Just realized that vite's build watch uses rollup's watch mode, not the vite dev server which vitest uses. I changed packageb to be a web app that the vitest dev server can serve, and confirmed that rebuilding the dependency as in case 1 (using vitest instead of vitest build --watch) still caused a proper reload: https://stackblitz.com/edit/vitest-dev-vitest-nhye4s

@sheremet-va
Copy link
Member

This should be fixed in 0.31.2.

@luxaritas
Copy link
Author

Thanks for the update @sheremet-va - could you point me to the commit/PR in that release that resolves this (since my related PR is still open)?

@sheremet-va
Copy link
Member

Thanks for the update @sheremet-va - could you point me to the commit/PR in that release that resolves this (since my related PR is still open)?

#3446

@luxaritas
Copy link
Author

luxaritas commented May 30, 2023

The issue is not fully resolved yet. I was able to remove the deps inline, but watchExclude still needs to be cleared (as mentioned earlier, easy to work around) and tests to not rerun on a dependency vite build (which is what my PR addresses)

@luxaritas
Copy link
Author

Updated Stackblitz: https://stackblitz.com/edit/vitest-dev-vitest-g1bmwe

@sheremet-va
Copy link
Member

watchExclude still needs to be cleared (as mentioned earlier, easy to work around)

This is expected behavior.

tests to not rerun on a dependency vite build (which is what my PR addresses)

I left comments in PR.

@sheremet-va sheremet-va reopened this May 30, 2023
@luxaritas
Copy link
Author

Thanks - I'll revisit the PR once I have some available cycles

@sheremet-va
Copy link
Member

This is expected behavior.

On the other hand, it should also be removed from exclude at this point. We are moving away from treating named folders differently.

@ekwoka
Copy link

ekwoka commented Jul 30, 2023

I'm not sure what the situation is right now, but vitest does not respond to rebuilds in the case of a workspace package being rebuilt. I think, ideally, there would be a way to just have vitest directly access the source of the workspace package instead of needing to look at the built package at all.

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