After a great deal of exploration, I have finally solved this.
In my case, using Homestead in windows, I am running my vite server in a windows terminal but not for lack of trying*
So for my test running inside Homestead, it needs to be able to access the vite server running on windows
Running npm run dev -- showed me the local IP that vite was using
Then in vite.config.js
export default defineConfig({
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment'
},
plugins: [
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
server: {
hmr: {
host: "192.168.10.1", <-- this was the IP exposed in previous step
},
host: "0.0.0.0", <-- this allows other IPs to connect N.B. 0.0.0.0 means any IP!
},
});
Now when I run dusk it can see the vite server rather than having to build assets every time I run the tests
Hope this helps someone else!
- I tried installing vite inside Homestead, but
npm installwas failing trying to create symlinks. I had to then restart vagrant from a windows terminal running as admin. This allowed me to install everything and then run vite.
However, I have using vscode as my editor and I have learned that as I'm changing files vite was not registering the change. From the vite docs:
"Using Vite on Windows Subsystem for Linux (WSL) 2
When running Vite on WSL2, file system watching does not work when a file is edited by Windows applications (non-WSL2 process). This is due to a WSL2 limitation. This also applies to running on Docker with a WSL2 backend.
To fix it, you could either:
Recommended: Use WSL2 applications to edit your files. It is also recommended to move the project folder outside of a Windows filesystem. Accessing Windows filesystem from WSL2 is slow. Removing that overhead will improve performance. Set { usePolling: true }. Note that usePolling leads to high CPU utilization."
And yes, userPolling:true made my server crawl to a halt.