UNPKG

@ngx-playwright/jest

Version:
98 lines 4.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightRunner = void 0; const jest_runner_1 = __importDefault(require("jest-runner")); const browsers_1 = require("./browsers"); const config_1 = require("./config"); function isDebug() { return !!process.env.PWDEBUG; } function getDefaultTimeout() { // Use 1 week if debugging is enabled, otherwise default to 15 seconds return isDebug() ? 7 * 24 * 60 * 60 * 1000 : 15000; } const browserSpecsCache = new WeakMap(); function getBrowserSpecs(config) { let browsers = browserSpecsCache.get(config); if (browsers == null) { browsers = config_1.getBrowserSpecs(config, isDebug()); browserSpecsCache.set(config, browsers); } return browsers; } async function getLauncherConfig(config, launchersByKey) { const browsers = getBrowserSpecs(config); const launchers = await Promise.all(browsers.map(async (browser) => { var _a; const cacheKey = browsers_1.getCacheKey(browser); let launcher = launchersByKey.get(cacheKey); if (launcher == null) { launcher = browsers_1.getLauncher(browser); launchersByKey.set(cacheKey, launcher); } await ((_a = launcher.setup) === null || _a === void 0 ? void 0 : _a.call(launcher)); return launcher; })); return launchers.map(launcher => launcher.getSpec()); } async function expandTests(tests, launchersByKey) { return (await Promise.all(tests.map(async (test) => { const browsers = await getLauncherConfig(test.context.config.testEnvironmentOptions, launchersByKey); return browsers.map(browser => { var _a, _b, _c, _d; return ({ ...test, context: { ...test.context, config: { ...test.context.config, runnerSpec: browser, ...(browsers.length > 1 ? { displayName: { name: test.context.config.displayName ? `${(_a = browser.name) !== null && _a !== void 0 ? _a : browser.type} ${test.context.config.displayName.name}` : (_b = browser.name) !== null && _b !== void 0 ? _b : browser.type, color: (_d = (_c = test.context.config.displayName) === null || _c === void 0 ? void 0 : _c.color) !== null && _d !== void 0 ? _d : 'yellow', }, } : {}), }, }, }); }); }))).flat(); } /** * Run tests over multiple browsers */ class PlaywrightRunner extends jest_runner_1.default { constructor(globalConfig, context) { var _a; super({ ...globalConfig, // Overrule Jest's defaults for the timeout testTimeout: (_a = globalConfig.testTimeout) !== null && _a !== void 0 ? _a : getDefaultTimeout(), }, context); } async runTests(tests, watcher, onStart, onResult, onFailure, options) { const launchersByKey = new Map(); const allTests = await expandTests(tests, launchersByKey); try { return await super.runTests(allTests, watcher, onStart, onResult, onFailure, options); } finally { await Promise.all(Array.from(launchersByKey.values(), launcher => { var _a; return (_a = launcher.teardown) === null || _a === void 0 ? void 0 : _a.call(launcher).catch(() => { // ignore errors in the teardown }); })); } } } exports.PlaywrightRunner = PlaywrightRunner; //# sourceMappingURL=runner.js.map