All files / src/tests/integrationTests prepareTestLocation.js

100% Statements 14/14
100% Branches 2/2
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x 1x 1x   1x 3x   3x     3x 3x 3x 3x 2x   2x         1x  
const path = require('path')
const uuid = require('uuid')
const fs = require('fs-extra')
const log = require('../../log')
 
const prepareTestLocation = label => {
  const location = path.join('tmp', `${uuid.v4()}-${label}`)
 
  return {
    location,
    cleanup: async () => {
      log.info('Cleaning up...')
      await fs.remove(location)
      const files = await fs.readdir('tmp')
      if (!files.length) {
        await fs.remove('tmp')
      }
      log.info('... cleaned up.')
    }
  }
}
 
module.exports = prepareTestLocation