From 9fe65beb93100744b5808b5d84cdf75fe980de56 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 2 Dec 2021 13:52:13 -0800 Subject: [PATCH] cherry-pick+fix(#10678): test: add reporter test with grep (#10682) This includes manual fix for the issue that was fixed in trunk already, but cannot be cherry-picked. --- packages/playwright-test/src/project.ts | 2 +- tests/playwright-test/reporter.spec.ts | 30 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/playwright-test/src/project.ts b/packages/playwright-test/src/project.ts index e94304f443..ec1174b380 100644 --- a/packages/playwright-test/src/project.ts +++ b/packages/playwright-test/src/project.ts @@ -106,7 +106,7 @@ export class ProjectImpl { to._addTest(test); if (!filter(test)) { to._entries.pop(); - to.suites.pop(); + to.tests.pop(); } } } diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.ts index 932aa324e6..1a92203606 100644 --- a/tests/playwright-test/reporter.spec.ts +++ b/tests/playwright-test/reporter.spec.ts @@ -405,6 +405,36 @@ test('should show nice stacks for locators', async ({ runInlineTest }) => { ]); }); +test('should report correct tests/suites when using grep', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.spec.js': ` + const { test } = pwt; + + test.describe('@foo', () => { + test('test1', async ({ }) => { + console.log('%%test1'); + }); + test('test2', async ({ }) => { + console.log('%%test2'); + }); + }); + + test('test3', async ({ }) => { + console.log('%%test3'); + }); + `, + }, { 'grep': '@foo' }); + + expect(result.exitCode).toBe(0); + expect(result.output).toContain('%%test1'); + expect(result.output).toContain('%%test2'); + expect(result.output).not.toContain('%%test3'); + const fileSuite = result.report.suites[0]; + expect(fileSuite.suites.length).toBe(1); + expect(fileSuite.suites[0].specs.length).toBe(2); + expect(fileSuite.specs.length).toBe(0); +}); + function stripEscapedAscii(str: string) { return str.replace(/\\u00[a-z0-9][a-z0-9]\[[^m]+m/g, ''); }