mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-23 22:27:34 -05:00
38 lines
1,005 B
JavaScript
38 lines
1,005 B
JavaScript
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const debug = require('debug')('verdaccio:e2e:ui:puppeteer');
|
|
|
|
const NodeEnvironment = require('jest-environment-node');
|
|
const { yellow } = require('kleur');
|
|
const puppeteer = require('puppeteer');
|
|
|
|
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
|
|
class PuppeteerEnvironment extends NodeEnvironment {
|
|
constructor(config) {
|
|
super(config);
|
|
}
|
|
|
|
async setup() {
|
|
debug(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() {
|
|
debug(yellow('Teardown Test Environment.'));
|
|
await super.teardown();
|
|
}
|
|
|
|
runScript(script) {
|
|
return super.runScript(script);
|
|
}
|
|
}
|
|
|
|
module.exports = PuppeteerEnvironment;
|