fix(playwright-test): prohibit async functions passed to describe (#14538)

References #14533
This commit is contained in:
Andrey Lushnikov 2022-06-02 10:44:47 -06:00 committed by GitHub
parent 321db57e96
commit bd0fe50a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -129,7 +129,9 @@ export class TestTypeImpl {
}
setCurrentlyLoadingFileSuite(child);
fn();
const result = fn();
if (result instanceof Promise)
throw errorWithLocation(location, 'describe cannot use async functions as callbacks');
setCurrentlyLoadingFileSuite(suite);
}

View File

@ -48,6 +48,17 @@ test('it should enforce unique test names based on the describe block name', asy
expect(result.output).toContain(` - tests${path.sep}example.spec.js:8`);
});
test('it should prohibit async functions in test.describe', async ({ runInlineTest }) => {
const result = await runInlineTest({
'tests/example.spec.js': `
const { test } = pwt;
test.describe('hello', async () => { test('my world', () => {}) });
`
});
expect(result.exitCode).toBe(1);
expect(result.output).toContain('describe cannot use async functions as callbacks');
});
test('it should not allow multiple tests with the same name in multiple files', async ({ runInlineTest }) => {
const result = await runInlineTest({
'tests/example1.spec.js': `