Skip to content

Commit

Permalink
fix(allure-jest): missing hooks in some tests
Browse files Browse the repository at this point in the history
beforeAll/afterAll hooks were missing for tests of sub-suites
  • Loading branch information
delatrie committed Jul 8, 2024
1 parent 1b3c982 commit d189d9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/allure-jest/src/environmentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(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(".");
Expand All @@ -216,7 +215,7 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
...getEnvironmentLabels(),
],
},
[scopeUuid],
this.runContext.scopes,
);

this.runtime.updateTest(testUuid, (result) => {
Expand Down
29 changes: 29 additions & 0 deletions packages/allure-jest/test/spec/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": `
Expand Down

0 comments on commit d189d9a

Please sign in to comment.