tailwindcss/jest/runInTempDirectory.js
Adam Wathan 38b4eeb288 Prettier likes parens a lot now
git blame is now broken forever.
2020-10-16 15:39:44 -04:00

24 lines
512 B
JavaScript

import fs from 'fs'
import path from 'path'
import rimraf from 'rimraf'
let id = 0
export default function (callback) {
return new Promise((resolve) => {
const workerId = `${process.env.JEST_WORKER_ID}-${id++}`
const tmpPath = path.resolve(__dirname, `../__tmp_${workerId}`)
const currentPath = process.cwd()
rimraf.sync(tmpPath)
fs.mkdirSync(tmpPath)
process.chdir(tmpPath)
callback().then(() => {
process.chdir(currentPath)
rimraf(tmpPath, resolve)
})
})
}