UNPKG

@nx/playwright

Version:

The Nx Plugin for Playwright contains executors and generators allowing your workspace to use the powerful Playwright integration testing capabilities.

89 lines (88 loc) 3.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nxE2EPreset = nxE2EPreset; const devkit_1 = require("@nx/devkit"); const internal_1 = require("@nx/devkit/internal"); const internal_2 = require("@nx/js/internal"); const test_1 = require("@playwright/test"); const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const semver_1 = require("semver"); const versions_1 = require("./versions"); /** * nx E2E Preset for Playwright * @description * this preset contains the base configuration * for your e2e tests that nx recommends. * By default html reporter is configured * along with the following browsers: * - chromium * - firefox * - webkit * These are generated by default. * * you can easily extend this within your playwright config via spreading the preset * @example * // Nx generates `playwright.config.mts` (ESM). Pass `import.meta.dirname`. * // For hand-written CJS configs (`.cts` or `.ts` outside a `type: "module"` * // workspace), pass `__filename` instead. * export default defineConfig({ * ...nxE2EPreset(import.meta.dirname, options) * // add your own config here * }) * * @param pathToConfig will be used to construct the output paths for reporters and test results * @param options optional configuration options */ function nxE2EPreset(pathToConfig, options) { const normalizedPath = (0, node_fs_1.lstatSync)(pathToConfig).isDirectory() ? pathToConfig : (0, node_path_1.dirname)(pathToConfig); const projectPath = (0, node_path_1.relative)(devkit_1.workspaceRoot, normalizedPath); const offset = (0, node_path_1.relative)(normalizedPath, devkit_1.workspaceRoot); const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(); const testResultOuputDir = isTsSolutionSetup ? 'test-output/playwright/output' : (0, node_path_1.join)(offset, 'dist', '.playwright', projectPath, 'test-output'); const reporters = []; reporters.push([ 'html', { outputFolder: isTsSolutionSetup ? 'test-output/playwright/report' : (0, node_path_1.join)(offset, 'dist', '.playwright', projectPath, 'playwright-report'), open: options?.openHtmlReport ?? 'on-failure', }, ]); if (options?.generateBlobReports === true) { const installed = (0, internal_1.getInstalledPackageVersion)('@playwright/test'); if (installed && (0, semver_1.lt)(installed, versions_1.minPlaywrightVersionForBlobReports)) { throw new Error(`The "blob" reporter requires "@playwright/test" version ${versions_1.minPlaywrightVersionForBlobReports} or greater. You are currently using version ${installed}. Either upgrade "@playwright/test" or set "generateBlobReports" to false.`); } } const shouldGenerateBlobReports = options?.generateBlobReports ?? !!process.env['CI']; if (shouldGenerateBlobReports) { reporters.push([ 'blob', { outputDir: isTsSolutionSetup ? 'test-output/playwright/blob-report' : (0, node_path_1.join)(offset, 'dist', '.playwright', projectPath, 'blob-report'), }, ]); } return (0, test_1.defineConfig)({ testDir: options?.testDir ?? './src', outputDir: testResultOuputDir, /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, /* Retry on CI only */ retries: process.env.CI ? 2 : 0, /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: [...reporters], }); }