test(windows): close native coverage gaps

This commit is contained in:
Tianyi Cui
2026-08-09 03:12:58 +08:00
parent 94799abfb0
commit bfb456e0c6
8 changed files with 63 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import { lstat, mkdir, mkdtemp, readFile, readdir, stat, symlink, writeFile } fr
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { writeFileAtomic } from '../src/index.ts'
import { withFileLock, writeFileAtomic } from '../src/index.ts'
async function scratch(): Promise<string> {
return mkdtemp(join(tmpdir(), 'dsh-atomic-write-'))
@@ -46,3 +46,17 @@ describe('writeFileAtomic', () => {
expect((await readdir(dir)).filter(entry => entry.includes('.tmp'))).toEqual([])
})
})
describe('withFileLock', () => {
it('rejects an invalid parent hierarchy before running the operation', async () => {
const dir = await scratch()
const parent = join(dir, 'not-a-directory')
await writeFile(parent, 'occupied')
let called = false
await expect(withFileLock(join(parent, 'document'), async () => {
called = true
})).rejects.toThrow(/ENOENT|ENOTDIR|not a directory/i)
expect(called).toBe(false)
})
})