test-utils
test-utils copied to clipboard
The "setup" in the tests is very slow for every rerun
Environment
- Operating System:
Linux - Node Version:
v16.14.2 - Nuxt Version:
3.0.0-rc.12 - Nitro Version:
0.6.0 - Package Manager:
[email protected] - Builder:
vite - User Config:
- - Runtime Modules:
- - Build Modules:
-
Reproduction
https://stackblitz.com/edit/nuxt-framework-zehqm6
Describe the bug
The empty await setup({}) in the tests takes ~4 seconds for every rerun in watch mode in the empty project.
Please, check the reproduction, try to run npm test.
Additional context
No response
Logs
No response
I think @antfu was working on a PR to avoid restarting/rebuilding Nuxt when rerunning tests.
Also relevant: https://github.com/nuxt/framework/pull/4578.
Besides not re-building on every test (re-)run it would be even better if server could be re-built separately if only server-side code changed (e.g. an API) 🙃
In either case, eagerly awaiting for a change here, cause otherwise running tests is pretty painful atm
@danielroe Is it possible to have a dev. instance running & to use that as the "server" for the e2e tests? I don't really care about building all the time as the built version will run in the pipeline anyway . It would be nice to skip "building" and just to use the "npm run dev" server I have running.
Is it possible to have a dev. instance running & to use that as the "server" for the e2e tests?
I managed to avoid rebuilding every time by building into .output/output
npm run build
mv .output .output1 && mkdir .output && mv .output1 .output/output
And then setting output directory to .output
// playwright.config.ts
export default defineConfig<ConfigOptions>({
use: {
nuxt: {
build: false,
buildDir: ".output",
rootDir: fileURLToPath(new URL(".", import.meta.url)),
},
},
})
For now nuxt always sets nitro.output.dir to buildDir/output and starts a server from buildDir/output
npx playwright test is using an existing build after this
You are amazing @nWacky ! I only adjusted to doesn't need mv command:
export default defineConfig<ConfigOptions>({
use: {
nuxt: {
build: false,
buildDir: '.output',
nuxtConfig: {
nitro: {
output: {
dir: '.output',
},
},
},
rootDir: fileURLToPath(new URL('.', import.meta.url)),
},
})
Wrapping nuxt setup: Be Happy
OBS: The test now takes 5 seconds, previously it took around 50 seconds
import { setup } from '@nuxt/test-utils/e2e'
import type { TestOptions } from '@nuxt/test-utils/e2e'
export const setupNuxt = (options?: Partial<TestOptions>) => {
return setup({
build: false,
buildDir: '.output',
nuxtConfig: {
nitro: {
output: {
dir: '.output',
},
},
},
...options
})
}
You are amazing @nWacky ! I only adjusted to doesn't need mv command:
export default defineConfig<ConfigOptions>({ use: { nuxt: { build: false, buildDir: '.output', nuxtConfig: { nitro: { output: { dir: '.output', }, }, }, rootDir: fileURLToPath(new URL('.', import.meta.url)), }, })
Hi @linspw I'm trying to implement the changes you have here but I'm running into an error
TypeError: Cannot read properties of undefined (reading 'options')
at startServer...
did you not experience this?
You are amazing @nWacky ! I only adjusted to doesn't need mv command:
export default defineConfig<ConfigOptions>({ use: { nuxt: { build: false, buildDir: '.output', nuxtConfig: { nitro: { output: { dir: '.output', }, }, }, rootDir: fileURLToPath(new URL('.', import.meta.url)), }, })Hi @linspw I'm trying to implement the changes you have here but I'm running into an error
TypeError: Cannot read properties of undefined (reading 'options') at startServer...did you not experience this?
Having the same problem.
I found a workaround by starting a dev/preview server and then running tests against that until there is a better solution
use: {
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
host: 'http://localhost:3000',
},
trace: 'on-first-retry',
},
build: false option is broken in current master. See https://github.com/nuxt/test-utils/pull/936
TypeError: Cannot read properties of undefined (reading 'options') at startServer (
i am having this issue as well.
Same here