-
Notifications
You must be signed in to change notification settings - Fork 29.8k
/
jest-environment-puppeteer-tests.ts
38 lines (31 loc) · 1.1 KB
/
jest-environment-puppeteer-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Browser, Page, BrowserContext } from 'puppeteer';
import JestEnvironmentPuppeteer from 'jest-environment-puppeteer';
import { Config, Circus } from '@jest/types';
import { Script } from 'vm';
const myBrowser: Browser = browser; // $ExpectType Browser
const myPage: Page = page; // $ExpectType Page
const myContext: BrowserContext = context; // $ExpectType BrowserContext
jestPuppeteer.debug();
jestPuppeteer.resetPage();
// Creating a custom Jest environment
class CustomJestEnvironment extends JestEnvironmentPuppeteer {
constructor(config: Config.ProjectConfig) {
super(config);
}
async setup() {
await super.setup();
await this.global.page.goto('https://www.google.com');
}
async teardown() {
await this.global.page.waitFor(2000);
await super.teardown();
}
runScript(script: Script) {
return super.runScript(script);
}
async handleTestEvent(event: Circus.Event, state: Circus.State) {
if (event.name === 'test_fn_failure') {
console.error('woaw your test failed, you should feel bad!');
}
}
}