-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly report information from before/after hooks
- Loading branch information
1 parent
ab47cdd
commit c933122
Showing
6 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { MochaAllureInterface } from "../../.."; | ||
import { ContentType } from "allure-js-commons"; | ||
import { expect } from "chai"; | ||
|
||
declare const allure: MochaAllureInterface; | ||
|
||
describe("hooks test", () => { | ||
describe("before fails", () => { | ||
before(function() { | ||
throw new Error("In before"); | ||
}); | ||
|
||
it("never runs", () => {}); | ||
}); | ||
|
||
describe("after fails", () => { | ||
it("fails in after", () => {}); | ||
|
||
after(function() { | ||
throw new Error("In after"); | ||
}); | ||
}); | ||
|
||
describe("beforeEach fails", () => { | ||
beforeEach(function() { | ||
allure.attachment("saved in beforeEach", "should be saved", ContentType.TEXT); | ||
throw new Error("In before each"); | ||
}); | ||
|
||
it("test with beforeEach", () => {}); | ||
}); | ||
|
||
describe("afterEach fails", () => { | ||
afterEach(function() { | ||
allure.attachment("saved in afterEach", "should be saved", ContentType.TEXT); | ||
throw new Error("In after each"); | ||
}); | ||
|
||
it("passed test with afterEach", () => {}); | ||
}); | ||
|
||
describe("both afterEach and test fail", () => { | ||
afterEach(function() { | ||
allure.attachment("saved in afterEach", "should be saved", ContentType.TEXT); | ||
throw new Error("In after each"); | ||
}); | ||
|
||
it("failed test with afterEach", () => { | ||
expect(1).eq(2); | ||
}); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { InMemoryAllureWriter, Status } from "allure-js-commons"; | ||
import { expect } from "chai"; | ||
import { suite } from "mocha-typescript"; | ||
import { runTests } from "../utils"; | ||
|
||
@suite | ||
class HooksSuite { | ||
private writerStub!: InMemoryAllureWriter; | ||
|
||
async before() { | ||
this.writerStub = await runTests("hooks"); | ||
} | ||
|
||
@test | ||
shouldHandleBeforeEach() { | ||
const test = this.writerStub.getTestByName("test with beforeEach"); | ||
|
||
expect(test.status).eq(Status.BROKEN); | ||
expect(test.statusDetails.message).eq("In before each"); | ||
expect(test.attachments).have.length(1); | ||
expect(test.attachments[0].name).eq("saved in beforeEach"); | ||
} | ||
|
||
@test | ||
shouldHandleAfterEach() { | ||
const test = this.writerStub.getTestByName("passed test with afterEach"); | ||
|
||
expect(test.status).eq(Status.BROKEN); | ||
expect(test.statusDetails.message).eq("In after each"); | ||
expect(test.attachments).have.length(1); | ||
expect(test.attachments[0].name).eq("saved in afterEach"); | ||
} | ||
|
||
@test | ||
shouldPreserveTestErrorIfAfterEachFails() { | ||
const test = this.writerStub.getTestByName("failed test with afterEach"); | ||
|
||
expect(test.status).eq(Status.FAILED); | ||
expect(test.statusDetails.message).eq("expected 1 to equal 2"); | ||
expect(test.attachments).have.length(1); | ||
expect(test.attachments[0].name).eq("saved in afterEach"); | ||
} | ||
|
||
@test | ||
shouldHandleBefore() { | ||
const test = this.writerStub.getTestByName("\"before all\" hook for \"never runs\""); | ||
|
||
expect(test.status).eq(Status.BROKEN); | ||
expect(test.statusDetails.message).eq("In before"); | ||
} | ||
|
||
@test | ||
shouldHandleAfter() { | ||
const test = this.writerStub.getTestByName("fails in after"); | ||
|
||
expect(test.status).eq(Status.BROKEN); | ||
expect(test.statusDetails.message).eq("In after"); | ||
} | ||
} |