fix(runner): do not override trace files in afterAll (#14529)

This commit is contained in:
Yury Semikhatsky 2022-05-31 15:21:51 -07:00 committed by GitHub
parent 947e6f58db
commit 2bcdf68ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -393,8 +393,11 @@ export class WorkerRunner extends EventEmitter {
// Run "afterAll" hooks for suites that are not shared with the next test. // Run "afterAll" hooks for suites that are not shared with the next test.
const nextSuites = new Set(getSuites(nextTest)); const nextSuites = new Set(getSuites(nextTest));
// In case of failure the worker will be stopped and we have to make sure that afterAll
// hooks run before test fixtures teardown.
const isFailure = testInfo.status !== 'skipped' && testInfo.status !== testInfo.expectedStatus;
for (const suite of reversedSuites) { for (const suite of reversedSuites) {
if (!nextSuites.has(suite)) { if (!nextSuites.has(suite) || isFailure) {
const afterAllError = await this._runAfterAllHooksForSuite(suite, testInfo); const afterAllError = await this._runAfterAllHooksForSuite(suite, testInfo);
firstAfterHooksError = firstAfterHooksError || afterAllError; firstAfterHooksError = firstAfterHooksError || afterAllError;
} }

View File

@ -211,6 +211,37 @@ test('should work in serial mode', async ({ runInlineTest }, testInfo) => {
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-serial-fails', 'trace.zip'))).toBeTruthy(); expect(fs.existsSync(testInfo.outputPath('test-results', 'a-serial-fails', 'trace.zip'))).toBeTruthy();
}); });
test('should not override trace file in afterAll', async ({ runInlineTest, server }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { trace: 'retain-on-failure' } };
`,
'a.spec.ts': `
const { test } = pwt;
test('test 1', async ({ page }) => {
await page.goto('about:blank');
throw 'oh no!';
});
// Another test in the same file to affect after hooks order.
test('test 2', async ({}) => {
});
test.afterAll(async ({ request }) => {
await request.get('${server.EMPTY_PAGE}');
});
`,
}, { workers: 1 });
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(1);
expect(result.failed).toBe(1);
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBeTruthy();
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace-1.zip'))).toBeTruthy();
});
async function parseTrace(file: string): Promise<Map<string, Buffer>> { async function parseTrace(file: string): Promise<Map<string, Buffer>> {
const zipFS = new ZipFileSystem(file); const zipFS = new ZipFileSystem(file);
const resources = new Map<string, Buffer>(); const resources = new Map<string, Buffer>();