Skip to content

Commit

Permalink
fix errors reporting for steps
Browse files Browse the repository at this point in the history
fix skipped tests reporting
cover rest functionality with tests
hide jest log during unit tests
  • Loading branch information
epszaw committed Aug 17, 2023
1 parent 8d69882 commit 2d05272
Show file tree
Hide file tree
Showing 18 changed files with 242 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/allure-jest/src/AllureJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ export default class AllureJest extends NodeEnvironment {
private handleTestFail(test: Circus.TestEntry) {
const currentTestID = getTestID(getTestPath(test));
const currentTest = this.runningTests.get(currentTestID)!;
// jest collects all errors, but we need to report the first one because it's a reason why the test has been failed
const [error] = test.errors;
const hasMultipleErrors = Array.isArray(error);

currentTest.stage = Stage.FINISHED;
currentTest.status = Status.FAILED;
currentTest.statusDetails = {
message: test.errors[0].message,
trace: test.errors[0].stack,
message: hasMultipleErrors ? error[0].message : error.message,
trace: hasMultipleErrors ? error[0].stack : error.stack,
};
}

Expand All @@ -145,6 +148,9 @@ export default class AllureJest extends NodeEnvironment {

currentTest.stage = Stage.PENDING;
currentTest.status = Status.SKIPPED;

currentTest.endTest();
this.runningTests.delete(currentTestID);
}

private handleTestDone(test: Circus.TestEntry) {
Expand Down
3 changes: 3 additions & 0 deletions packages/allure-jest/test/fixtures/attachments.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("json", () => {
allure.attachment(JSON.stringify({ foo: "bar" }), "application/json");
});
7 changes: 7 additions & 0 deletions packages/allure-jest/test/fixtures/description.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
it("markdown", () => {
allure.description("foo");
});

it("html", () => {
allure.descriptionHtml("foo");
});
3 changes: 3 additions & 0 deletions packages/allure-jest/test/fixtures/historyId.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("historyId", () => {
allure.historyId("foo");
});
6 changes: 6 additions & 0 deletions packages/allure-jest/test/fixtures/parameters.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
it("custom", () => {
allure.parameter("foo", "bar", {
excluded: false,
mode: "hidden",
});
});
5 changes: 5 additions & 0 deletions packages/allure-jest/test/fixtures/skipped.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it.skip("skipped", () => {});

describe.skip("suite", () => {
it("skipped", () => {});
});
19 changes: 19 additions & 0 deletions packages/allure-jest/test/fixtures/steps.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
it("passed", async () => {
await allure.step("first step name", async (s1) => {
await s1.step("second step name", async (s2) => {
await s2.step("third step name", (s3) => {
s3.label("foo", "bar");
});
});
});
});

it("failed", async () => {
await allure.step("first step name", async (s1) => {
await s1.step("second step name", async (s2) => {
await s2.step("third step name", (s3) => {
throw new Error("foo");
});
});
});
});
3 changes: 3 additions & 0 deletions packages/allure-jest/test/fixtures/testCaseId.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("testCaseId", () => {
allure.testCaseId("foo");
});
1 change: 1 addition & 0 deletions packages/allure-jest/test/fixtures/todo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it.todo("todo");
19 changes: 19 additions & 0 deletions packages/allure-jest/test/spec/attachments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("attachments", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/attachments.test.js"]);
});

it("adds markdown description", () => {
const { attachments } = results.json;

attachments.should.include.something.like({
name: "Attachment",
type: "application/json",
});
});
});
22 changes: 22 additions & 0 deletions packages/allure-jest/test/spec/description.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("description", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/description.test.js"]);
});

it("adds markdown description", () => {
const { description } = results.markdown;

expect(description).eq("foo");
});

it("adds custom history id", () => {
const { descriptionHtml } = results.html;

expect(descriptionHtml).eq("foo");
});
});
16 changes: 16 additions & 0 deletions packages/allure-jest/test/spec/historyId.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("historyId", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/historyId.test.js"]);
});

it("adds custom history id", () => {
const { historyId } = results.historyId;

expect(historyId).eq("foo");
});
});
20 changes: 20 additions & 0 deletions packages/allure-jest/test/spec/parameters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { runJestTests, TestResultsByFullName } from "../utils";

describe("parameters", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/parameters.test.js"]);
});

it("adds custom parameter", () => {
const { parameters } = results.custom;

parameters.should.include.something.that.deep.equals({
name: "foo",
value: "bar",
excluded: false,
mode: "hidden",
});
});
});
25 changes: 25 additions & 0 deletions packages/allure-jest/test/spec/skipped.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Stage, Status } from "allure-js-commons";
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("skipped", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/skipped.test.js"]);
});

it("marks skipped test as skipped", () => {
const { stage, status } = results.skipped;

expect(stage).eq(Stage.PENDING);
expect(status).eq(Status.SKIPPED);
});

it("marks test inside skipped suite as skipped", () => {
const { stage, status } = results["suite skipped"];

expect(stage).eq(Stage.PENDING);
expect(status).eq(Status.SKIPPED);
});
});
50 changes: 50 additions & 0 deletions packages/allure-jest/test/spec/steps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Stage, Status } from "allure-js-commons";
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("steps", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/steps.test.js"]);
});

describe("passed steps", () => {
it("adds nested steps", () => {
const { steps, labels } = results.passed;

labels.should.include.something.that.deep.equals({
name: "foo",
value: "bar",
});

expect(steps.length).eq(1);
expect(steps[0].name).eq("first step name");
expect(steps[0].steps.length).eq(1);
expect(steps[0].steps[0].name).eq("second step name");
expect(steps[0].steps[0].steps.length).eq(1);
expect(steps[0].steps[0].steps[0].name).eq("third step name");
});
});

describe("failed steps", () => {
it("fails the test with original step error", () => {
const { status, statusDetails, steps } = results.failed;

expect(status).eq(Status.FAILED);
expect(statusDetails.message).eq("foo");
expect(steps).to.have.length(1);
expect(steps[0].name).eq("first step name");
expect(steps[0].status).eq(Status.BROKEN);
expect(steps[0].statusDetails.message).eq("foo");
expect(steps[0].steps.length).eq(1);
expect(steps[0].steps[0].name).eq("second step name");
expect(steps[0].steps[0].status).eq(Status.BROKEN);
expect(steps[0].steps[0].statusDetails.message).eq("foo");
expect(steps[0].steps[0].steps.length).eq(1);
expect(steps[0].steps[0].steps[0].name).eq("third step name");
expect(steps[0].steps[0].steps[0].status).eq(Status.BROKEN);
expect(steps[0].steps[0].steps[0].statusDetails.message).eq("foo");
});
});
});
16 changes: 16 additions & 0 deletions packages/allure-jest/test/spec/testCaseId.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("testCaseId", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/testCaseId.test.js"]);
});

it("adds custom history id", () => {
const { testCaseId } = results.testCaseId;

expect(testCaseId).eq("foo");
});
});
18 changes: 18 additions & 0 deletions packages/allure-jest/test/spec/todo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Stage, Status } from "allure-js-commons";
import { expect } from "chai";
import { runJestTests, TestResultsByFullName } from "../utils";

describe("todo", () => {
let results: TestResultsByFullName;

beforeEach(async () => {
results = await runJestTests(["./test/fixtures/todo.test.js"]);
});

it("marks todo tests as skipped", () => {
const { stage, status } = results.todo;

expect(stage).eq(Stage.PENDING);
expect(status).eq(Status.SKIPPED);
});
});
3 changes: 1 addition & 2 deletions packages/allure-jest/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export const runJestTests = async (fixtures: string[]): Promise<TestResultsByFul
const argv: Config.Argv = {
config: require.resolve("./jest.config"),
collectCoverage: false,
verbose: false,
silent: true,
reporters: [],
$0: "",
_: fixtures,
};
Expand Down

0 comments on commit 2d05272

Please sign in to comment.