Skip to content

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

fix(ui): when --grep is used, UI should only show selected tests (#31815)

Simon Knottbbe5df3f5f36
diff --git a/packages/playwright/src/isomorphic/testServerInterface.ts b/packages/playwright/src/isomorphic/testServerInterface.ts
index ac06f65c24..08214ee723 100644
--- a/packages/playwright/src/isomorphic/testServerInterface.ts
+++ b/packages/playwright/src/isomorphic/testServerInterface.ts
@@ -79,6 +79,8 @@ export interface TestServerInterface {
listTests(params: {
projects?: string[];
locations?: string[];
+ grep?: string;
+ grepInvert?: string;
}): Promise<{
report: ReportEntry[],
status: reporterTypes.FullResult['status']
diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.ts
index c5133df3eb..b6c0f2fd72 100644
--- a/packages/playwright/src/runner/testServer.ts
+++ b/packages/playwright/src/runner/testServer.ts
@@ -261,6 +261,8 @@ class TestServerDispatcher implements TestServerInterface {
}
config.cliArgs = params.locations || [];
+ config.cliGrep = params.grep;
+ config.cliGrepInvert = params.grepInvert;
config.cliProjectFilter = params.projects?.length ? params.projects : undefined;
config.cliListOnly = true;
diff --git a/packages/trace-viewer/src/ui/uiModeView.tsx b/packages/trace-viewer/src/ui/uiModeView.tsx
index c626c862c9..3e0ad5c65b 100644
--- a/packages/trace-viewer/src/ui/uiModeView.tsx
+++ b/packages/trace-viewer/src/ui/uiModeView.tsx
@@ -161,7 +161,7 @@ export const UIModeView: React.FC<{}> = ({
commandQueue.current = commandQueue.current.then(async () => {
setIsLoading(true);
try {
- const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args });
+ const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args, grep: queryParams.grep, grepInvert: queryParams.grepInvert });
teleSuiteUpdater.processListReport(result.report);
} catch (e) {
// eslint-disable-next-line no-console
@@ -186,7 +186,7 @@ export const UIModeView: React.FC<{}> = ({
if (status !== 'passed')
return;
- const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args });
+ const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args, grep: queryParams.grep, grepInvert: queryParams.grepInvert });
teleSuiteUpdater.processListReport(result.report);
testServerConnection.onListChanged(updateList);
diff --git a/tests/playwright-test/match-grep.spec.ts b/tests/playwright-test/match-grep.spec.ts
index 739197cd87..357c897bcd 100644
--- a/tests/playwright-test/match-grep.spec.ts
+++ b/tests/playwright-test/match-grep.spec.ts
@@ -99,3 +99,8 @@ test('should be case sensitive by default with a regex', async ({ runInlineTest
const result = await runInlineTest(files, { 'grep': '/TesT Cc/' });
expect(result.passed).toBe(0);
});
+
+test('excluded tests should not be shown in UI', async ({ runInlineTest, runTSC }) => {
+ const result = await runInlineTest(files, { 'grep': 'Test AA' });
+ expect(result.passed).toBe(3);
+});
diff --git a/tests/playwright-test/ui-mode-test-filters.spec.ts b/tests/playwright-test/ui-mode-test-filters.spec.ts
index 776e74f31e..3f65c65a0e 100644
--- a/tests/playwright-test/ui-mode-test-filters.spec.ts
+++ b/tests/playwright-test/ui-mode-test-filters.spec.ts
@@ -229,3 +229,18 @@ test('should filter skipped', async ({ runUITest, createLatch }) => {
⊘ fails
`);
});
+
+test('should only show tests selected with --grep', async ({ runUITest }) => {
+ const { page } = await runUITest(basicTestTree, undefined, {
+ additionalArgs: ['--grep', 'fails'],
+ });
+ await expect.poll(dumpTestTree(page)).not.toContain('passes');
+});
+
+test('should not show tests filtered with --grep-invert', async ({ runUITest }) => {
+ const { page } = await runUITest(basicTestTree, undefined, {
+ additionalArgs: ['--grep-invert', 'fails'],
+ });
+ await expect.poll(dumpTestTree(page)).toContain('passes');
+ await expect.poll(dumpTestTree(page)).not.toContain('fails');
+});