diff --git a/.webpack/webpack.coverage.mjs b/.webpack/webpack.coverage.mjs index 47204a30f8..2a527612bb 100644 --- a/.webpack/webpack.coverage.mjs +++ b/.webpack/webpack.coverage.mjs @@ -16,7 +16,6 @@ config.module.rules.push({ loader: 'babel-loader', options: { retainLines: true, - // eslint-disable-next-line no-undef plugins: [ [ 'babel-plugin-istanbul', diff --git a/e2e/baseFixtures.js b/e2e/baseFixtures.js index 681ab4319d..5cfb2678e4 100644 --- a/e2e/baseFixtures.js +++ b/e2e/baseFixtures.js @@ -60,14 +60,16 @@ function waitForAnimations(locator) { ); } -/** - * This is part of our codecoverage shim. - * @see {@link https://github.com/mxschmitt/playwright-test-coverage Github Example Project} - * @constant {string} - */ -const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output'); +const istanbulCLIOutput = fileURLToPath(new URL('.nyc_output', import.meta.url)); const extendedTest = test.extend({ + /** + * Path to output raw coverage files. Can be overridden in Playwright config file. + * @see {@link https://github.com/mxschmitt/playwright-test-coverage Github Example Project} + * @constant {string} + */ + + coveragePath: [istanbulCLIOutput, { option: true }], /** * This allows the test to manipulate the browser clock. This is useful for Visual and Snapshot tests which need * the Time Indicator Clock to be in a specific state. @@ -148,17 +150,17 @@ const extendedTest = test.extend({ * Extends the base context class to add codecoverage shim. * @see {@link https://github.com/mxschmitt/playwright-test-coverage Github Project} */ - context: async ({ context }, use) => { + context: async ({ context, coveragePath }, use) => { await context.addInitScript(() => window.addEventListener('beforeunload', () => window.collectIstanbulCoverage(JSON.stringify(window.__coverage__)) ) ); - await fs.promises.mkdir(istanbulCLIOutput, { recursive: true }); + await fs.promises.mkdir(coveragePath, { recursive: true }); await context.exposeFunction('collectIstanbulCoverage', (coverageJSON) => { if (coverageJSON) { fs.writeFileSync( - path.join(istanbulCLIOutput, `playwright_coverage_${uuid()}.json`), + path.join(coveragePath, `playwright_coverage_${uuid()}.json`), coverageJSON ); } @@ -166,9 +168,9 @@ const extendedTest = test.extend({ await use(context); for (const page of context.pages()) { - await page.evaluate(() => - window.collectIstanbulCoverage(JSON.stringify(window.__coverage__)) - ); + await page.evaluate(() => { + window.collectIstanbulCoverage(JSON.stringify(window.__coverage__)); + }); } }, /** diff --git a/e2e/playwright-ci.config.js b/e2e/playwright-ci.config.js index ee44b40641..affc39313b 100644 --- a/e2e/playwright-ci.config.js +++ b/e2e/playwright-ci.config.js @@ -3,6 +3,7 @@ // eslint-disable-next-line no-unused-vars import { devices } from '@playwright/test'; +import { fileURLToPath } from 'url'; const MAX_FAILURES = 5; const NUM_WORKERS = 2; @@ -15,7 +16,7 @@ const config = { timeout: 60 * 1000, webServer: { command: 'npm run start:coverage', - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 200 * 1000, reuseExistingServer: true //This was originally disabled to prevent differences in local debugging vs. CI. However, it significantly speeds up local debugging. @@ -28,7 +29,9 @@ const config = { ignoreHTTPSErrors: true, screenshot: 'only-on-failure', trace: 'on-first-retry', - video: 'off' + video: 'off', + // @ts-ignore - custom configuration option for nyc codecoverage output path + coveragePath: fileURLToPath(new URL('../.nyc_output', import.meta.url)) }, projects: [ { diff --git a/e2e/playwright-local.config.js b/e2e/playwright-local.config.js index 454dc97927..5a4b72e791 100644 --- a/e2e/playwright-local.config.js +++ b/e2e/playwright-local.config.js @@ -1,6 +1,6 @@ // playwright.config.js // @ts-check - +import { fileURLToPath } from 'url'; /** @type {import('@playwright/test').PlaywrightTestConfig} */ const config = { retries: 0, @@ -10,7 +10,7 @@ const config = { timeout: 30 * 1000, webServer: { command: 'npm run start:coverage', - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 120 * 1000, reuseExistingServer: true diff --git a/e2e/playwright-mobile.config.js b/e2e/playwright-mobile.config.js index 52b11aa324..036e858578 100644 --- a/e2e/playwright-mobile.config.js +++ b/e2e/playwright-mobile.config.js @@ -14,7 +14,7 @@ const config = { timeout: 30 * 1000, webServer: { command: 'npm run start:coverage', - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 200 * 1000, reuseExistingServer: true //This was originally disabled to prevent differences in local debugging vs. CI. However, it significantly speeds up local debugging. @@ -28,7 +28,9 @@ const config = { ignoreHTTPSErrors: true, screenshot: 'only-on-failure', trace: 'on-first-retry', - video: 'off' + video: 'off', + // @ts-ignore - custom configuration option for nyc codecoverage output path + coveragePath: fileURLToPath(new URL('../.nyc_output', import.meta.url)) }, projects: [ { diff --git a/e2e/playwright-performance-dev.config.js b/e2e/playwright-performance-dev.config.js index 0ad3a8835f..44c97da09e 100644 --- a/e2e/playwright-performance-dev.config.js +++ b/e2e/playwright-performance-dev.config.js @@ -1,6 +1,6 @@ // playwright.config.js // @ts-check - +import { fileURLToPath } from 'url'; /** @type {import('@playwright/test').PlaywrightTestConfig} */ const config = { retries: 1, //Only for debugging purposes for trace: 'on-first-retry' @@ -10,7 +10,7 @@ const config = { workers: 1, //Only run in serial with 1 worker webServer: { command: 'npm run start', //need development mode for performance.marks and others - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 200 * 1000, reuseExistingServer: false diff --git a/e2e/playwright-performance-prod.config.js b/e2e/playwright-performance-prod.config.js index 791c8f1d0d..2f2944de2d 100644 --- a/e2e/playwright-performance-prod.config.js +++ b/e2e/playwright-performance-prod.config.js @@ -1,6 +1,6 @@ // playwright.config.js // @ts-check - +import { fileURLToPath } from 'url'; /** @type {import('@playwright/test').PlaywrightTestConfig} */ const config = { retries: 0, //Only for debugging purposes for trace: 'on-first-retry' @@ -10,7 +10,7 @@ const config = { workers: 1, //Only run in serial with 1 worker webServer: { command: 'npm run start:prod', //Production mode - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 200 * 1000, reuseExistingServer: false //Must be run with this option to prevent dev mode diff --git a/e2e/playwright-visual-a11y.config.js b/e2e/playwright-visual-a11y.config.js index e1de0cb879..0d95f9e397 100644 --- a/e2e/playwright-visual-a11y.config.js +++ b/e2e/playwright-visual-a11y.config.js @@ -1,6 +1,6 @@ // playwright.config.js // @ts-check - +import { fileURLToPath } from 'url'; /** @type {import('@playwright/test').PlaywrightTestConfig<{ theme: string }>} */ const config = { retries: 0, // Visual tests should never retry due to snapshot comparison errors. Leaving as a shim @@ -10,7 +10,7 @@ const config = { workers: 1, //Lower stress on Circle CI Agent for Visual tests https://github.com/percy/cli/discussions/1067 webServer: { command: 'npm run start:coverage', - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 200 * 1000, reuseExistingServer: !process.env.CI diff --git a/e2e/playwright-watch.config.js b/e2e/playwright-watch.config.js index 3d4996ce00..5d578f25f0 100644 --- a/e2e/playwright-watch.config.js +++ b/e2e/playwright-watch.config.js @@ -1,6 +1,5 @@ // playwright.config.js // @ts-check - import { devices } from '@playwright/test'; import { fileURLToPath } from 'url'; @@ -11,7 +10,7 @@ const config = { timeout: 60 * 1000, webServer: { command: 'npm run start', //Start in dev mode for hot reloading - cwd: '../', // Provide cwd for the root of the project + cwd: fileURLToPath(new URL('../', import.meta.url)), // Provide cwd for the root of the project url: 'http://localhost:8080/#', timeout: 200 * 1000, reuseExistingServer: true //This was originally disabled to prevent differences in local debugging vs. CI. However, it significantly speeds up local debugging.