test_runner: `t.after` should respect `the first-in-last-out` principle like Golang's defer
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
Version
v22.10.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
1. Create a test file
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
test('basic', async (t) => {
const testDir = path.join(import.meta.dirname, 'logs')
fs.mkdirSync(testDir, { recursive: true })
t.after(() => {
console.log('remove test dir')
fs.rmdirSync(testDir, { recursive: true })
})
fs.writeFileSync(path.join(testDir, 'test.log'), 'hello world!')
t.after(() => {
console.log('remove test file')
fs.unlinkSync(path.join(testDir, 'test.log'))
})
// do staff...
})
How often does it reproduce? Is there a required condition?
None
What is the expected behavior? Why is that the expected behavior?
t.after should follow the first-in, last-out principle
According to the above code, the file should be deleted first, then the directory
What do you see instead?
✖ basic (7.4021ms)
Error: ENOENT: no such file or directory, unlink 'project\folder\logs\test.log'
at Object.unlinkSync (node:fs:1871:11)
at TestContext.<anonymous> (file:///path/to/test.test.mjs:19:12)
at TestHook.runInAsyncScope (node:async_hooks:211:14)
at TestHook.run (node:internal/test_runner/test:934:25)
at TestHook.run (node:internal/test_runner/test:1225:18)
at TestHook.run (node:internal/util:543:20)
at node:internal/test_runner/test:853:20
at async Test.runHook (node:internal/test_runner/test:851:7)
at async after (node:internal/test_runner/test:893:9)
at async Test.run (node:internal/test_runner/test:942:7) {
Additional information
the first-in-last-out principle is more reasonable and practical. It is useful in many scenarios.
I'm not sure why it was designed in the form of a queue. Is there anything special about it?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il comportamento con il caso di test fornito, quindi traccia la pulizia a partire dagli stack frame di node:internal/test_runner, in particolare TestHook.run e after. Il lavoro è completato quando i callback vengono eseguiti in ordine inverso rispetto alla registrazione, così che il file venga rimosso prima della sua directory, con una copertura dell’ordine segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 55/100