UNPKG

888 BJavaScriptView Raw
1/* eslint-disable */
2const NodeEnvironment = require('jest-environment-node')
3const puppeteer = require('puppeteer')
4const fs = require('fs')
5const os = require('os')
6const path = require('path')
7
8const DIR = process.env.DIR || path.join(os.tmpdir(), 'jest_puppeteer_global_setup')
9
10class PuppeteerEnvironment extends NodeEnvironment {
11 async setup() {
12 console.log('Setup Test Environment.')
13 await super.setup()
14 const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8')
15 if (!wsEndpoint) {
16 throw new Error('wsEndpoint not found')
17 }
18 this.global.__BROWSER__ = await puppeteer.connect({ browserWSEndpoint: wsEndpoint })
19 }
20
21 async teardown() {
22 console.log('Teardown Test Environment.')
23 await super.teardown()
24 }
25
26 runScript(script) {
27 return super.runScript(script)
28 }
29}
30
31module.exports = PuppeteerEnvironment
32/* eslint-enable */