UNPKG

rerumaccusamus

Version:

The meta-framework suite designed from scratch for frontend-focused modern web development.

41 lines (33 loc) 1.04 kB
/* eslint-disable filenames/match-exported,no-useless-constructor */ // puppeteer_environment.js const { readFile } = require('fs').promises; const os = require('os'); const path = require('path'); const puppeteer = require('puppeteer'); const NodeEnvironment = require('jest-environment-node'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); class PuppeteerEnvironment extends NodeEnvironment { constructor(config) { super(config); } async setup() { await super.setup(); // get the wsEndpoint const wsEndpoint = await readFile(path.join(DIR, 'wsEndpoint'), 'utf8'); if (!wsEndpoint) { throw new Error('wsEndpoint not found'); } // connect to puppeteer this.global.__BROWSER__ = await puppeteer.connect({ browserWSEndpoint: wsEndpoint, }); } async teardown() { await super.teardown(); } getVmContext() { return super.getVmContext(); } } module.exports = PuppeteerEnvironment; /* eslint-enable filenames/match-exported,no-useless-constructor */