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

Change skipped tests handling logic #758

Merged
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
28 changes: 9 additions & 19 deletions packages/allure-hermione/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const hostname = os.hostname();

const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) => {
const { ALLURE_REPORTER_DEV_MODE } = process.env;
const loadedTests: Map<string, Hermione.Test> = new Map();
const runningTests: Map<string, AllureTest> = new Map();
const runtime = new AllureRuntime({
resultsDir: "allure-results",
Expand Down Expand Up @@ -239,11 +238,17 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =
});
});
hermione.on(hermione.events.AFTER_TESTS_READ, (collection) => {
// cache all the tests to handle skipped tests in future
// handle all skipped (pending) tests
collection.eachTest((test) => {
const testId = getTestId(test);
if (!test.pending) {
return;
}

const currentTest = createAllureTest(test);

loadedTests.set(testId(), test);
currentTest.status = Status.SKIPPED;
currentTest.stage = Stage.FINISHED;
currentTest.endTest();
});
});
hermione.on(hermione.events.TEST_BEGIN, (test) => {
Expand Down Expand Up @@ -290,23 +295,8 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =
currentTest.calculateHistoryId();
currentTest.stage = Stage.FINISHED;
currentTest.endTest(Date.now());
loadedTests.delete(testId());
runningTests.delete(testId());
});
hermione.on(hermione.events.END, () => {
// all tests have been finished
if (loadedTests.size === 0) {
return;
}

loadedTests.forEach((test) => {
const currentTest = createAllureTest(test);

currentTest.status = Status.SKIPPED;
currentTest.stage = Stage.FINISHED;
currentTest.endTest();
});
});

// it needs for tests because we need to read runtime writer data redefined in hermione config
// eslint-disable-next-line
Expand Down
5 changes: 5 additions & 0 deletions packages/allure-hermione/test/fixtures/only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it("first", () => {});

it("second", () => {});

it.only("third", () => {});
18 changes: 18 additions & 0 deletions packages/allure-hermione/test/spec/only.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from "chai";
import Hermione from "hermione";
import { describe, it } from "mocha";
import { getTestResultByName } from "../runner";
import { HermioneAllure } from "../types";

describe("only", () => {
it("reports only one spec", async () => {
const hermione = new Hermione("./test/.hermione.conf.js") as HermioneAllure;

await hermione.run(["./test/fixtures/only.js"], {});

const results = hermione.allure.writer.results;

expect(results).length(1);
expect(results[0].name).eq("third");
});
});
Loading