Fixed warnings tests to check for actual annotations
This commit is contained in:
parent
cb56e78e9f
commit
52a23d3fbe
|
|
@ -14,15 +14,18 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { JSONReport } from 'packages/playwright-test/reporter';
|
||||||
import { test, expect } from './playwright-test-fixtures';
|
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');
|
||||||
|
|
||||||
test.describe('await', () => {
|
test.describe('await', () => {
|
||||||
test('should not care about non-API promises', async ({ runInlineTest }) => {
|
test('should not care about non-API promises', async ({ runInlineTest }) => {
|
||||||
const { exitCode, stdout } = await runInlineTest({
|
const { exitCode, report } = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
import { test } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
test('test', () => {
|
test('test', () => {
|
||||||
|
|
@ -31,11 +34,12 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
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 expects when failing', 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('custom test name', async ({ page }) => {
|
test('custom test name', async ({ page }) => {
|
||||||
|
|
@ -44,13 +48,14 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(1);
|
expect(exitCode).toBe(1);
|
||||||
expect(stdout).toContain(warningSnippet);
|
const warnings = getWarnings(report);
|
||||||
expect(stdout).toContain('the test');
|
expect(warnings.length).toEqual(1);
|
||||||
expect(stdout).toContain('custom test name');
|
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 }) => {
|
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 }) => {
|
||||||
|
|
@ -60,11 +65,13 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(0);
|
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 not warn when not missing await on expects when failing', 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 }) => {
|
||||||
|
|
@ -73,11 +80,12 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(1);
|
expect(exitCode).toBe(1);
|
||||||
expect(stdout).not.toContain(warningSnippet);
|
const warnings = getWarnings(report);
|
||||||
|
expect(warnings.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 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 }) => {
|
||||||
|
|
@ -87,11 +95,12 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
expect(stdout).not.toContain(warningSnippet);
|
const warnings = getWarnings(report);
|
||||||
|
expect(warnings.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not warn when using then on expects when passing', 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 }) => {
|
||||||
|
|
@ -101,11 +110,12 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
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 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 }) => {
|
||||||
|
|
@ -114,11 +124,13 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(0);
|
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 reject.not', 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 }) => {
|
||||||
|
|
@ -127,11 +139,13 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(1);
|
expect(exitCode).toBe(1);
|
||||||
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 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 }) => {
|
||||||
|
|
@ -142,11 +156,13 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(0);
|
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 not warn when not missing await on test.step', 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 }) => {
|
||||||
|
|
@ -157,11 +173,12 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
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 test.step.skip', async ({ runInlineTest }) => {
|
test('should warn about missing await on test.step.skip', 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 }) => {
|
||||||
|
|
@ -172,7 +189,9 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
expect(stdout).toContain(warningSnippet);
|
const warnings = getWarnings(report);
|
||||||
|
expect(warnings.length).toEqual(1);
|
||||||
|
expect(warnings[0].description).toContain(warningSnippet);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('traced promise should be instanceof Promise', async ({ runInlineTest }) => {
|
test('traced promise should be instanceof Promise', async ({ runInlineTest }) => {
|
||||||
|
|
@ -193,7 +212,7 @@ test.describe('await', () => {
|
||||||
const group = ['beforeAll', 'beforeEach'];
|
const group = ['beforeAll', 'beforeEach'];
|
||||||
for (const hook of group) {
|
for (const hook of group) {
|
||||||
await test.step(hook, async () => {
|
await test.step(hook, async () => {
|
||||||
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';
|
||||||
let page;
|
let page;
|
||||||
|
|
@ -209,8 +228,10 @@ test.describe('await', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
expect(stdout).toContain(warningSnippet);
|
const warnings = getWarnings(report);
|
||||||
expect(stdout).toContain(`${group[0]}/${group[1]} hooks`);
|
expect(warnings.length).toEqual(1);
|
||||||
|
expect(warnings[0].description).toContain(warningSnippet);
|
||||||
|
expect(warnings[0].description).toContain(`${group[0]}/${group[1]} hooks`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -219,7 +240,7 @@ test.describe('await', () => {
|
||||||
const group = ['afterAll', 'afterEach'];
|
const group = ['afterAll', 'afterEach'];
|
||||||
for (const hook of group) {
|
for (const hook of group) {
|
||||||
test(hook, async ({ runInlineTest }) => {
|
test(hook, 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';
|
||||||
let page;
|
let page;
|
||||||
|
|
@ -233,14 +254,16 @@ test.describe('await', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
expect(stdout).toContain(warningSnippet);
|
const warnings = getWarnings(report);
|
||||||
expect(stdout).toContain(`${group[0]}/${group[1]} hooks`);
|
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 }) => {
|
test('should warn about missing await across hooks and test', 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.beforeAll(async () => {
|
test.beforeAll(async () => {
|
||||||
|
|
@ -255,8 +278,10 @@ test.describe('await', () => {
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
expect(exitCode).toBe(0);
|
expect(exitCode).toBe(0);
|
||||||
expect(stdout).toContain(`${warningSnippet} by the end of beforeAll/beforeEach hooks.`);
|
const warnings = getWarnings(report);
|
||||||
expect(stdout).toContain(`${warningSnippet} by the end of the test.`);
|
expect(warnings.length).toEqual(3);
|
||||||
expect(stdout).toContain(`${warningSnippet} by the end of afterAll/afterEach hooks.`);
|
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.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue