forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.environment.ts
39 lines (34 loc) · 1.11 KB
/
jest.environment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const NodeEnvironment = require(`jest-environment-node`).TestEnvironment
const fsExtra = require(`fs-extra`)
const isWindows = process.platform === `win32`
class CustomEnvironment extends NodeEnvironment {
constructor(config, context) {
super(config, context)
}
async teardown(): Promise<void> {
// close open lmdbs after running test suite
// this prevent dangling open handles that sometimes cause problems
// particularly in windows tests (failures to move or delete a db file)
if (this.global.__GATSBY_OPEN_ROOT_LMDBS) {
if (isWindows) {
for (const rootDb of this.global.__GATSBY_OPEN_ROOT_LMDBS.values()) {
await rootDb.clearAsync()
await rootDb.close()
}
} else {
for (const [
dbPath,
rootDb,
] of this.global.__GATSBY_OPEN_ROOT_LMDBS.entries()) {
if (rootDb.isOperational()) {
await rootDb.close()
}
await fsExtra.remove(dbPath)
}
}
this.global.__GATSBY_OPEN_ROOT_LMDBS = undefined
}
await super.teardown()
}
}
module.exports = CustomEnvironment