Skip to content

Commit 37e2294

Browse files
colinrotherhamgregberge
authored andcommitted
fix(types): fix missing jestPuppeteer global before setup
Moves global `jestPuppeteer` to environment constructor
1 parent fb691f7 commit 37e2294

File tree

1 file changed

+16
-21
lines changed
  • packages/jest-environment-puppeteer/src

1 file changed

+16
-21
lines changed

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,41 +136,36 @@ export class PuppeteerEnvironment extends NodeEnvironment {
136136
super(config, _context);
137137

138138
this.global.puppeteerConfig = {};
139-
this.global.jestPuppeteer = {};
140-
}
141-
142-
// Jest is not available here, so we have to reverse engineer
143-
// the setTimeout function, see https://github.com/facebook/jest/blob/ffe2352c781703b427fab10777043fb76d0d4267/packages/jest-runtime/src/index.ts#L2331
144-
setTimeout(timeout: number) {
145-
this.global[testTimeoutSymbol] = timeout;
146-
}
147-
148-
async setup(): Promise<void> {
149-
const config = await readConfig();
150-
const global = this.global;
151-
global.puppeteerConfig = config;
152-
153-
global.jestPuppeteer = {
139+
this.global.jestPuppeteer = {
154140
debug: async () => {
155141
// Set timeout to 4 days
156142
this.setTimeout(345600000);
157143
// Run a debugger (in case Puppeteer has been launched with `{ devtools: true }`)
158-
await getPage(global).evaluate(() => {
144+
await getPage(this.global).evaluate(() => {
159145
debugger;
160146
});
161147
return blockStdin();
162148
},
163149
resetPage: async () => {
164-
await closePage(global);
165-
await openPage(global);
150+
await closePage(this.global);
151+
await openPage(this.global);
166152
},
167153
resetBrowser: async () => {
168-
await closeAll(global);
169-
await initAll(global);
154+
await closeAll(this.global);
155+
await initAll(this.global);
170156
},
171157
};
158+
}
172159

173-
await initAll(global);
160+
// Jest is not available here, so we have to reverse engineer
161+
// the setTimeout function, see https://github.com/facebook/jest/blob/ffe2352c781703b427fab10777043fb76d0d4267/packages/jest-runtime/src/index.ts#L2331
162+
setTimeout(timeout: number) {
163+
this.global[testTimeoutSymbol] = timeout;
164+
}
165+
166+
async setup(): Promise<void> {
167+
this.global.puppeteerConfig = await readConfig();
168+
await initAll(this.global);
174169
}
175170

176171
async teardown() {

0 commit comments

Comments
 (0)