Skip to content

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

chore: throw pretty error if rest parameters is used inside fixtures (#21659)

Max Schmitta2c96494e0f6
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': `