Debian Codegraph @

nyc/test/helpers/temp-dir-setup.js

raw ◀ ▶
1 Debian patch touch this file
1 'use strict'
2
3 const path = require('path')
4 const fs = require('fs')
5 const makeDir = require('make-dir')
•6 const { rimraf } = require('rimraf')
7 const { promisify } = require('util')
8
9 const mkdtemp = promisify(fs.mkdtemp)
10
11 function tempDirSetup (t, testFile) {
12 const { dir, name } = path.parse(testFile)
13 const tempDirBase = path.resolve(dir, 'temp-dir-' + name)
14
15 makeDir.sync(tempDirBase)
16
17 // Do not use arrow function for beforeEach
18 // or afterEach, they need this from tap.
19 t.beforeEach(async function () {
20 this.tempDir = await mkdtemp(tempDirBase + '/')
21 })
22
23 t.afterEach(function () {
24 return rimraf(this.tempDir)
25 })
26
27 t.tearDown(() => rimraf(tempDirBase))
28 }
29
30 module.exports = tempDirSetup