Skip to content

Commit fb691f7

Browse files
colinrotherhamgregberge
authored andcommitted
fix(types): fix environment global types
PuppeteerEnvironment global is now typed with page/browser globals etc
1 parent 7becfaf commit fb691f7

File tree

1 file changed

+15
-3
lines changed
  • packages/jest-environment-puppeteer/src

1 file changed

+15
-3
lines changed

packages/jest-environment-puppeteer/src/env.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* eslint-disable no-debugger */
2+
import type {
3+
EnvironmentContext,
4+
JestEnvironmentConfig,
5+
} from "@jest/environment";
26
import NodeEnvironment from "jest-environment-node";
37
import { readConfig } from "./config";
48
import { blockStdin } from "./stdin";
@@ -126,6 +130,15 @@ const closeAll = async (global: StrictGlobal) => {
126130
};
127131

128132
export class PuppeteerEnvironment extends NodeEnvironment {
133+
declare global: StrictGlobal & NodeEnvironment["global"];
134+
135+
constructor(config: JestEnvironmentConfig, _context: EnvironmentContext) {
136+
super(config, _context);
137+
138+
this.global.puppeteerConfig = {};
139+
this.global.jestPuppeteer = {};
140+
}
141+
129142
// Jest is not available here, so we have to reverse engineer
130143
// the setTimeout function, see https://github.com/facebook/jest/blob/ffe2352c781703b427fab10777043fb76d0d4267/packages/jest-runtime/src/index.ts#L2331
131144
setTimeout(timeout: number) {
@@ -134,7 +147,7 @@ export class PuppeteerEnvironment extends NodeEnvironment {
134147

135148
async setup(): Promise<void> {
136149
const config = await readConfig();
137-
const global = this.global as unknown as StrictGlobal;
150+
const global = this.global;
138151
global.puppeteerConfig = config;
139152

140153
global.jestPuppeteer = {
@@ -161,7 +174,6 @@ export class PuppeteerEnvironment extends NodeEnvironment {
161174
}
162175

163176
async teardown() {
164-
const global = this.global as unknown as StrictGlobal;
165-
await closeAll(global);
177+
await closeAll(this.global);
166178
}
167179
}

0 commit comments

Comments
 (0)