silverwolf-x/project / test /lib /use-temp-dir.ts
silverwolf-x's picture
download
raw
666 Bytes
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
/**
* Create a randomly-named directory in `os.tmpdir()`, await a function call,
* and delete the directory when finished, unless `NEXT_TEST_SKIP_CLEANUP` is set.
*/
export async function useTempDir(
fn: (folder: string) => void | Promise<void>,
mode?: string | number
) {
const folder = path.join(
os.tmpdir(),
'next-test-' + Math.random().toString(36).slice(2)
)
await fs.mkdirp(folder)
if (mode) {
await fs.chmod(folder, mode)
}
try {
await fn(folder)
} finally {
if (!process.env.NEXT_TEST_SKIP_CLEANUP) {
await fs.remove(folder)
}
}
}

Xet Storage Details

Size:
666 Bytes
·
Xet hash:
b0e14d67665813de0752c339a176a7265f22f72ab6bfb78d11df440c95b2d1f1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.