Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allure-mocha: fix test result overwritten when a test is skipped dynamically #1015

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading