Skip to content

Commit

Permalink
fix(allure-mocha): fix test result overwritten when a test is skipped…
Browse files Browse the repository at this point in the history
… dynamically (fixes #457, via #1015)
  • Loading branch information
delatrie authored Jun 25, 2024
1 parent 0cea166 commit b60dad0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/allure-mocha/src/AllureMochaReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export class AllureMochaReporter extends Mocha.reporters.Base {

private onPending = (test: Mocha.Test) => {
if (isIncludedInTestRun(test)) {
this.onTest(test);
if (!this.runtime.hasTest()) {
this.onTest(test);
}
this.runtime.updateTest((r) => {
r.status = Status.SKIPPED;
r.statusDetails = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// cjs: const { it } = require("mocha");
// cjs: const { tag } = require("allure-js-commons");
// esm: import { it } from "mocha";
// esm: import { tag } from "allure-js-commons";

it("a skipped test with a tag", async function () {
await tag("foo");
this.skip();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// cjs: const { it } = require("mocha");
// cjs: const { allure } = require("allure-mocha/runtime");
// esm: import { it } from "mocha";
// esm: import { allure } from "allure-mocha/runtime";

it("a skipped test with a tag", function () {
allure.tag("foo");
this.skip();
});
16 changes: 16 additions & 0 deletions packages/allure-mocha/test/spec/defects/dynamicSkip.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, it } from "vitest";
import { issue } from "allure-js-commons";
import { runMochaInlineTest } from "../../utils.js";

it("shouldn't overwrite the result of a dynamically skipped test", async () => {
await issue("457");

const { tests } = await runMochaInlineTest(["labels", "skippedAtRuntime"], ["legacy", "labels", "skippedAtRuntime"]);

expect(tests).toHaveLength(2);
for (const test of tests) {
expect(test).toMatchObject({
labels: expect.arrayContaining([expect.objectContaining({ name: "tag", value: "foo" })]),
});
}
});
1 change: 1 addition & 0 deletions packages/allure-mocha/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ abstract class AllureMochaTestRunner {
// TODO parameter should accept any type
await parameter("parallel", `${RUN_IN_PARALLEL}`);
await parameter("module", SPEC_FORMAT);
await parameter("runner", RUNNER);

const testDir = path.join(this.runResultsDir, randomUUID());

Expand Down
11 changes: 10 additions & 1 deletion packages/allure-mocha/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ export default defineConfig({
hookTimeout: 25000,
globalSetup: ["./test/setup.ts"],
setupFiles: ["./vitest-setup.ts"],
reporters: ["default", ["allure-vitest/reporter", { resultsDir: "./out/allure-results" }]],
reporters: [
"default",
[
"allure-vitest/reporter",
{
resultsDir: "./out/allure-results",
links: { issue: { urlTemplate: "https://github.com/allure-framework/allure-js/issues/%s" } },
},
],
],
typecheck: {
enabled: true,
tsconfig: "./tsconfig.test.json",
Expand Down

0 comments on commit b60dad0

Please sign in to comment.