e2e setup() leaves its random .nuxt/test/<id> build directory behind after every run

Aperta
#1,889 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, nuxt, typescript
Ambito
testing

Direzione di ricerca

The issue points to loadFixture in the generated dist/e2e-*.mjs and shows the cleanup registration condition. Trace this code to its source and check how loadNuxt() creates the build directory and how teardown runs. Reproduce with the provided Vitest e2e test; done when the test-created random build directory is removed after the test finishes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment
  • @nuxt/test-utils 4.1.0, nuxt 4.5.2, Node 22.21.1, macOS
What happens

Every run of an e2e test that uses setup({ server: true }) (build mode, no buildDir option) leaves its random build directory, .nuxt/test/<randomId> (about 23 MB for our app), behind after the run finishes. They pile up, one per run.

Why

In loadFixture (dist/e2e-*.mjs), the teardown that removes the build directory is only registered when the directory does not exist after loadNuxt():

ctx.nuxt = await loadNuxt({ ... overrides: ctx.options.nuxtConfig ... })
const buildDir = ctx.nuxt.options.buildDir
if (!existsSync(buildDir)) {
  await promises.mkdir(buildDir, { recursive: true })
  ctx.teardown = ctx.teardown || []
  ctx.teardown.push(() => promises.rm(buildDir, { recursive: true, force: true }))
}

On our app loadNuxt() has already created the directory by that point, so the cleanup is never registered.

Steps to reproduce
  1. In a Nuxt 4 app, add a test:
    // @vitest-environment node
    import { expect, it } from "vitest";
    import { fetch, setup } from "@nuxt/test-utils/e2e";
    await setup({ server: true, browser: false });
    it("serves /", async () => { expect((await fetch("/")).status).toBe(200); });
    
  2. Run it with npx vitest run <file>; it passes.
  3. ls .nuxt/test shows a <randomId> directory left behind. Each further run adds another.
Expected

The build directory created for the test is removed when the test finishes.

Lingua principale
TypeScript
Stelle
445
Fork
121
Merge medio
3g 11h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nuxt/test-utils

Tutte le issue di nuxt/test-utils

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.