2019-03-20 08:17:56 -05:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
|
|
import rimraf from 'rimraf'
|
|
|
|
|
|
2020-10-08 11:21:39 -04:00
|
|
|
let id = 0
|
|
|
|
|
|
2020-10-16 13:30:06 -04:00
|
|
|
export default function (callback) {
|
2020-10-16 15:39:44 -04:00
|
|
|
return new Promise((resolve) => {
|
2020-10-08 11:21:39 -04:00
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|