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

Vitest failing when baseURL is defined at nuxt.config.ts

Open leopradac opened this issue 1 year ago • 2 comments

Environment


  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: app, devtools, modules
  • Runtime Modules: @nuxt/test-utils/[email protected]
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-ichjfp?file=nuxt.config.ts&view=editor

Describe the bug

Quite simple as the title describes, when app > baseURL is defined at nuxt.config.ts vitest starts failing, at least at those tests using the nuxt environment with the // @vitest-environment nuxt at the beginning of the file.

Additional context

Logs shared below are for "baseURL": "/admin/". Also, for those struggling with this, by the time being a workaround would be modifying the "test" script at package.json to:

{
...
"test": "NUXT_APP_BASE_URL='/' vitest"
...
}

Logs

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FetchError: [GET] "/admin/_nuxt/builds/meta/test.json": 404 Cannot find any path matching /admin/_nuxt/builds/meta/test.json.
 ❯ $fetch2 node_modules/ofetch/dist/shared/ofetch.37386b05.mjs:285:15

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { request: '/admin/_nuxt/builds/meta/test.json', options: { method: undefined }, response: { _data: { statusCode: 404, statusMessage: 'Cannot find any path matching /admin/_nuxt/builds/meta/test.json.', stack: [] }, constructor: 'Function<Response>', type: 'default', url: '', redirected: false, status: 404, ok: false, statusText: 'Cannot find any path matching /admin/_nuxt/builds/meta/test.json.', headers: { constructor: 'Function<Headers>', append: 'Function<append>', delete: 'Function<delete>', get: 'Function<get>', has: 'Function<has>', set: 'Function<set>', getSetCookie: 'Function<getSetCookie>', keys: 'Function<keys>', values: 'Function<values>', entries: 'Function<entries>', forEach: 'Function<forEach>' }, body: { constructor: 'Function<ReadableStream>', locked: true, cancel: 'Function<cancel>', getReader: 'Function<getReader>', pipeThrough: 'Function<pipeThrough>', pipeTo: 'Function<pipeTo>', tee: 'Function<tee>', values: 'Function<values>' }, bodyUsed: true, clone: 'Function<clone>', blob: 'Function<blob>', arrayBuffer: 'Function<arrayBuffer>', text: 'Function<text>', json: 'Function<json>', formData: 'Function<formData>' }, data: { statusCode: 404, statusMessage: 'Cannot find any path matching /admin/_nuxt/builds/meta/test.json.', stack: [] }, status: 404, statusCode: 404, statusText: 'Cannot find any path matching /admin/_nuxt/builds/meta/test.json.', statusMessage: 'Cannot find any path matching /admin/_nuxt/builds/meta/test.json.' }
This error originated in "__test__/nuxt.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 Test Files  1 passed (1)
      Tests  1 passed (1)
     Errors  1 error
   Start at  04:53:52
   Duration  2.42s (transform 149ms, setup 304ms, collect 11ms, tests 1ms, environment 455ms, prepare 610ms)


 FAIL  Tests failed. Watching for file changes...
       press h to show help, press q to quit

leopradac avatar Jun 06 '24 03:06 leopradac