Skip to content

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

fix(test): clarify error for test() after await in async describe (#41145)

Yury Semikhatsky26e3dc2b8d0f
diff --git a/packages/playwright/src/common/testType.ts b/packages/playwright/src/common/testType.ts
index f08eb29b7e..9911efe09c 100644
--- a/packages/playwright/src/common/testType.ts
+++ b/packages/playwright/src/common/testType.ts
@@ -85,6 +85,7 @@ export class TestTypeImpl {
`- You are calling ${title} in a file that is imported by the configuration file.`,
`- You have two different versions of @playwright/test. This usually happens`,
` when one of the dependencies in your package.json depends on @playwright/test.`,
+ `- You are calling ${title} from an async test.describe() block. Only sync ones are supported.`,
].join('\n'));
}
return suite;
diff --git a/tests/playwright-test/basic.spec.ts b/tests/playwright-test/basic.spec.ts
index 13959c2765..62aa216bb1 100644
--- a/tests/playwright-test/basic.spec.ts
+++ b/tests/playwright-test/basic.spec.ts
@@ -411,6 +411,37 @@ test('should support describe() without a title', async ({ runInlineTest }) => {
expect(result.output).toContain('a.spec.ts:6:17 › suite1 › suite2 › my test');
});
+test('should hint at async describe() callbacks when test() is called too late', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'data.json': `{"entries":{"a":{"id":"a","title":"A"},"b":{"id":"b","title":"B"}}}`,
+ 'a.spec.ts': `
+ import { test, expect } from '@playwright/test';
+ test.describe('theme', async () => {
+ const { default: data } = await import('./data.json', { with: { type: 'json' } });
+ for (const entry of Object.values(data.entries))
+ test(entry.title, async () => {});
+ });
+ `,
+ });
+ expect(result.exitCode).toBe(1);
+ expect(result.output).toContain('Playwright Test did not expect test() to be called here.');
+ expect(result.output).toContain('You are calling test() from an async test.describe() block. Only sync ones are supported.');
+});
+
+test('should allow async describe() callback that registers tests synchronously', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'a.spec.ts': `
+ import { test, expect } from '@playwright/test';
+ test.describe('theme', async () => {
+ test('one', async () => {});
+ test('two', async () => {});
+ });
+ `,
+ });
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(2);
+});
+
test('test.{skip,fixme} should define a skipped test', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `