0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00
wagtail/client/tests/integration/PuppeteerEnvironment.js
Thibaud Colas af942a27e4
Reformat codebase with Prettier (#7912)
- Automated reformatting
- Manually change code where Prettier reformatting causes issues
- Revert "Disable Prettier formatting in CI for now"
2022-02-04 11:57:55 +00:00

49 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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');
/**
* Custom Puppeteer environment as documented on https://jestjs.io/docs/puppeteer.
* We dont use jest-puppeteer because its unreliable.
*/
class PuppeteerEnvironment extends NodeEnvironment {
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');
}
this.global.TEST_ORIGIN =
process.env.TEST_ORIGIN ?? 'http://localhost:8000';
// connect to puppeteer
this.global.browser = await puppeteer.connect({
browserWSEndpoint: wsEndpoint,
defaultViewport: {
width: 1024,
height: 768,
},
});
this.global.page = await this.global.browser.newPage();
}
async teardown() {
await this.global.page.close();
await super.teardown();
}
getVmContext() {
return super.getVmContext();
}
}
module.exports = PuppeteerEnvironment;