Skip to content

Commit

Permalink
chore: report on errors in before and describe during the test run
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Sep 5, 2024
1 parent 8dbbcb1 commit d9bca64
Show file tree
Hide file tree
Showing 7 changed files with 625 additions and 181 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
in describe
3) foo

4) in describe

testing before each
nested
✔ neseted foo
Expand All @@ -30,7 +32,7 @@
- skipped test


6 passing (136ms)
6 passing (133ms)
2 failing
1 skipped
1 todo
Expand Down Expand Up @@ -67,7 +69,7 @@
foo:

Test cancelled by parent error
 This test was cancelled due to an error in its parent suite/it or test/it, or in one of its before/beforeEach
 This test was cancelled due to an error in its parent describe or before hook

4) in describe:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ describe("before", () => {
assert.equal(1, 1);
});
});

describe("nested before", () => {
describe("level 1", () => {
before(() => {
throw new Error("before hook error");
});

it("should pass", async () => {
assert.equal(1, 1);
});

it("should pass, too", async () => {
assert.equal(1, 1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ describe("describe", () => {

throw new Error("describe setup error");
});

describe("nested describe", () => {
describe("level 1", () => {
it("should pass", async () => {
assert.equal(1, 1);
});

it("should pass, too", async () => {
assert.equal(1, 1);
});

throw new Error("describe setup error");
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
✔ should pass
✔ should pass, too

3) after

before each
4) should pass
5) should pass, too
Expand All @@ -14,14 +16,32 @@
6) should pass
7) should pass, too

8) before

nested before
level 1
9) should pass
10) should pass, too

11) level 1

describe
9) should pass
10) should pass, too
12) should pass
13) should pass, too

14) describe

2 passing (143ms)
nested describe
level 1
15) should pass
16) should pass, too

17) level 1


2 passing (144ms)
4 failing
4 cancelled
8 cancelled

1) after each
should pass:
Expand Down Expand Up @@ -69,20 +89,60 @@
Error: before hook error
 at SuiteContext.<anonymous> (integration-tests/fixture-tests/hooks-test/before.ts:6:11)

9) describe
should pass:
9) nested before
level 1
should pass:

Test cancelled by parent error
 This test was cancelled due to an error in its parent describe or before hook

10) nested before
level 1
should pass, too:

Test cancelled by parent error
 This test was cancelled due to an error in its parent describe or before hook

11) nested before
level 1:

Error: before hook error
 at SuiteContext.<anonymous> (integration-tests/fixture-tests/hooks-test/before.ts:21:13)

12) describe
should pass:

Test cancelled by parent error
 This test was cancelled due to an error in its parent describe or before hook

10) describe
13) describe
should pass, too:

Test cancelled by parent error
 This test was cancelled due to an error in its parent describe or before hook

11) describe:
14) describe:

Error: describe setup error
 at SuiteContext.<anonymous> (integration-tests/fixture-tests/hooks-test/describe.ts:13:9)

15) nested describe
level 1
should pass:

Test cancelled by parent error
 This test was cancelled due to an error in its parent describe or before hook

16) nested describe
level 1
should pass, too:

Test cancelled by parent error
 This test was cancelled due to an error in its parent describe or before hook

17) nested describe
level 1:

Error: describe setup error
 at SuiteContext.<anonymous> (integration-tests/fixture-tests/hooks-test/describe.ts:26:11)

18 changes: 11 additions & 7 deletions v-next/hardhat-node-test-reporter/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,19 @@ export default async function* customReporter(
// want to print its failure.
if (event.type === "test:fail") {
if (!isSubtestFailedError(event.data.details.error)) {
const failure: Failure = {
index: preFormattedFailureReasons.length,
testFail: event.data,
contextStack: stack,
};

// We format the failure reason and store it in an array, so that we
// can output it at the end.
preFormattedFailureReasons.push(formatFailureReason(failure));

await annotatePR(event.data);

preFormattedFailureReasons.push(
formatFailureReason({
index: preFormattedFailureReasons.length,
testFail: event.data,
contextStack: stack,
}),
);
yield `\n${formatTestFailure(failure)}\n`;
}
}

Expand Down

0 comments on commit d9bca64

Please sign in to comment.