Skip to content

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

fix(test runner): keep project suites in config order (#41780)

Domenico Gemoliffac6fe555f0
diff --git a/packages/playwright/src/runner/loadUtils.ts b/packages/playwright/src/runner/loadUtils.ts
index e409d11021..80553cb8e2 100644
--- a/packages/playwright/src/runner/loadUtils.ts
+++ b/packages/playwright/src/runner/loadUtils.ts
@@ -220,12 +220,15 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho
const finalProjectClosure = buildProjectsClosure(rootSuite.suites.map(suite => suite._fullProject!));
for (const [project, type] of finalProjectClosure) {
if (type === 'dependency')
- rootSuite._prependSuite(dependencySuites.get(project)!);
+ rootSuite._addSuite(dependencySuites.get(project)!);
else
topLevelProjects.push(project);
}
}
+ // Keep project suites in the order they are declared in the config.
+ rootSuite._entries.sort((a, b) => config.projects.indexOf((a as testNs.Suite)._fullProject!) - config.projects.indexOf((b as testNs.Suite)._fullProject!));
+
testRun.rootSuite = rootSuite;
testRun.topLevelProjects = topLevelProjects;
}
diff --git a/tests/playwright-test/ui-mode-test-filters.spec.ts b/tests/playwright-test/ui-mode-test-filters.spec.ts
index fefe28f03e..ef72b00b57 100644
--- a/tests/playwright-test/ui-mode-test-filters.spec.ts
+++ b/tests/playwright-test/ui-mode-test-filters.spec.ts
@@ -175,6 +175,32 @@ test('should filter by project', async ({ runUITest }) => {
await expect(page.getByText('Projects: foo bar')).toBeVisible();
});
+test('should list projects in config order', async ({ runUITest }) => {
+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/41779' });
+ const { page } = await runUITest({
+ ...basicTestTree,
+ 'playwright.config.ts': `
+ import { defineConfig } from '@playwright/test';
+ export default defineConfig({
+ projects: [
+ { name: 'dev-setup', testMatch: /a.test.ts/ },
+ { name: 'dev', dependencies: ['dev-setup'] },
+ { name: 'staging-setup', testMatch: /a.test.ts/ },
+ { name: 'staging', dependencies: ['staging-setup'] },
+ ],
+ });
+ `
+ });
+
+ await page.getByText('Status:').click();
+ await expect(page.getByTestId('project-filters').locator('.filter-entry')).toHaveText([
+ 'dev-setup',
+ 'dev',
+ 'staging-setup',
+ 'staging',
+ ]);
+});
+
test('should not hide filtered while running', async ({ runUITest, createLatch }) => {
const latch = createLatch();
const { page } = await runUITest({
diff --git a/tests/playwright-test/ui-mode-test-setup.spec.ts b/tests/playwright-test/ui-mode-test-setup.spec.ts
index 5738a3ec22..8b08d37985 100644
--- a/tests/playwright-test/ui-mode-test-setup.spec.ts
+++ b/tests/playwright-test/ui-mode-test-setup.spec.ts
@@ -135,12 +135,12 @@ test('should run setup and teardown projects (1)', async ({ runUITest }) => {
await expect(page.getByTestId('project-filters')).toMatchAriaSnapshot(`
- list:
- - listitem:
- - checkbox "teardown"
- listitem:
- checkbox "setup"
- listitem:
- checkbox "test"
+ - listitem:
+ - checkbox "teardown"
`);
await page.getByTitle('Run all').click();
@@ -186,12 +186,12 @@ test('should run setup and teardown projects (2)', async ({ runUITest }) => {
await expect(page.getByTestId('project-filters')).toMatchAriaSnapshot(`
- list:
- - listitem:
- - checkbox "teardown" [checked]
- listitem:
- checkbox "setup"
- listitem:
- checkbox "test" [checked]
+ - listitem:
+ - checkbox "teardown" [checked]
`);
await page.getByTitle('Run all').click();
@@ -232,12 +232,12 @@ test('should run setup and teardown projects (3)', async ({ runUITest }) => {
await expect(page.getByTestId('project-filters')).toMatchAriaSnapshot(`
- list:
- - listitem:
- - checkbox "teardown"
- listitem:
- checkbox "setup"
- listitem:
- checkbox "test" [checked]
+ - listitem:
+ - checkbox "teardown"
`);
await page.getByTitle('Run all').click();
@@ -273,12 +273,12 @@ test('should run part of the setup only', async ({ runUITest }) => {
await expect(page.getByTestId('project-filters')).toMatchAriaSnapshot(`
- list:
- - listitem:
- - checkbox "teardown" [checked]
- listitem:
- checkbox "setup" [checked]
- listitem:
- checkbox "test" [checked]
+ - listitem:
+ - checkbox "teardown" [checked]
`);
await page.getByText('setup.ts').hover();