test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

The "setup" in the tests is very slow for every rerun

Open enkot opened this issue 3 years ago • 11 comments

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

enkot avatar Oct 19 '22 09:10 enkot

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.

danielroe avatar Oct 19 '22 12:10 danielroe

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) 🙃

fabis94 avatar Jul 03 '23 11:07 fabis94

In either case, eagerly awaiting for a change here, cause otherwise running tests is pretty painful atm

fabis94 avatar Jul 03 '23 11:07 fabis94

@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.

KarelVendla avatar Mar 07 '24 09:03 KarelVendla

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

nWacky avatar Apr 01 '24 16:04 nWacky

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)),
    },
})

linspw avatar Apr 09 '24 22:04 linspw

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
  })
}

linspw avatar Apr 10 '24 15:04 linspw

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?

chrisjbrown avatar Aug 27 '24 15:08 chrisjbrown

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.

martinsnajdr avatar Aug 27 '24 20:08 martinsnajdr

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',
  },

chrisjbrown avatar Sep 02 '24 07:09 chrisjbrown

build: false option is broken in current master. See https://github.com/nuxt/test-utils/pull/936

Al-Rozhkov avatar Sep 09 '24 09:09 Al-Rozhkov

TypeError: Cannot read properties of undefined (reading 'options') at startServer (

i am having this issue as well.

antecuic avatar Dec 03 '24 16:12 antecuic

Same here

danielgran avatar Nov 15 '25 07:11 danielgran