|
1 | | -import { Config } from "@jest/types" |
| 1 | +import type { |
| 2 | + JestEnvironmentConfig, |
| 3 | + EnvironmentContext |
| 4 | +} from "@jest/environment" |
2 | 5 | import BrowserEnvironment from "jest-environment-jsdom" |
3 | 6 | import timers from "timers" |
4 | 7 |
|
5 | 8 | class IntegrationEnvironment extends BrowserEnvironment { |
6 | | - constructor(config: Config.ProjectConfig) { |
7 | | - super( |
8 | | - Object.assign({}, config, { |
9 | | - globals: Object.assign({}, config.globals, { |
10 | | - // https://github.com/firebase/firebase-js-sdk/issues/3096#issuecomment-637584185 |
11 | | - Uint32Array: Uint32Array, |
12 | | - Uint8Array: Uint8Array, |
13 | | - ArrayBuffer: ArrayBuffer, |
| 9 | + constructor(config: JestEnvironmentConfig, context: EnvironmentContext) { |
| 10 | + super(config, context) |
| 11 | + } |
14 | 12 |
|
15 | | - // These are required to run the admin sdk in a jsdom environment |
16 | | - setImmediate: timers.setImmediate, |
17 | | - setTimeout: timers.setTimeout, |
18 | | - setInterval: timers.setInterval, |
19 | | - clearImmediate: timers.clearImmediate, |
20 | | - clearTimeout: timers.clearTimeout, |
21 | | - clearInterval: timers.clearInterval, |
| 13 | + async setup() { |
| 14 | + await super.setup() |
22 | 15 |
|
23 | | - /** jsdom's Blob implementation does not work with firebase/storage. |
24 | | - * firebase/storage *does* work with a fallback if Blob is not |
25 | | - * available, so removing the global is a hack to get storage tests |
26 | | - * working. We'll need a better solution when tests need to use Blobs. |
27 | | - * */ |
28 | | - Blob: undefined |
29 | | - }) |
30 | | - }) |
31 | | - ) |
32 | | - } |
| 16 | + // https://github.com/firebase/firebase-js-sdk/issues/3096#issuecomment-637584185 |
| 17 | + this.global.Uint32Array = Uint32Array |
| 18 | + this.global.Uint8Array = Uint8Array |
| 19 | + this.global.ArrayBuffer = ArrayBuffer |
33 | 20 |
|
34 | | - async setup() {} |
| 21 | + // These are required to run the admin sdk in a jsdom environment |
| 22 | + this.global.setImmediate = |
| 23 | + timers.setImmediate as typeof globalThis.setImmediate |
| 24 | + this.global.setTimeout = timers.setTimeout as typeof globalThis.setTimeout |
| 25 | + this.global.setInterval = |
| 26 | + timers.setInterval as typeof globalThis.setInterval |
| 27 | + this.global.clearImmediate = timers.clearImmediate |
| 28 | + this.global.clearTimeout = |
| 29 | + timers.clearTimeout as typeof globalThis.clearTimeout |
| 30 | + this.global.clearInterval = |
| 31 | + timers.clearInterval as typeof globalThis.clearInterval |
35 | 32 |
|
36 | | - async teardown() {} |
| 33 | + /** jsdom's Blob implementation does not work with firebase/storage. |
| 34 | + * firebase/storage *does* work with a fallback if Blob is not |
| 35 | + * available, so removing the global is a hack to get storage tests |
| 36 | + * working. We'll need a better solution when tests need to use Blobs. |
| 37 | + * */ |
| 38 | + ;(this.global as any).Blob = undefined |
| 39 | + } |
| 40 | + |
| 41 | + async teardown() { |
| 42 | + await super.teardown() |
| 43 | + } |
37 | 44 | } |
38 | 45 |
|
39 | 46 | export default IntegrationEnvironment |
0 commit comments