Skip to content

Commit

Permalink
fix(e2e): specify .nyc_output path as custom config setting (#7658)
Browse files Browse the repository at this point in the history
* fix: specify .nyc_output path as custom config setting

* fix: coverage for mobile suite

* fix: pathing in playwright configs
  • Loading branch information
ozyx authored Apr 1, 2024
1 parent f98eb31 commit 311ad0b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 27 deletions.
1 change: 0 additions & 1 deletion .webpack/webpack.coverage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ config.module.rules.push({
loader: 'babel-loader',
options: {
retainLines: true,
// eslint-disable-next-line no-undef
plugins: [
[
'babel-plugin-istanbul',
Expand Down
26 changes: 14 additions & 12 deletions e2e/baseFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -148,27 +150,27 @@ 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
);
}
});

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__));
});
}
},
/**
Expand Down
7 changes: 5 additions & 2 deletions e2e/playwright-ci.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -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: [
{
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright-local.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// playwright.config.js
// @ts-check

import { fileURLToPath } from 'url';
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
retries: 0,
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions e2e/playwright-mobile.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: [
{
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright-performance-dev.config.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright-performance-prod.config.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright-visual-a11y.config.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions e2e/playwright-watch.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// playwright.config.js
// @ts-check

import { devices } from '@playwright/test';
import { fileURLToPath } from 'url';

Expand All @@ -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.
Expand Down

0 comments on commit 311ad0b

Please sign in to comment.