chore: throw pretty error if rest parameters is used inside fixtures (#21659)
Fixes https://github.com/microsoft/playwright/issues/21566
This commit is contained in:
parent
716d451be5
commit
a2c96494e0
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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': `
|
||||
|
|
|
|||
Loading…
Reference in New Issue