Skip to content

Commit

Permalink
avoid EBUSY when deleting fixture dir on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Nov 15, 2023
1 parent 7505ccd commit f4da093
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/fixture/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export class TestFixtures {
const { onEOF } = this.#t
this.#t.onEOF = async () => {
this.#t.onEOF = onEOF
if (relative(process.cwd(), dir) === '') {
// cd out of it first, or else Windows fails with EBUSY every time
process.chdir(dirname(dir))
}
await rimraf(dir)
await onEOF()
}
Expand Down
15 changes: 15 additions & 0 deletions src/fixture/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
rmdirSync,
writeFileSync,
} from 'fs'
import { relative } from 'path'
import t from 'tap'
import { plugin } from '../dist/esm/index.js'

Expand Down Expand Up @@ -86,3 +87,17 @@ t.test('change testdirName', t => {
})
t.end()
})

t.test('cd out of dir before deleting', t => {
let dir: string
t.test('chdir into testdir', t => {
process.chdir(t.testdir({}))
dir = t.testdirName
t.end()
})
t.test('got kicked up a level', t => {
t.equal(relative(dir, process.cwd()), '..')
t.end()
})
t.end()
})

0 comments on commit f4da093

Please sign in to comment.