tailwindcss/jest/runInTempDirectory.js

24 lines
512 B
JavaScript
Raw Normal View History

2019-03-20 08:17:56 -05:00
import fs from 'fs'
import path from 'path'
import rimraf from 'rimraf'
let id = 0
2020-10-16 13:30:06 -04:00
export default function (callback) {
return new Promise((resolve) => {
const workerId = `${process.env.JEST_WORKER_ID}-${id++}`
2019-05-09 13:29:48 +02:00
const tmpPath = path.resolve(__dirname, `../__tmp_${workerId}`)
2019-03-20 08:17:56 -05:00
const currentPath = process.cwd()
rimraf.sync(tmpPath)
fs.mkdirSync(tmpPath)
process.chdir(tmpPath)
callback().then(() => {
process.chdir(currentPath)
rimraf(tmpPath, resolve)
})
})
}