From ee2748eb15c49faa11ef474b950e50e005134cb2 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Thu, 27 Feb 2025 12:04:34 -0800 Subject: [PATCH] Disabled annotation output --- packages/playwright/src/worker/workerMain.ts | 3 +- tests/playwright-test/warnings.spec.ts | 502 +++++++++---------- 2 files changed, 253 insertions(+), 252 deletions(-) diff --git a/packages/playwright/src/worker/workerMain.ts b/packages/playwright/src/worker/workerMain.ts index 1c3a006ccd..126d3c8052 100644 --- a/packages/playwright/src/worker/workerMain.ts +++ b/packages/playwright/src/worker/workerMain.ts @@ -328,7 +328,8 @@ export class WorkerMain extends ProcessRunner { return; if (!testInfo._floatingPromiseScope.hasFloatingPromises()) return; - testInfo.annotations.push({ type: 'warning', description: `Some async calls were not awaited by the end of ${functionDescription}. This can cause flakiness.` }); + // TODO: 1.52: Actually build annotations + // testInfo.annotations.push({ type: 'warning', description: `Some async calls were not awaited by the end of ${functionDescription}. This can cause flakiness.` }); testInfo._floatingPromiseScope.clear(); }; diff --git a/tests/playwright-test/warnings.spec.ts b/tests/playwright-test/warnings.spec.ts index ac69ac7d31..2734c9593e 100644 --- a/tests/playwright-test/warnings.spec.ts +++ b/tests/playwright-test/warnings.spec.ts @@ -14,274 +14,274 @@ * limitations under the License. */ -import { JSONReport } from 'packages/playwright-test/reporter'; -import { test, expect } from './playwright-test-fixtures'; +// import { JSONReport } from 'packages/playwright-test/reporter'; +// import { test, expect } from './playwright-test-fixtures'; -const warningSnippet = 'Some async calls were not awaited'; +// const warningSnippet = 'Some async calls were not awaited'; -test.describe.configure({ mode: 'parallel' }); +// test.describe.configure({ mode: 'parallel' }); -const getWarnings = (report: JSONReport) => report.suites.flatMap(s => s.specs).flatMap(s => s.tests).flatMap(t => t.annotations).filter(a => a.type === 'warning'); +// const getWarnings = (report: JSONReport) => report.suites.flatMap(s => s.specs).flatMap(s => s.tests).flatMap(t => t.annotations).filter(a => a.type === 'warning'); -test.describe('await', () => { - test('should not care about non-API promises', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test } from '@playwright/test'; - test('test', () => { - new Promise(() => {}); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(0); - }); +// test.describe('await', () => { +// test('should not care about non-API promises', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test } from '@playwright/test'; +// test('test', () => { +// new Promise(() => {}); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(0); +// }); - test('should warn about missing await on expects when failing', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('custom test name', async ({ page }) => { - expect(page.locator('div')).toHaveText('A', { timeout: 100 }); - }); - ` - }); - expect(exitCode).toBe(1); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - expect(warnings[0].description).toContain('the test'); - }); +// test('should warn about missing await on expects when failing', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('custom test name', async ({ page }) => { +// expect(page.locator('div')).toHaveText('A', { timeout: 100 }); +// }); +// ` +// }); +// expect(exitCode).toBe(1); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// expect(warnings[0].description).toContain('the test'); +// }); - test('should warn about missing await on expects when passing', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - expect(page.locator('div')).toHaveText('A'); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - }); +// test('should warn about missing await on expects when passing', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// expect(page.locator('div')).toHaveText('A'); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// }); - test('should not warn when not missing await on expects when failing', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await expect(page.locator('div')).toHaveText('A', { timeout: 100 }); - }); - ` - }); - expect(exitCode).toBe(1); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(0); - }); +// test('should not warn when not missing await on expects when failing', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await expect(page.locator('div')).toHaveText('A', { timeout: 100 }); +// }); +// ` +// }); +// expect(exitCode).toBe(1); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(0); +// }); - test('should not warn when not missing await on expects when passing', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - await expect(page.locator('div')).toHaveText('A'); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(0); - }); +// test('should not warn when not missing await on expects when passing', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// await expect(page.locator('div')).toHaveText('A'); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(0); +// }); - test('should not warn when using then on expects when passing', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - expect(page.locator('div')).toHaveText('A').then(() => {}); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(0); - }); +// test('should not warn when using then on expects when passing', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// expect(page.locator('div')).toHaveText('A').then(() => {}); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(0); +// }); - test('should warn about missing await on reject', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - expect(Promise.reject(new Error('foo'))).rejects.toThrow('foo'); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - }); +// test('should warn about missing await on reject', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// expect(Promise.reject(new Error('foo'))).rejects.toThrow('foo'); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// }); - test('should warn about missing await on reject.not', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - expect(Promise.reject(new Error('foo'))).rejects.not.toThrow('foo'); - }); - ` - }); - expect(exitCode).toBe(1); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - }); +// test('should warn about missing await on reject.not', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// expect(Promise.reject(new Error('foo'))).rejects.not.toThrow('foo'); +// }); +// ` +// }); +// expect(exitCode).toBe(1); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// }); - test('should warn about missing await on test.step', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - test.step('step', () => {}); - await expect(page.locator('div')).toHaveText('A'); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - }); +// test('should warn about missing await on test.step', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// test.step('step', () => {}); +// await expect(page.locator('div')).toHaveText('A'); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// }); - test('should not warn when not missing await on test.step', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - await test.step('step', () => {}); - await expect(page.locator('div')).toHaveText('A'); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(0); - }); +// test('should not warn when not missing await on test.step', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// await test.step('step', () => {}); +// await expect(page.locator('div')).toHaveText('A'); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(0); +// }); - test('should warn about missing await on test.step.skip', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - test.step.skip('step', () => {}); - await expect(page.locator('div')).toHaveText('A'); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - }); +// test('should warn about missing await on test.step.skip', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// test.step.skip('step', () => {}); +// await expect(page.locator('div')).toHaveText('A'); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// }); - test('traced promise should be instanceof Promise', async ({ runInlineTest }) => { - const { exitCode } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test('test', async ({ page }) => { - await page.setContent('
A
'); - const expectPromise = expect(page.locator('div')).toHaveText('A'); - expect(expectPromise instanceof Promise).toBeTruthy(); - }); - ` - }); - expect(exitCode).toBe(0); - }); +// test('traced promise should be instanceof Promise', async ({ runInlineTest }) => { +// const { exitCode } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test('test', async ({ page }) => { +// await page.setContent('
A
'); +// const expectPromise = expect(page.locator('div')).toHaveText('A'); +// expect(expectPromise instanceof Promise).toBeTruthy(); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// }); - test('should warn about missing await in before hooks', async ({ runInlineTest }) => { - const group = ['beforeAll', 'beforeEach']; - for (const hook of group) { - await test.step(hook, async () => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - let page; - test.${hook}(async ({ browser }) => { - page = await browser.newPage(); - await page.setContent('
A
'); - expect(page.locator('div')).toHaveText('A'); - }); - test('test ${hook}', async () => { - await expect(page.locator('div')).toBeVisible(); - }); - ` - }); +// test('should warn about missing await in before hooks', async ({ runInlineTest }) => { +// const group = ['beforeAll', 'beforeEach']; +// for (const hook of group) { +// await test.step(hook, async () => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// let page; +// test.${hook}(async ({ browser }) => { +// page = await browser.newPage(); +// await page.setContent('
A
'); +// expect(page.locator('div')).toHaveText('A'); +// }); +// test('test ${hook}', async () => { +// await expect(page.locator('div')).toBeVisible(); +// }); +// ` +// }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`); - }); - } - }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`); +// }); +// } +// }); - test.describe('should warn about missing await in after hooks', () => { - const group = ['afterAll', 'afterEach']; - for (const hook of group) { - test(hook, async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - let page; - test('test ${hook}', async ({ browser }) => { - await expect(Promise.resolve()).resolves.toBe(undefined); - }); - test.${hook}(async () => { - expect(Promise.resolve()).resolves.toBe(undefined); - }); - ` - }); +// test.describe('should warn about missing await in after hooks', () => { +// const group = ['afterAll', 'afterEach']; +// for (const hook of group) { +// test(hook, async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// let page; +// test('test ${hook}', async ({ browser }) => { +// await expect(Promise.resolve()).resolves.toBe(undefined); +// }); +// test.${hook}(async () => { +// expect(Promise.resolve()).resolves.toBe(undefined); +// }); +// ` +// }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(1); - expect(warnings[0].description).toContain(warningSnippet); - expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`); - }); - } - }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(1); +// expect(warnings[0].description).toContain(warningSnippet); +// expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`); +// }); +// } +// }); - test('should warn about missing await across hooks and test', async ({ runInlineTest }) => { - const { exitCode, report } = await runInlineTest({ - 'a.test.ts': ` - import { test, expect } from '@playwright/test'; - test.beforeAll(async () => { - expect(Promise.resolve()).resolves.toBe(undefined); - }); - test('test', async () => { - expect(Promise.resolve()).resolves.toBe(undefined); - }); - test.afterEach(async () => { - expect(Promise.resolve()).resolves.toBe(undefined); - }); - ` - }); - expect(exitCode).toBe(0); - const warnings = getWarnings(report); - expect(warnings.length).toEqual(3); - expect(warnings[0].description).toContain(`${warningSnippet} by the end of beforeAll/beforeEach hooks.`); - expect(warnings[1].description).toContain(`${warningSnippet} by the end of the test.`); - expect(warnings[2].description).toContain(`${warningSnippet} by the end of afterAll/afterEach hooks.`); - }); -}); +// test('should warn about missing await across hooks and test', async ({ runInlineTest }) => { +// const { exitCode, report } = await runInlineTest({ +// 'a.test.ts': ` +// import { test, expect } from '@playwright/test'; +// test.beforeAll(async () => { +// expect(Promise.resolve()).resolves.toBe(undefined); +// }); +// test('test', async () => { +// expect(Promise.resolve()).resolves.toBe(undefined); +// }); +// test.afterEach(async () => { +// expect(Promise.resolve()).resolves.toBe(undefined); +// }); +// ` +// }); +// expect(exitCode).toBe(0); +// const warnings = getWarnings(report); +// expect(warnings.length).toEqual(3); +// expect(warnings[0].description).toContain(`${warningSnippet} by the end of beforeAll/beforeEach hooks.`); +// expect(warnings[1].description).toContain(`${warningSnippet} by the end of the test.`); +// expect(warnings[2].description).toContain(`${warningSnippet} by the end of afterAll/afterEach hooks.`); +// }); +// });