adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js

Home Page:https://gitter.im/mochawesome/general

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

addContext called in beforeEach/afterEach hook adds additional context to the test even when the hook fails and the test is pending

xkorin opened this issue · comments

commented

Hello,

we are adding additional content like screenshots, logs in beforeEach Mocha hook but the content is always attached to the test. Normally it is not big issue as the test is listed in report so additional content can be checked there. In the case that beforeEach fails, any additional content is also added to the test but the test is marked as pending in this time and the mochawesome report is hiding all pending tests by the default.

image

As user I need to go to menu and enable switch to show all pending tests. Only then the user can check additional content added in the beforeEach hook.

image

Code Reproduce

  • Run test below where 'addContext' is called in beforeEach

describe.only("Mochawesome", () => {
	beforeEach(async function () {
		addContext(this, {
			title: "beforeEach hook",
			value: "Additional content is added to the test not to the reported hook in the report.",
		});
		throw "Error in beforeEach hook";
	});

	it("My test", () => {});
});
  • Open mochawesome report

Actual behavior

  • Additional content by addContext is added to the test "My test" which is hidden in the report by default.

Expected behavior
Additional content by addContext will be directly added to the failed beforeEach hook in the report.

image

In my opinion, additional content added in beforeEach (or in any other hook) hook should be always added to that hook in the report. then it would be always clear if it was added in the hook or test.

Environment (please complete the following information):

  • Platform Windows 10
  • mochawesome 7.1.3
  • mocha 8.2.3
  • Node 16.19.0