Comments (6)
Thanks for the concise reproduction. It might look surprising, but I think it's mostly working as intended. Let me check one by one.
- Update foo.ts ...
- 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'));
- ... 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.
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.
Does forceRerunTriggers
work here? https://vitest.dev/config/#forcereruntriggers
from vitest.
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.
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
:
vitest/packages/vitest/src/node/core.ts
Line 742 in 0ec4d0e
[
'**/.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:
from vitest.
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)
- Tries to assign to a getter-only field when formatting an error
- 【question】Unable to recognize the @ (root path) of the project HOT 1
- Vitest doesn't discover tests when pointed at monorepo root HOT 1
- Ability to specify benchmarks that should run synchronously HOT 3
- 在使用vitest编写单测模块时,抛出错误模块与编写模块不一致 HOT 5
- Vitest could detect some errors it is currently silencing when using `jsdom` or `happy-dom` environments
- toHaveBeenNthCalledWith does not check call times HOT 1
- V8 Coverage: Exclude empty lines, comments, TS types
- toMatchFileSnapshot does not use custom snapshot serializer HOT 6
- Source code missing in reporters on error, when certain line width is reached, very inconsistent HOT 1
- TypeError: Unknown file extension ".jsx" HOT 1
- `.mockRestore` on `vi.fn` is not compatible with jest
- Unexpected istanbul code coverage HOT 3
- Incompatibility for type-checking with bun HOT 3
- Support specifying a line number when filtering tests
- Vitest workspace run doesn't pick .env from individual projects HOT 2
- Unable to resolve a dependency of a dependency using alias HOT 4
- SyntaxError: Cannot use import statement outside a module HOT 1
- concurrent.each executes iterations serially instead of concurrently HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.