Skip to content

Commit 113640c

Browse files
committed
unfinished tests now use jests computed failure status
1 parent 61c82d8 commit 113640c

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

packages/allure-jest/src/environmentFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,16 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
236236
const testUuid = this.runContext.executables.pop();
237237

238238
if (testUuid) {
239-
const { details } = this.#statusAndDetails(test.errors);
239+
const { status, details } = this.#statusAndDetails(test.errors);
240240
let tr: TestResult | undefined;
241241
this.runtime.updateTest(testUuid, (result) => {
242242
tr = result;
243243
});
244-
// hook failure, finish as skipped
244+
// hook failure, finish with the status reported by Jest
245245
if (tr?.status === undefined && tr?.stage === Stage.RUNNING) {
246246
this.runtime.updateTest(testUuid, (result) => {
247247
result.stage = Stage.FINISHED;
248-
result.status = Status.SKIPPED;
248+
result.status = status;
249249
result.statusDetails = {
250250
...result.statusDetails,
251251
...details,

packages/allure-jest/test/spec/hooks.test.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ it("should report failed beforeAll hooks", async () => {
194194
expect.arrayContaining([
195195
expect.objectContaining({
196196
name: "test 1",
197-
status: Status.SKIPPED,
197+
status: Status.BROKEN,
198198
stage: Stage.FINISHED,
199199
statusDetails: expect.objectContaining({
200200
message: "foo",
@@ -204,7 +204,7 @@ it("should report failed beforeAll hooks", async () => {
204204

205205
expect.objectContaining({
206206
name: "test 2",
207-
status: Status.SKIPPED,
207+
status: Status.BROKEN,
208208
stage: Stage.FINISHED,
209209
statusDetails: expect.objectContaining({
210210
message: "foo",
@@ -252,7 +252,7 @@ it("should report failed beforeEach hooks", async () => {
252252
expect(testResult).toEqual(
253253
expect.objectContaining({
254254
name: "sample test",
255-
status: Status.SKIPPED,
255+
status: Status.BROKEN,
256256
stage: Stage.FINISHED,
257257
statusDetails: expect.objectContaining({
258258
message: "foo",
@@ -283,6 +283,50 @@ it("should report failed beforeEach hooks", async () => {
283283
);
284284
});
285285

286+
it("should report tests as failed on failed assertions in before hooks", async () => {
287+
const { tests } = await runJestInlineTest({
288+
"sample.test.js": `
289+
describe("beforeAll assertion", () => {
290+
beforeAll(() => {
291+
expect(1).toStrictEqual(2);
292+
});
293+
294+
it("test 1", () => {});
295+
it("test 2", () => {});
296+
});
297+
298+
describe("beforeEach assertion", () => {
299+
beforeEach(() => {
300+
expect(1).toStrictEqual(2);
301+
});
302+
303+
it("test 3", () => {});
304+
});
305+
`,
306+
});
307+
308+
expect(tests).toHaveLength(3);
309+
expect(tests).toEqual(
310+
expect.arrayContaining([
311+
expect.objectContaining({
312+
name: "test 1",
313+
status: Status.FAILED,
314+
stage: Stage.FINISHED,
315+
}),
316+
expect.objectContaining({
317+
name: "test 2",
318+
status: Status.FAILED,
319+
stage: Stage.FINISHED,
320+
}),
321+
expect.objectContaining({
322+
name: "test 3",
323+
status: Status.FAILED,
324+
stage: Stage.FINISHED,
325+
}),
326+
]),
327+
);
328+
});
329+
286330
it("should report failed afterEach hooks", async () => {
287331
const { tests, groups } = await runJestInlineTest({
288332
"sample.test.js": `

0 commit comments

Comments
 (0)