Skip to content

Commit

Permalink
fix(allure-jest): duplicated each type fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
delatrie committed Jul 8, 2024
1 parent e217039 commit 7534830
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
29 changes: 23 additions & 6 deletions packages/allure-jest/src/environmentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
case "test_start":
this.#handleTestStart(event.test);
break;
case "test_done":
this.#handleTestDone();
break;
case "test_todo":
this.#handleTestTodo(event.test);
break;
Expand Down Expand Up @@ -124,15 +127,11 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
}

#handleSuiteStart() {
const scopeUuid = this.runtime.startScope();

this.runContext.scopes.push(scopeUuid);
this.#startScope();
}

#handleSuiteEnd() {
const scopeUuid = this.runContext.scopes.pop()!;

this.runtime.writeScope(scopeUuid);
this.#stopScope();
}

#handleHookStart(hook: Circus.Hook) {
Expand Down Expand Up @@ -194,6 +193,8 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
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(".");

this.#startScope();
const testUuid = this.runtime.startTest(
{
name: test.name,
Expand Down Expand Up @@ -256,6 +257,22 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
});
}

#handleTestDone() {
this.#stopScope();
}

#startScope() {
const scopeUuid = this.runtime.startScope();

this.runContext.scopes.push(scopeUuid);
}

#stopScope() {
const scopeUuid = this.runContext.scopes.pop()!;

this.runtime.writeScope(scopeUuid);
}

#handleTestPass(test: Circus.TestEntry) {
const testUuid = this.runContext.executables.pop();

Expand Down
36 changes: 36 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,42 @@ it("reports before and after each hooks", async () => {
);
});

it("should report one beforeEach/afterEach per test", async () => {
const { tests, groups } = await runJestInlineTest({
"sample.test.js": `
beforeEach(() => {});
afterEach(() => {});
it("foo", () => {});
it("bar", () => {});
`,
});

const [{ uuid: test1Uuid }, { uuid: test2Uuid }] = tests;

expect(groups).toHaveLength(4);
expect(groups).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "beforeEach",
children: [test1Uuid],
}),
expect.objectContaining({
name: "beforeEach",
children: [test2Uuid],
}),
expect.objectContaining({
name: "afterEach",
children: [test1Uuid],
}),
expect.objectContaining({
name: "afterEach",
children: [test2Uuid],
}),
]),
);
});

it("should report beforeAll/afterAll for tests in sub-suites", async () => {
const { tests, groups } = await runJestInlineTest({
"sample.test.js": `
Expand Down

0 comments on commit 7534830

Please sign in to comment.