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

ctx.nuxt does not exist when build: false in setup

Open Al-Rozhkov opened this issue 1 year ago โ€ข 4 comments

๐Ÿ”— Linked issue

Resolves #918

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation or readme)
  • [X] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality)
  • [ ] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

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

Thank You so much for this @Al-Rozhkov. I've been wondering why I've unable to run my tests for a while without any luck.

@danielroe any chance this gets reviewed soon? Many thanks ๐Ÿ™๐Ÿฝ

Boluwatife2904 avatar Sep 09 '24 10:09 Boluwatife2904

Would you be able to add a test in examples/app-vitest/test/build-false.e2e.spec.ts? ๐Ÿ™

danielroe avatar Sep 10 '24 12:09 danielroe

Thank you ๐Ÿ™

Can you explain a bit about why you would do this rather than passing that config to setup?

danielroe avatar Sep 10 '24 17:09 danielroe

Thank you ๐Ÿ™

Can you explain a bit about why you would do this rather than passing that config to setup?

I wasn't sure how to build Nuxt manually and make setup use exact that build. I would appreciate your advice.

Also not sure why windows tests failed.

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

Thank you ๐Ÿ™

Can you explain a bit about why you would do this rather than passing that config to setup?

Maybe this helps https://github.com/nuxt/test-utils/issues/314#issuecomment-2047815314

The dudes and I want to reduce the setup times for playwright testrunners. Since on every test the app makes a new prod build, very time consuming.

So we tried this config in the playwright.config.ts

export default defineConfig<ConfigOptions>({
  use: {
    nuxt: {
      build: false,
      buildDir: '.output',
      nuxtConfig: {
        nitro: {
          output: {
            dir: '.output',
          },
        },
      },
      rootDir: fileURLToPath(new URL('.', import.meta.url)),
    },
})

with that we get this errror TypeError: Cannot read properties of undefined (reading 'options') at startServer...

Maybe this is the wrong approach, i dont know. What I know, my tests succeed locally but in the ci I get "Test timeout of 30000ms exceeded while setting up "_nuxtHooks"."

Setting the Timeout of each test to 2 minutes a workaround but far from effective. If we could reduce the build to one, it would be very helpful.

I have to build the frontend in the CI anyway before I copy it to the server, so it would make sense if the testrunner could use this artifact. --> build fe -use build artifact-> test e2e

skoenfaelt avatar Dec 03 '24 08:12 skoenfaelt