UNPKG

@zyf2e/mitojs

Version:

A SDK for monitoring browser errors

40 lines (32 loc) 1 kB
/* eslint-disable @typescript-eslint/no-var-requires */ const chalk = require('chalk') const NodeEnvironment = require('jest-environment-node') const puppeteer = require('puppeteer') const fs = require('fs') const os = require('os') const path = require('path') const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup') class PuppeteerEnvironment extends NodeEnvironment { constructor(config) { super(config) } async setup() { // console.log(chalk.yellow('Setup Test Environment.')) await super.setup() const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8') if (!wsEndpoint) { throw new Error('wsEndpoint not found') } this.global.__BROWSER__ = await puppeteer.connect({ browserWSEndpoint: wsEndpoint }) } async teardown() { console.log(chalk.yellow('Teardown Test Environment.')) await super.teardown() } runScript(script) { return super.runScript(script) } } module.exports = PuppeteerEnvironment