rsnext/test/lib/use-temp-dir.ts
JJ Kasper 90f022aeb6
Update test config (#43661)
Updates our test config to take advantage of more concurrency and also
updates to leverage the playwright docker image to reduce flakes from
actions/setup-node stalling or playwright dependencies stalling on `apt
install`.

This reduces our test times from upwards of 30 minutes down to back
around 15 minutes.
2022-12-03 19:49:00 -08:00

28 lines
571 B
TypeScript

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.
*/
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 {
await fs.remove(folder)
}
}