Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(deps): `--repeat-each` should not apply to dependencies (#22858)

Dmitry Gozman03616e976ef9
diff --git a/packages/playwright-test/src/common/config.ts b/packages/playwright-test/src/common/config.ts
index 198eff70ac..6de5ea0e68 100644
--- a/packages/playwright-test/src/common/config.ts
+++ b/packages/playwright-test/src/common/config.ts
@@ -164,7 +164,9 @@ export class FullProjectInternal {
grep: takeFirst(projectConfig.grep, config.grep, defaultGrep),
grepInvert: takeFirst(projectConfig.grepInvert, config.grepInvert, null),
outputDir: takeFirst(configCLIOverrides.outputDir, pathResolve(configDir, projectConfig.outputDir), pathResolve(configDir, config.outputDir), path.join(throwawayArtifactsPath, 'test-results')),
- repeatEach: takeFirst(configCLIOverrides.repeatEach, projectConfig.repeatEach, config.repeatEach, 1),
+ // Note: we either apply the cli override for repeatEach or not, depending on whether the
+ // project is top-level vs dependency. See collectProjectsAndTestFiles in loadUtils.
+ repeatEach: takeFirst(projectConfig.repeatEach, config.repeatEach, 1),
retries: takeFirst(configCLIOverrides.retries, projectConfig.retries, config.retries, 0),
metadata: takeFirst(projectConfig.metadata, config.metadata, undefined),
name: takeFirst(projectConfig.name, config.name, ''),
diff --git a/packages/playwright-test/src/runner/loadUtils.ts b/packages/playwright-test/src/runner/loadUtils.ts
index 8a5b9a7b77..202c7ad403 100644
--- a/packages/playwright-test/src/runner/loadUtils.ts
+++ b/packages/playwright-test/src/runner/loadUtils.ts
@@ -73,6 +73,12 @@ export async function collectProjectsAndTestFiles(testRun: TestRun, additionalFi
}
}
+ // Apply overrides that are only applicable to top-level projects.
+ for (const [project, type] of projectClosure) {
+ if (type === 'top-level')
+ project.project.repeatEach = project.fullConfig.configCLIOverrides.repeatEach ?? project.project.repeatEach;
+ }
+
testRun.projects = [...filesToRunByProject.keys()];
testRun.projectFiles = filesToRunByProject;
testRun.projectType = projectClosure;
diff --git a/tests/playwright-test/deps.spec.ts b/tests/playwright-test/deps.spec.ts
index 57a3ce5783..5c10b4b850 100644
--- a/tests/playwright-test/deps.spec.ts
+++ b/tests/playwright-test/deps.spec.ts
@@ -559,3 +559,25 @@ test('should complain about teardown used multiple times', async ({ runInlineTes
expect(result.exitCode).toBe(1);
expect(result.output).toContain(`Project C can not be designated as teardown to multiple projects (A and B)`);
});
+
+test('should only apply --repeat-each to top-level', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = {
+ projects: [
+ { name: 'A' },
+ { name: 'B', dependencies: ['A'] },
+ { name: 'C', dependencies: ['A'] },
+ ],
+ };`,
+ 'test.spec.ts': `
+ import { test, expect } from '@playwright/test';
+ test('test', async ({}, testInfo) => {
+ console.log('\\n%%' + testInfo.project.name);
+ });
+ `,
+ }, { 'workers': 1, 'repeat-each': 2 });
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(5);
+ expect(result.outputLines).toEqual(['A', 'B', 'B', 'C', 'C']);
+});