Skip to content

Commit

Permalink
🤖 Merge PR #46845 [jest-environment-puppeteer] Allow jest 26 and exte…
Browse files Browse the repository at this point in the history
…nd from jest-environment-node by @danez

The source code of the jest-environment-puppeteer also extends jest-environment-node, so it makes sense that the types do the same
  • Loading branch information
danez committed Sep 28, 2020
1 parent f9deaf3 commit f477068
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 37 deletions.
38 changes: 6 additions & 32 deletions types/jest-environment-puppeteer/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Type definitions for jest-environment-puppeteer 4.3
// Type definitions for jest-environment-puppeteer 4.4
// Project: https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer
// Definitions by: Josh Goldberg <https://github.com/joshuakgoldberg>
// Ifiok Jr. <https://github.com/ifiokjr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.4
// TypeScript Version: 3.8

import { JestEnvironment } from '@jest/environment';
import { JestFakeTimers as FakeTimers } from '@jest/fake-timers';
import { Circus, Global as GlobalType, Config } from '@jest/types';
import { ModuleMocker } from 'jest-mock';
import NodeEnvironment = require('jest-environment-node');
import { Global as GlobalType } from '@jest/types';
import { Browser, Page, BrowserContext } from 'puppeteer';
import { Script, Context } from 'vm';
import { Context } from 'vm';

interface JestPuppeteer {
/**
Expand Down Expand Up @@ -49,12 +47,6 @@ interface JestPuppeteer {
debug(): Promise<void>;
}

interface Timer {
id: number;
ref: () => Timer;
unref: () => Timer;
}

interface Global extends GlobalType.Global {
browser: Browser;
context: Context;
Expand All @@ -63,26 +55,8 @@ interface Global extends GlobalType.Global {
}

/** Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment. */
declare class PuppeteerEnvironment implements JestEnvironment {
context: Context | null;
fakeTimers: FakeTimers<Timer> | null;
declare class PuppeteerEnvironment extends NodeEnvironment {
global: Global;
moduleMocker: ModuleMocker | null;
constructor(config: Config.ProjectConfig);

/**
* Setup runs when the environment is being spun up, generally before each test suite
* You should always call `await super.setup()` in here
*/
setup(): Promise<void>;

/**
* Teardowns runs as the environment is being torn down, generally after each test suite.
* You should always call `await super.tearDown()` in here
*/
teardown(): Promise<void>;
runScript(script: Script): any;
handleTestEvent?(event: Circus.Event, state: Circus.State): void;
}

declare global {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CustomJestEnvironment extends JestEnvironmentPuppeteer {
await super.teardown();
}

runScript(script: Script) {
runScript(script: Script): any {
return super.runScript(script);
}

Expand Down
6 changes: 2 additions & 4 deletions types/jest-environment-puppeteer/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"private": true,
"dependencies": {
"@jest/environment": "^24",
"@jest/fake-timers": "^24",
"@jest/types": "^24",
"jest-mock": "^24"
"@jest/types": ">=24 && <=26",
"jest-environment-node": ">=24 && <=26"
}
}

0 comments on commit f477068

Please sign in to comment.