Skip to content

Commit

Permalink
fix(types): fix missing jestPuppeteer global before setup
Browse files Browse the repository at this point in the history
Moves global `jestPuppeteer` to environment constructor
  • Loading branch information
colinrotherham authored and gregberge committed May 24, 2023
1 parent fb691f7 commit 37e2294
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions packages/jest-environment-puppeteer/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,41 +136,36 @@ export class PuppeteerEnvironment extends NodeEnvironment {
super(config, _context);

this.global.puppeteerConfig = {};
this.global.jestPuppeteer = {};
}

// Jest is not available here, so we have to reverse engineer
// the setTimeout function, see https://github.com/facebook/jest/blob/ffe2352c781703b427fab10777043fb76d0d4267/packages/jest-runtime/src/index.ts#L2331
setTimeout(timeout: number) {
this.global[testTimeoutSymbol] = timeout;
}

async setup(): Promise<void> {
const config = await readConfig();
const global = this.global;
global.puppeteerConfig = config;

global.jestPuppeteer = {
this.global.jestPuppeteer = {
debug: async () => {
// Set timeout to 4 days
this.setTimeout(345600000);
// Run a debugger (in case Puppeteer has been launched with `{ devtools: true }`)
await getPage(global).evaluate(() => {
await getPage(this.global).evaluate(() => {
debugger;
});
return blockStdin();
},
resetPage: async () => {
await closePage(global);
await openPage(global);
await closePage(this.global);
await openPage(this.global);
},
resetBrowser: async () => {
await closeAll(global);
await initAll(global);
await closeAll(this.global);
await initAll(this.global);
},
};
}

await initAll(global);
// Jest is not available here, so we have to reverse engineer
// the setTimeout function, see https://github.com/facebook/jest/blob/ffe2352c781703b427fab10777043fb76d0d4267/packages/jest-runtime/src/index.ts#L2331
setTimeout(timeout: number) {
this.global[testTimeoutSymbol] = timeout;
}

async setup(): Promise<void> {
this.global.puppeteerConfig = await readConfig();
await initAll(this.global);
}

async teardown() {
Expand Down

0 comments on commit 37e2294

Please sign in to comment.