From d189d9a04476e08797c8660dc94867dd87d87726 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Sat, 6 Jul 2024 00:43:43 +0700 Subject: [PATCH] fix(allure-jest): missing hooks in some tests beforeAll/afterAll hooks were missing for tests of sub-suites --- .../allure-jest/src/environmentFactory.ts | 3 +- packages/allure-jest/test/spec/hooks.test.ts | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/allure-jest/src/environmentFactory.ts b/packages/allure-jest/src/environmentFactory.ts index dbc990a6d..67c6b9586 100644 --- a/packages/allure-jest/src/environmentFactory.ts +++ b/packages/allure-jest/src/environmentFactory.ts @@ -191,7 +191,6 @@ const createJestEnvironment = (Base: T): T => return; } - const scopeUuid = last(this.runContext.scopes); const threadLabel = ALLURE_THREAD_NAME || JEST_WORKER_ID || process.pid.toString(); const hostLabel = ALLURE_HOST_NAME || hostname; const packageLabel = dirname(this.testPath).split(sep).join("."); @@ -216,7 +215,7 @@ const createJestEnvironment = (Base: T): T => ...getEnvironmentLabels(), ], }, - [scopeUuid], + this.runContext.scopes, ); this.runtime.updateTest(testUuid, (result) => { diff --git a/packages/allure-jest/test/spec/hooks.test.ts b/packages/allure-jest/test/spec/hooks.test.ts index 1e918dcf8..2fa880a39 100644 --- a/packages/allure-jest/test/spec/hooks.test.ts +++ b/packages/allure-jest/test/spec/hooks.test.ts @@ -111,6 +111,35 @@ it("reports before and after each hooks", async () => { ); }); +it("should report beforeAll/afterAll for tests in sub-suites", async () => { + const { tests, groups } = await runJestInlineTest({ + "sample.test.js": ` + beforeAll(() => {}); + afterAll(() => {}); + + describe("", () => { + it("foo", () => {}); + }); + `, + }); + + const [{ uuid: testUuid }] = tests; + + expect(groups).toHaveLength(2); + expect(groups).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + name: "beforeAll", + children: [testUuid], + }), + expect.objectContaining({ + name: "afterAll", + children: [testUuid], + }), + ]), + ); +}); + it("reports failed hooks", async () => { const { tests, groups } = await runJestInlineTest({ "sample.test.js": `