Giter VIP home page Giter VIP logo

Comments (6)

hi-ogawa avatar hi-ogawa commented on July 17, 2024

Thanks for the concise reproduction. It might look surprising, but I think it's mostly working as intended. Let me check one by one.

  1. Update foo.ts ...
  2. Watch didn't run automatically (That is the first problem)

This looks like because of "too dynamic" dynamic import, which is not statically analyzed by Vite/Vitest, so module graph cannot track "test file -> foo.ts" dependency to trigger auto re-run.

I made a quick example to show the difference here.
https://stackblitz.com/edit/vitest-dev-vitest-giqgmf?file=test%2Fdynamic-ok.test.ts

Given these two tests, bar.ts only triggers re-running dynamic-ok.test.ts:

// dynamic-ok.test.ts
await import('../src/bar');

// dynamic-not-ok.test.ts
await import(String('../src/bar'));  
  1. ... JS files are not even though I reconfigured the exclude to not exclude dist folder. If you change so that TS output dir is customDist instead of dist then the JS files do get reloaded correctly.

This one looks weird, but maybe a different issue, something related to deprecated test.watchExclude option and Vite side server.watch.ignored #5171, which picks up build.outDir: "dist" automatically as ignored.

Actually this might be a bug, so this needs to be investigated further.


Regarding point 4, do you actually use this "too dynamic" form of dynamic import? I think supporting this is out-of-scope for now. But depending on the use case, there might be a workaround, for example, using Vite's import glob import.meta.glob("/dist/*.js"), which can probably keep track module graph correctly.

from vitest.

timotheeguerin avatar timotheeguerin commented on July 17, 2024

Thanks for the quick reply, we do actually use a lot of those dynamic loading but only directly to JS for now(I could get into the details but not sure this is really relevant, let me know if you want to), not having the auto rerun of vitest watch is unfortunate but not the end of the world. The main issue I have is it looks like the new vitest extension preview depends on watch and rerunning the test doesn't reload the the dynamically loaded JS files. However that might just be the 2nd issue that you said sounds like a bug. I played also with the server.watch.ignore and couldn't get it to work either.

I'll look into import.meta.glob("/dist/*.js") I didn't know this was a thing thanks!

from vitest.

AriPerkkio avatar AriPerkkio commented on July 17, 2024

Does forceRerunTriggers work here? https://vitest.dev/config/#forcereruntriggers

from vitest.

timotheeguerin avatar timotheeguerin commented on July 17, 2024

It doesn't surprisingly not even in the TS case, I updated the repro abvoe with

    forceRerunTriggers: ['src/**'],

or with

    forceRerunTriggers: ['src/**', 'dist/**'],

neither seems to retrigger the auto run

from vitest.

AriPerkkio avatar AriPerkkio commented on July 17, 2024

I thought that would work... Weirdly it looks like it's not possible to make Vite's watcher to look for changes in **/dist/**.

Even something like this doesn't work:

export default defineConfig({
  server: {
    watch: {
      ignored: ["**/node_modules/**"],
    },
  },
  test: {
    watchExclude: ["**/node_modules/**"],
    forceRerunTriggers: ["**/dist/**"],
  },
});

The watcher here still has some hardcoded values in ignored:

const watcher = this.server.watcher

[
  '**/.git/**',
  '**/node_modules/**',
  '**/test-results/**',
  '/x/y/vitest-dist-rerun/node_modules/.vite/**',
  '**/node_modules/**',
  '**/node_modules/**',
  '/x/y/vitest-dist-rerun/dist/**'
]

The build.outDir is always excluded from watcher:

https://github.com/vitejs/vite/blob/c2d0b881d8dcca93e16aa74792e01ecbf3e2bf29/packages/vite/src/node/watch.ts#L13-L24

from vitest.

timotheeguerin avatar timotheeguerin commented on July 17, 2024

I see so if I add this to the config then the js reloads fine(though unsure if this is a viable workaround, feel like it should as vitest doesn't actually write to the outDir)

  build: {
    outDir: 'dummy',
  },

also noticed that forceRerunTriggers: ['src/**'], actually makes things worse as now the TS doesn't get reloaded when you press ENTER.

from vitest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.