Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(tele receiver): make sure to resolve "." and ".." in relative paths (#38377)
Dmitry Gozman44664ab596a9
diff --git a/packages/playwright/src/isomorphic/teleSuiteUpdater.ts b/packages/playwright/src/isomorphic/teleSuiteUpdater.tsindex 7c4c14fae7..526d04695c 100644--- a/packages/playwright/src/isomorphic/teleSuiteUpdater.ts+++ b/packages/playwright/src/isomorphic/teleSuiteUpdater.ts@@ -61,7 +61,7 @@ export class TeleSuiteUpdater {this._receiver = new TeleReporterReceiver(this._createReporter(), {mergeProjects: true,mergeTestCases: true,- resolvePath: (rootDir, relativePath) => rootDir + options.pathSeparator + relativePath,+ resolvePath: createPathResolve(options.pathSeparator),clearPreviousResultsWhenTestBegins: true,});this._options = options;@@ -71,8 +71,8 @@ export class TeleSuiteUpdater {return {version: () => 'v2',- onConfigure: (c: reporterTypes.FullConfig) => {- this.config = c;+ onConfigure: (config: reporterTypes.FullConfig) => {+ this.config = config;// TeleReportReceiver is merging everything into a single suite, so when we// run one test, we still get many tests via rootSuite.allTests().length.// To work around that, have a dedicated per-run receiver that will only have@@ -86,8 +86,9 @@ export class TeleSuiteUpdater {}, {mergeProjects: true,mergeTestCases: false,- resolvePath: (rootDir, relativePath) => rootDir + this._options.pathSeparator + relativePath,+ resolvePath: createPathResolve(this._options.pathSeparator),});+ void this._lastRunReceiver.dispatch({ method: 'onConfigure', params: { config } });},onBegin: (suite: reporterTypes.Suite) => {@@ -177,3 +178,24 @@ export class TeleSuiteUpdater {};}}++function createPathResolve(pathSeparator: string) {+ return (rootDir: string, relativePath: string) => {+ const segments: string[] = [];+ for (const segment of [...rootDir.split(pathSeparator), ...relativePath.split(pathSeparator)]) {+ // Careful with "C:\\" on win32 and "/root" on posix.+ const isAfterDrive = pathSeparator === '\\' && segments.length === 1 && segments[0].endsWith(':');+ const isFirst = !segments.length;+ if (!segment && !isFirst && !isAfterDrive)+ continue;+ if (segment === '.')+ continue;+ if (segment === '..') {+ segments.pop();+ continue;+ }+ segments.push(segment);+ }+ return segments.join(pathSeparator);+ };+}diff --git a/packages/playwright/src/reporters/merge.ts b/packages/playwright/src/reporters/merge.tsindex 3571f62972..b099c0c791 100644--- a/packages/playwright/src/reporters/merge.ts+++ b/packages/playwright/src/reporters/merge.ts@@ -58,10 +58,15 @@ export async function createMergedReport(config: FullConfigInternal, dir: stringconst eventData = await mergeEvents(dir, shardFiles, stringPool, printStatus, rootDirOverride);// If explicit config is provided, use platform path separator, otherwise use the one from the report (if any).const pathSeparator = rootDirOverride ? path.sep : (eventData.pathSeparatorFromMetadata ?? path.sep);+ const pathPackage = pathSeparator === '/' ? path.posix : path.win32;const receiver = new TeleReporterReceiver(multiplexer, {mergeProjects: false,mergeTestCases: false,- resolvePath: (rootDir, relativePath) => stringPool.internString(rootDir + pathSeparator + relativePath),+ // When merging on a different OS, an absolute path like `C:\foo\bar` from win may look like+ // a relative path on posix, and vice versa.+ // Therefore, we cannot use `path.resolve()` here - it will resolve relative-looking paths+ // against `process.cwd()`, while we just want to normalize ".." and "." segments.+ resolvePath: (rootDir, relativePath) => stringPool.internString(pathPackage.normalize(pathPackage.join(rootDir, relativePath))),configOverrides: config.config,});printStatus(`processing test events`);diff --git a/tests/playwright-test/ui-mode-trace.spec.ts b/tests/playwright-test/ui-mode-trace.spec.tsindex ac62040b1b..fe31875767 100644--- a/tests/playwright-test/ui-mode-trace.spec.ts+++ b/tests/playwright-test/ui-mode-trace.spec.ts@@ -48,6 +48,35 @@ test('should merge trace events', async ({ runUITest }) => {]);});+test('should work with non-existing rootDir and testDir outside of it', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/38367' },+}, async ({ runUITest }) => {+ const { page } = await runUITest({+ 'playwright.config.ts': `+ import { defineConfig } from '@playwright/test';+ export default defineConfig({+ testDir: './nothingness',+ projects: [+ { name: 'main', testDir: './tests' },+ ],+ });+ `,+ 'tests/a.test.ts': `+ import { test, expect } from '@playwright/test';+ test('example test', async ({ page }) => {+ await page.setContent('<button>Submit</button>');+ });+ `,+ });++ await page.getByText('example test').dblclick();+ await expect(page.getByTestId('actions-tree')).toMatchAriaSnapshot(`+ - treeitem /Before Hooks/+ - treeitem /Set content/ [selected]+ - treeitem /After Hooks/+ `);+});+test('should merge web assertion events', async ({ runUITest }, testInfo) => {const { page } = await runUITest({'a.test.ts': `