Skip to content

Commit

Permalink
chore: Adjust jest environment conditionally for OS (#37452)
Browse files Browse the repository at this point in the history
Co-authored-by: LekoArts <[email protected]>
  • Loading branch information
pieh and LekoArts authored Jan 26, 2023
1 parent bea75ae commit 6268730
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions jest.environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const NodeEnvironment = require(`jest-environment-node`).TestEnvironment
const fsExtra = require(`fs-extra`)

const isWindows = process.platform === `win32`

class CustomEnvironment extends NodeEnvironment {
constructor(config, context) {
Expand All @@ -10,10 +13,23 @@ class CustomEnvironment extends NodeEnvironment {
// 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) {
for (const rootDb of this.global.__GATSBY_OPEN_ROOT_LMDBS.values()) {
await rootDb.clearAsync()
await rootDb.close()
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()
Expand Down

0 comments on commit 6268730

Please sign in to comment.