2019-04-29 01:44:29 -05:00
|
|
|
const { yellow } = require('kleur');
|
2018-02-08 16:24:34 -05:00
|
|
|
const NodeEnvironment = require('jest-environment-node');
|
|
|
|
const puppeteer = require('puppeteer');
|
|
|
|
const fs = require('fs');
|
|
|
|
const os = require('os');
|
|
|
|
const path = require('path');
|
2018-06-17 06:34:59 -05:00
|
|
|
const {VerdaccioConfig} = require("../lib/verdaccio-server");
|
|
|
|
const VerdaccioProcess = require("../lib/server_process");
|
|
|
|
const Server = require("../lib/server");
|
2018-02-10 10:43:14 -05:00
|
|
|
|
2018-02-08 16:24:34 -05:00
|
|
|
|
|
|
|
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
|
|
|
|
|
|
|
|
class PuppeteerEnvironment extends NodeEnvironment {
|
|
|
|
constructor(config) {
|
|
|
|
super(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
async setup() {
|
2018-02-10 10:43:14 -05:00
|
|
|
const config1 = new VerdaccioConfig(path.join(__dirname, './store-e2e'),
|
2018-03-13 16:15:21 -05:00
|
|
|
path.join(__dirname, './config/config-scoped-e2e.yaml'), 'http://0.0.0.0:55558/', 55558);
|
|
|
|
const config2 = new VerdaccioConfig(path.join(__dirname, './store-e2e'),
|
|
|
|
path.join(__dirname, './config/config-protected-e2e.yaml'), 'http://0.0.0.0:55552/', 55552);
|
2018-02-10 10:43:14 -05:00
|
|
|
const server1 = new Server.default(config1.domainPath);
|
2018-03-13 16:15:21 -05:00
|
|
|
const server2 = new Server.default(config2.domainPath);
|
2018-02-10 10:43:14 -05:00
|
|
|
const process1 = new VerdaccioProcess.default(config1, server1, false);
|
2018-03-13 16:15:21 -05:00
|
|
|
const process2 = new VerdaccioProcess.default(config2, server2, false);
|
2018-02-10 10:43:14 -05:00
|
|
|
const fork = await process1.init();
|
2018-03-13 16:15:21 -05:00
|
|
|
const fork2 = await process2.init();
|
2018-02-10 10:43:14 -05:00
|
|
|
this.global.__VERDACCIO_E2E__ = fork[0];
|
2018-03-13 16:15:21 -05:00
|
|
|
this.global.__VERDACCIO__PROTECTED_E2E__ = fork2[0];
|
2018-02-10 10:43:14 -05:00
|
|
|
|
2019-04-29 01:44:29 -05:00
|
|
|
console.log(yellow('Setup Test Environment.'));
|
2018-02-08 16:24:34 -05:00
|
|
|
await super.setup();
|
|
|
|
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
|
|
|
|
if (!wsEndpoint) {
|
|
|
|
throw new Error('wsEndpoint not found')
|
|
|
|
}
|
2018-02-10 10:43:14 -05:00
|
|
|
this.global.__SERVER__ = server1;
|
2018-03-13 16:15:21 -05:00
|
|
|
this.global.__SERVER_PROTECTED__ = server2;
|
2018-02-08 16:24:34 -05:00
|
|
|
this.global.__BROWSER__ = await puppeteer.connect({
|
|
|
|
browserWSEndpoint: wsEndpoint,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async teardown() {
|
2019-04-29 01:44:29 -05:00
|
|
|
console.log(yellow('Teardown Test Environment.'));
|
2018-02-10 10:43:14 -05:00
|
|
|
await super.teardown();
|
|
|
|
this.global.__VERDACCIO_E2E__.stop();
|
2018-03-13 16:15:21 -05:00
|
|
|
this.global.__VERDACCIO__PROTECTED_E2E__.stop();
|
2018-02-08 16:24:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
runScript(script) {
|
2018-02-10 10:43:14 -05:00
|
|
|
return super.runScript(script);
|
2018-02-08 16:24:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PuppeteerEnvironment;
|