fix(test runner): hide beforeAll/afterAll hooks from the reporter api (#11306)

This api is not ready yet.
This commit is contained in:
Dmitry Gozman 2022-01-10 12:09:51 -08:00 committed by GitHub
parent 855f951ed8
commit 14fd837e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 11 additions and 98 deletions

View file

@ -24,11 +24,6 @@ Reporter is given a root suite in the [`method: Reporter.onBegin`] method.
Returns the list of all test cases in this suite and its descendants, as opposite to [`property: Suite.tests`].
## property: Suite.hooks
- type: <[Array]<[TestCase]>>
`beforeAll` and `afterAll` hooks in the suite. Note that other hooks such as `beforeEach` and `afterEach` are reported as the steps within the test.
## property: Suite.location
- type: <[void]|[Location]>

View file

@ -184,7 +184,8 @@ export class Dispatcher {
data.resultByWorkerIndex.set(worker.workerIndex, { result, stepStack: new Set(), steps: new Map() });
result.workerIndex = worker.workerIndex;
result.startTime = new Date(params.startWallTime);
this._reporter.onTestBegin?.(data.test, result);
if (data.test._type === 'test')
this._reporter.onTestBegin?.(data.test, result);
};
worker.addListener('testBegin', onTestBegin);
@ -308,7 +309,8 @@ export class Dispatcher {
result = runData.result;
} else {
result = data.test._appendTestResult();
this._reporter.onTestBegin?.(test, result);
if (test._type === 'test')
this._reporter.onTestBegin?.(test, result);
}
result.error = params.fatalError;
result.status = first ? 'failed' : 'skipped';
@ -354,9 +356,9 @@ export class Dispatcher {
return true;
// Emulate a "skipped" run, and drop this test from remaining.
const data = this._testById.get(test._id)!;
const result = data.test._appendTestResult();
this._reporter.onTestBegin?.(test, result);
const result = test._appendTestResult();
if (test._type === 'test')
this._reporter.onTestBegin?.(test, result);
result.status = 'skipped';
this._reportTestEnd(test, result);
return false;
@ -440,7 +442,8 @@ export class Dispatcher {
private _reportTestEnd(test: TestCase, result: TestResult) {
if (test._type === 'test' && result.status !== 'skipped' && result.status !== test.expectedStatus)
++this._failureCount;
this._reporter.onTestEnd?.(test, result);
if (test._type === 'test')
this._reporter.onTestEnd?.(test, result);
const maxFailures = this._loader.fullConfig().maxFailures;
if (maxFailures && this._failureCount === maxFailures)
this.stop().catch(e => {});

View file

@ -42,7 +42,6 @@ export interface JSONReportSuite {
column: number;
line: number;
specs: JSONReportSpec[];
hooks: JSONReportSpec[];
suites?: JSONReportSuite[];
}
export interface JSONReportSpec {
@ -208,7 +207,6 @@ class JSONReporter implements Reporter {
title: suite.title,
...this._relativeLocation(suite.location),
specs: suite.tests.map(test => this._serializeTestSpec(test)),
hooks: suite.hooks.map(test => this._serializeTestSpec(test)),
suites: suites.length ? suites : undefined,
};
}

View file

@ -190,7 +190,7 @@ class RawReporter {
location,
suites: suite.suites.map(s => this._serializeSuite(s)),
tests: suite.tests.map(t => this._serializeTest(t, fileId)),
hooks: suite.hooks.map(t => this._serializeTest(t, fileId)),
hooks: [],
};
}

View file

@ -84,11 +84,6 @@ export interface Suite {
* listed in the child [suite.suites](https://playwright.dev/docs/api/class-suite#suite-suites).
*/
tests: TestCase[];
/**
* `beforeAll` and `afterAll` hooks in the suite. Note that other hooks such as `beforeEach` and `afterEach` are reported
* as the steps within the test.
*/
hooks: TestCase[];
/**
* Returns a list of titles from the root down to this suite.
*/

View file

@ -587,28 +587,3 @@ test('should not hang and report results when worker process suddenly exits duri
expect(stripAscii(result.output)).toContain('[1/1] a.spec.js:6:7 passed');
expect(stripAscii(result.output)).toContain('[1/1] a.spec.js:7:12 afterAll');
});
test('same beforeAll running in parallel should be reported correctly', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.js': `
const { test } = pwt;
test.describe.parallel('', () => {
test.beforeAll(async () => {
await new Promise(f => setTimeout(f, 3000));
});
test('test1', () => {});
test('test2', () => {});
});
`
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(2);
const hook = result.report.suites[0].suites[0].hooks[0];
expect(hook.title).toBe('beforeAll');
expect(hook.tests.length).toBe(1);
expect(hook.tests[0].results.length).toBe(2);
expect(hook.tests[0].results[0].status).toBe('passed');
expect(hook.tests[0].results[1].status).toBe('passed');
const workers = [hook.tests[0].results[0].workerIndex, hook.tests[0].results[1].workerIndex];
expect(workers.sort()).toEqual([0, 1]);
});

View file

@ -325,45 +325,6 @@ test('should render annotations', async ({ runInlineTest, page, showReport }) =>
await expect(page.locator('.test-case-annotation')).toHaveText('skip: I am not interested in this test');
});
test('should render beforeAll/afterAll hooks', async ({ runInlineTest, page, showReport }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test.use({ trace: 'on' });
test.beforeAll(async () => {
});
test.afterAll(async ({ browser }) => {
const page = await browser.newPage();
await page.close();
await test.step('after step', () => {
throw new Error('oh!');
});
});
test('test', async ({}) => {
});
`,
}, { reporter: 'dot,html' });
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(1);
await showReport();
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('1');
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('1');
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('0');
await expect(page.locator('.subnav-item:has-text("Flaky") .counter')).toHaveText('0');
await expect(page.locator('.subnav-item:has-text("Skipped") .counter')).toHaveText('0');
await expect(page.locator('text=beforeAll')).toBeVisible();
await expect(page.locator('.test-file-test:has-text("beforeAll") svg.color-icon-success')).toHaveCount(1);
await expect(page.locator('text=afterAll')).toBeVisible();
await expect(page.locator('.test-file-test:has-text("afterAll") svg.color-text-danger')).toHaveCount(1);
await page.click('text=afterAll');
await expect(page.locator('.tree-item:has-text("after step") svg.color-text-danger')).toHaveCount(1);
await expect(page.locator('img')).toBeVisible();
});
test('should render text attachments as text', async ({ runInlineTest, page, showReport }) => {
const result = await runInlineTest({
'a.test.js': `

View file

@ -162,7 +162,7 @@ test('should retry beforeAll failure', async ({ runInlineTest }) => {
expect(result.passed).toBe(0);
expect(result.failed).toBe(1);
expect(result.skipped).toBe(1);
expect(stripAscii(result.output).split('\n')[2]).toBe('××°F×°FF°');
expect(stripAscii(result.output).split('\n')[2]).toBe('×°×°F°');
expect(result.output).toContain('BeforeAll is bugged!');
});

View file

@ -61,19 +61,6 @@ test('should get stdio from worker fixture teardown', async ({ runInlineTest })
]);
});
test('should get stdio from beforeAll and afterAll', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.js': `
const { test } = pwt;
test.beforeAll(() => console.log('before'));
test('is a test', () => {});
test.afterAll(() => console.error('after'));
`
});
expect(result.report.suites[0].hooks[0].tests[0].results[0].stdout).toEqual([{ text: 'before\n' }]);
expect(result.report.suites[0].hooks[1].tests[0].results[0].stderr).toEqual([{ text: 'after\n' }]);
});
test('should ignore stdio when quiet', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `

View file

@ -29,7 +29,6 @@ export interface Suite {
location?: Location;
suites: Suite[];
tests: TestCase[];
hooks: TestCase[];
titlePath(): string[];
allTests(): TestCase[];
project(): FullProject | undefined;