chore: temporarily disable floating promise warning messages (#34957)

This commit is contained in:
Adam Gastineau 2025-02-27 12:45:30 -08:00 committed by GitHub
parent b0ceed51a5
commit 67d6f7f603
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 261 additions and 229 deletions

View file

@ -270,7 +270,8 @@ export class TerminalReporter implements ReporterV2 {
if (full && summary.failuresToPrint.length && !this._omitFailures) if (full && summary.failuresToPrint.length && !this._omitFailures)
this._printFailures(summary.failuresToPrint); this._printFailures(summary.failuresToPrint);
this._printSlowTests(); this._printSlowTests();
this._printWarnings(); // TODO: 1.52: Make warning display prettier
// this._printWarnings();
this._printSummary(summaryMessage); this._printSummary(summaryMessage);
} }

View file

@ -23,6 +23,9 @@ export class FloatingPromiseScope {
* **NOTE:** Returning from an async function wraps the result in a promise, regardless of whether the return value is a promise. This will automatically mark the promise as awaited. Avoid this. * **NOTE:** Returning from an async function wraps the result in a promise, regardless of whether the return value is a promise. This will automatically mark the promise as awaited. Avoid this.
*/ */
wrapPromiseAPIResult<T>(promise: Promise<T>): Promise<T> { wrapPromiseAPIResult<T>(promise: Promise<T>): Promise<T> {
if (process.env.PW_DISABLE_FLOATING_PROMISES_WARNING)
return promise;
const promiseProxy = new Proxy(promise, { const promiseProxy = new Proxy(promise, {
get: (target, prop, receiver) => { get: (target, prop, receiver) => {
if (prop === 'then') { if (prop === 'then') {

View file

@ -324,9 +324,12 @@ export class WorkerMain extends ProcessRunner {
// Create warning if any of the async calls were not awaited in various stages. // Create warning if any of the async calls were not awaited in various stages.
const checkForFloatingPromises = (functionDescription: string) => { const checkForFloatingPromises = (functionDescription: string) => {
if (process.env.PW_DISABLE_FLOATING_PROMISES_WARNING)
return;
if (!testInfo._floatingPromiseScope.hasFloatingPromises()) if (!testInfo._floatingPromiseScope.hasFloatingPromises())
return; 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(); testInfo._floatingPromiseScope.clear();
}; };

View file

@ -14,249 +14,274 @@
* limitations under the License. * limitations under the License.
*/ */
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' });
test.describe('await', () => { // const getWarnings = (report: JSONReport) => report.suites.flatMap(s => s.specs).flatMap(s => s.tests).flatMap(t => t.annotations).filter(a => a.type === 'warning');
test('should not care about non-API promises', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({
'a.test.ts': `
import { test } from '@playwright/test';
test('test', () => {
new Promise(() => {});
});
`
});
expect(exitCode).toBe(0);
expect(stdout).not.toContain(warningSnippet);
});
test('should warn about missing await on expects when failing', async ({ runInlineTest }) => { // test.describe('await', () => {
const { exitCode, stdout } = await runInlineTest({ // test('should not care about non-API promises', async ({ runInlineTest }) => {
'a.test.ts': ` // const { exitCode, report } = await runInlineTest({
import { test, expect } from '@playwright/test'; // 'a.test.ts': `
test('custom test name', async ({ page }) => { // import { test } from '@playwright/test';
expect(page.locator('div')).toHaveText('A', { timeout: 100 }); // test('test', () => {
}); // new Promise(() => {});
` // });
}); // `
expect(exitCode).toBe(1); // });
expect(stdout).toContain(warningSnippet); // expect(exitCode).toBe(0);
expect(stdout).toContain('the test'); // const warnings = getWarnings(report);
expect(stdout).toContain('custom test name'); // expect(warnings.length).toEqual(0);
}); // });
test('should warn about missing await on expects when passing', async ({ runInlineTest }) => { // test('should warn about missing await on expects when failing', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('custom test name', async ({ page }) => {
await page.setContent('<div>A</div>'); // expect(page.locator('div')).toHaveText('A', { timeout: 100 });
expect(page.locator('div')).toHaveText('A'); // });
}); // `
` // });
}); // expect(exitCode).toBe(1);
expect(exitCode).toBe(0); // const warnings = getWarnings(report);
expect(stdout).toContain(warningSnippet); // expect(warnings.length).toEqual(1);
}); // expect(warnings[0].description).toContain(warningSnippet);
// expect(warnings[0].description).toContain('the test');
// });
test('should not warn when not missing await on expects when failing', async ({ runInlineTest }) => { // test('should warn about missing await on expects when passing', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await expect(page.locator('div')).toHaveText('A', { timeout: 100 }); // await page.setContent('<div>A</div>');
}); // expect(page.locator('div')).toHaveText('A');
` // });
}); // `
expect(exitCode).toBe(1); // });
expect(stdout).not.toContain(warningSnippet); // 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 passing', async ({ runInlineTest }) => { // test('should not warn when not missing await on expects when failing', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await page.setContent('<div>A</div>'); // await expect(page.locator('div')).toHaveText('A', { timeout: 100 });
await expect(page.locator('div')).toHaveText('A'); // });
}); // `
` // });
}); // expect(exitCode).toBe(1);
expect(exitCode).toBe(0); // const warnings = getWarnings(report);
expect(stdout).not.toContain(warningSnippet); // expect(warnings.length).toEqual(0);
}); // });
test('should not warn when using then on expects when passing', async ({ runInlineTest }) => { // test('should not warn when not missing await on expects when passing', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await page.setContent('<div>A</div>'); // await page.setContent('<div>A</div>');
expect(page.locator('div')).toHaveText('A').then(() => {}); // await expect(page.locator('div')).toHaveText('A');
}); // });
` // `
}); // });
expect(exitCode).toBe(0); // expect(exitCode).toBe(0);
expect(stdout).not.toContain(warningSnippet); // const warnings = getWarnings(report);
}); // expect(warnings.length).toEqual(0);
// });
test('should warn about missing await on reject', async ({ runInlineTest }) => { // test('should not warn when using then on expects when passing', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
expect(Promise.reject(new Error('foo'))).rejects.toThrow('foo'); // await page.setContent('<div>A</div>');
}); // expect(page.locator('div')).toHaveText('A').then(() => {});
` // });
}); // `
expect(exitCode).toBe(0); // });
expect(stdout).toContain(warningSnippet); // expect(exitCode).toBe(0);
}); // const warnings = getWarnings(report);
// expect(warnings.length).toEqual(0);
// });
test('should warn about missing await on reject.not', async ({ runInlineTest }) => { // test('should warn about missing await on reject', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
expect(Promise.reject(new Error('foo'))).rejects.not.toThrow('foo'); // expect(Promise.reject(new Error('foo'))).rejects.toThrow('foo');
}); // });
` // `
}); // });
expect(exitCode).toBe(1); // expect(exitCode).toBe(0);
expect(stdout).toContain(warningSnippet); // 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 }) => { // test('should warn about missing await on reject.not', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await page.setContent('<div>A</div>'); // expect(Promise.reject(new Error('foo'))).rejects.not.toThrow('foo');
test.step('step', () => {}); // });
await expect(page.locator('div')).toHaveText('A'); // `
}); // });
` // expect(exitCode).toBe(1);
}); // const warnings = getWarnings(report);
expect(exitCode).toBe(0); // expect(warnings.length).toEqual(1);
expect(stdout).toContain(warningSnippet); // expect(warnings[0].description).toContain(warningSnippet);
}); // });
test('should not warn when not missing await on test.step', async ({ runInlineTest }) => { // test('should warn about missing await on test.step', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await page.setContent('<div>A</div>'); // await page.setContent('<div>A</div>');
await test.step('step', () => {}); // test.step('step', () => {});
await expect(page.locator('div')).toHaveText('A'); // await expect(page.locator('div')).toHaveText('A');
}); // });
` // `
}); // });
expect(exitCode).toBe(0); // expect(exitCode).toBe(0);
expect(stdout).not.toContain(warningSnippet); // 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 }) => { // test('should not warn when not missing await on test.step', async ({ runInlineTest }) => {
const { exitCode, stdout } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await page.setContent('<div>A</div>'); // await page.setContent('<div>A</div>');
test.step.skip('step', () => {}); // await test.step('step', () => {});
await expect(page.locator('div')).toHaveText('A'); // await expect(page.locator('div')).toHaveText('A');
}); // });
` // `
}); // });
expect(exitCode).toBe(0); // expect(exitCode).toBe(0);
expect(stdout).toContain(warningSnippet); // const warnings = getWarnings(report);
}); // expect(warnings.length).toEqual(0);
// });
test('traced promise should be instanceof Promise', async ({ runInlineTest }) => { // test('should warn about missing await on test.step.skip', async ({ runInlineTest }) => {
const { exitCode } = await runInlineTest({ // const { exitCode, report } = await runInlineTest({
'a.test.ts': ` // 'a.test.ts': `
import { test, expect } from '@playwright/test'; // import { test, expect } from '@playwright/test';
test('test', async ({ page }) => { // test('test', async ({ page }) => {
await page.setContent('<div>A</div>'); // await page.setContent('<div>A</div>');
const expectPromise = expect(page.locator('div')).toHaveText('A'); // test.step.skip('step', () => {});
expect(expectPromise instanceof Promise).toBeTruthy(); // await expect(page.locator('div')).toHaveText('A');
}); // });
` // `
}); // });
expect(exitCode).toBe(0); // 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 in before hooks', async ({ runInlineTest }) => { // test('traced promise should be instanceof Promise', async ({ runInlineTest }) => {
const group = ['beforeAll', 'beforeEach']; // const { exitCode } = await runInlineTest({
for (const hook of group) { // 'a.test.ts': `
await test.step(hook, async () => { // import { test, expect } from '@playwright/test';
const { exitCode, stdout } = await runInlineTest({ // test('test', async ({ page }) => {
'a.test.ts': ` // await page.setContent('<div>A</div>');
import { test, expect } from '@playwright/test'; // const expectPromise = expect(page.locator('div')).toHaveText('A');
let page; // expect(expectPromise instanceof Promise).toBeTruthy();
test.${hook}(async ({ browser }) => { // });
page = await browser.newPage(); // `
await page.setContent('<div>A</div>'); // });
expect(page.locator('div')).toHaveText('A'); // expect(exitCode).toBe(0);
}); // });
test('test ${hook}', async () => {
await expect(page.locator('div')).toBeVisible();
});
`
});
expect(exitCode).toBe(0); // test('should warn about missing await in before hooks', async ({ runInlineTest }) => {
expect(stdout).toContain(warningSnippet); // const group = ['beforeAll', 'beforeEach'];
expect(stdout).toContain(`${group[0]}/${group[1]} hooks`); // 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('<div>A</div>');
// expect(page.locator('div')).toHaveText('A');
// });
// test('test ${hook}', async () => {
// await expect(page.locator('div')).toBeVisible();
// });
// `
// });
test.describe('should warn about missing await in after hooks', () => { // expect(exitCode).toBe(0);
const group = ['afterAll', 'afterEach']; // const warnings = getWarnings(report);
for (const hook of group) { // expect(warnings.length).toEqual(1);
test(hook, async ({ runInlineTest }) => { // expect(warnings[0].description).toContain(warningSnippet);
const { exitCode, stdout } = await runInlineTest({ // expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`);
'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); // test.describe('should warn about missing await in after hooks', () => {
expect(stdout).toContain(warningSnippet); // const group = ['afterAll', 'afterEach'];
expect(stdout).toContain(`${group[0]}/${group[1]} hooks`); // 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('should warn about missing await across hooks and test', async ({ runInlineTest }) => { // expect(exitCode).toBe(0);
const { exitCode, stdout } = await runInlineTest({ // const warnings = getWarnings(report);
'a.test.ts': ` // expect(warnings.length).toEqual(1);
import { test, expect } from '@playwright/test'; // expect(warnings[0].description).toContain(warningSnippet);
test.beforeAll(async () => { // expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`);
expect(Promise.resolve()).resolves.toBe(undefined); // });
}); // }
test('test', async () => { // });
expect(Promise.resolve()).resolves.toBe(undefined);
}); // test('should warn about missing await across hooks and test', async ({ runInlineTest }) => {
test.afterEach(async () => { // const { exitCode, report } = await runInlineTest({
expect(Promise.resolve()).resolves.toBe(undefined); // 'a.test.ts': `
}); // import { test, expect } from '@playwright/test';
` // test.beforeAll(async () => {
}); // expect(Promise.resolve()).resolves.toBe(undefined);
expect(exitCode).toBe(0); // });
expect(stdout).toContain(`${warningSnippet} by the end of beforeAll/beforeEach hooks.`); // test('test', async () => {
expect(stdout).toContain(`${warningSnippet} by the end of the test.`); // expect(Promise.resolve()).resolves.toBe(undefined);
expect(stdout).toContain(`${warningSnippet} by the end of afterAll/afterEach hooks.`); // });
}); // 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.`);
// });
// });