0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 13:10:14 +01:00
wagtail/client/tests/integration/setup.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-11-12 17:27:10 +01:00
const { mkdir, writeFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const puppeteer = require('puppeteer');
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
/**
* Custom Puppeteer setup as documented on https://jestjs.io/docs/puppeteer.
*/
module.exports = async () => {
const browser = await puppeteer.launch();
// store the browser instance so we can teardown it later
// this global is only available in the teardown but not in TestEnvironments
global.__BROWSER_GLOBAL__ = browser;
// Make sure this matches the origin defined in PuppeteerEnvironment.js.
const testOrigin = process.env.TEST_ORIGIN ?? 'http://localhost:8000';
2021-11-12 17:27:10 +01:00
// use the file system to expose the wsEndpoint for TestEnvironments
await mkdir(DIR, { recursive: true });
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
// Automatically log into the Wagtail admin.
const page = await browser.newPage();
await page.goto(`${testOrigin}/admin/login/`);
2021-11-12 17:27:10 +01:00
await page.type('#id_username', 'admin');
await page.type('#id_password', 'changeme');
await Promise.all([
page.waitForNavigation({ waitUntil: 'load' }),
page.keyboard.press('Enter'),
]);
};