UNPKG

@nx/playwright

Version:

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

66 lines (65 loc) 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nxE2EPreset = nxE2EPreset; const devkit_1 = require("@nx/devkit"); const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup"); const test_1 = require("@playwright/test"); const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); /** * 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 * export default defineConfig({ * ...nxE2EPreset(__filename, 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, ts_solution_setup_1.isUsingTsSolutionSetup)(); const testResultOuputDir = isTsSolutionSetup ? 'test-output/playwright/output' : (0, node_path_1.join)(offset, 'dist', '.playwright', projectPath, 'test-output'); const reporterOutputDir = isTsSolutionSetup ? 'test-output/playwright/report' : (0, node_path_1.join)(offset, 'dist', '.playwright', projectPath, 'playwright-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: [ [ 'html', { outputFolder: reporterOutputDir, }, ], ], }); }