1 |
|
2 | const fs = require('fs')
|
3 | const os = require('os')
|
4 | const path = require('path')
|
5 |
|
6 | const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup')
|
7 |
|
8 | function rimraf(dirPath) {
|
9 | function rmFile(entry) {
|
10 | const entryPath = path.join(dirPath, entry)
|
11 | if (fs.lstatSync(entryPath).isDirectory()) {
|
12 | rimraf(entryPath)
|
13 | } else {
|
14 | fs.unlinkSync(entryPath)
|
15 | }
|
16 | }
|
17 | if (fs.existsSync(dirPath)) {
|
18 | fs.readdirSync(dirPath).forEach(rmFile)
|
19 | fs.rmdirSync(dirPath)
|
20 | }
|
21 | }
|
22 |
|
23 | module.exports = async function teardown() {
|
24 | console.log('Teardown Puppeteer')
|
25 | await global.SPDT_BROWSER.close()
|
26 | rimraf(DIR)
|
27 | }
|
28 |
|