From a2c96494e0f6cd1b20dc1d0e591ac6581e200c60 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 14 Mar 2023 17:35:52 +0100 Subject: [PATCH] chore: throw pretty error if rest parameters is used inside fixtures (#21659) Fixes https://github.com/microsoft/playwright/issues/21566 --- .../playwright-test/src/common/fixtures.ts | 5 +++++ tests/playwright-test/fixtures.spec.ts | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/playwright-test/src/common/fixtures.ts b/packages/playwright-test/src/common/fixtures.ts index 2b8b5e55d3..716b224d9a 100644 --- a/packages/playwright-test/src/common/fixtures.ts +++ b/packages/playwright-test/src/common/fixtures.ts @@ -243,6 +243,11 @@ function innerFixtureParameterNames(fn: Function, location: Location, onError: L const colon = prop.indexOf(':'); return colon === -1 ? prop.trim() : prop.substring(0, colon).trim(); }); + const restProperty = props.find(prop => prop.startsWith('...')); + if (restProperty) { + onError({ message: `Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma.`, location }); + return []; + } return props; } diff --git a/tests/playwright-test/fixtures.spec.ts b/tests/playwright-test/fixtures.spec.ts index e9c9fa0fb5..4edc66c3c1 100644 --- a/tests/playwright-test/fixtures.spec.ts +++ b/tests/playwright-test/fixtures.spec.ts @@ -58,6 +58,26 @@ test('should work with comments inside fixtures', async ({ runInlineTest }) => { expect(results[0].status).toBe('passed'); }); +test('should throw a pretty error if fixtures use rest property', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import { test as base, expect } from '@playwright/test'; + const test = base.extend({ + asdf: async ({...props}, use) => await use(123), + }); + test('should not allow rest property inside tests', ({...all}) => { + expect(asdf).toBe(123); + }); + test('should not allow rest property inside fixtures', ({asdf}) => { + expect(asdf).toBe(123); + }); + ` + }); + expect(result.exitCode).toBe(1); + expect(result.output).toContain('Rest property "...all" is not supported. List all used fixtures explicitly, separated by comma.'); + expect(result.output).toContain('Rest property "...props" is not supported. List all used fixtures explicitly, separated by comma.'); +}); + test('should work with a sync test function', async ({ runInlineTest }) => { const { results } = await runInlineTest({ 'a.test.ts': `