Open Pajn opened 3 years ago
could you provide a repro ?
Sure, here https://github.com/Pajn/vite-web-test-runner-commands
I created a vanilla project with yarn create @vitejs/app
and added the bare minimum to set up tests. You'll see the above error when you try to run yarn test
.
This isn't specific to @web/test-runner-visual-reqression
but happens to everything using @web/test-runner-commands however that requires more code to use directly and I thought the repro is probably better with as little custom code as possible.
When rereading I can see that my inital post was a bit messy. Just trying to say the same thing here but hopefully more clearly :)
@web/test-runner-commands
imports a file named /__web-dev-server__web-socket.js
. This file does not exist on disk, it is generated on the fly by @web/dev-server
so we must somehow find a way to make Vite not care about this import and ship it as-is to the browser, so that it can fetch it from @web/dev-server
.
I've hit this as well. It occurs as soon as I add @web/test-runner-commands
to my optimizeDeps.include
list. I haven't found a way to exclude it via optimizeDeps.exclude
so far...
Edit: exclude: ['/__web-dev-server__web-socket.js']
lets the pre-bundling execute successfully, but then the test itself blows up with:
[plugin:vite:import-analysis] Failed to resolve import "/__web-dev-server__web-socket.js" from "node_modules/.cache/vite/@web_test-runner-commands.js?v=68191bf7". Does the file exist?
It looks like a few other plugins have been updated to ignore these imports (https://github.com/modernweb-dev/web/issues/725, https://github.com/modernweb-dev/web/pull/1079), but I'm not sure where/how this plugin could do the same.
@web/test-runner-commands
enables more advanced plugins like@web/test-runner-visual-regression
and it integrates with test-runner by importing a file served by the test-runner server and thus must not be handled by Vite. In snowpack this was easily solved by marking it as an externalPackage but I'm not seeing a similar config property for Vite. https://github.com/snowpackjs/snowpack/pull/1737/filesThe logs when trying to use visual regression plugin: