Hazyzh/jest-html-reporters

Add option to attach screenshot

storralba-elsevier opened this issue ยท 11 comments

Is your feature request related to a problem? Please describe.
The reporter is really good but I miss the option to add an screenshot or any other support file if something fails or to clarify the test report.
Describe the solution you'd like
reporter.currentTest.attach(file);
Where file an be image or text.

Would love this too - @Hazyzh any ideas on if/when this could/can be implemented?

good idea! need to think more about how to implement this feature. just add this to milestone 2.x.

Same as #37, this reporter just to display the data that we got form Jest, and we can not add any custom data to test results. I can provide a method to save images, but the key point is how to relate that image to the corresponding test case.

From Jest source code I found that there is a global variable when really running a test which stores the base information of the test. I can got file path and test full name from it, then combine it to our test result. This is a hack way that may not stable, but can not find another better way now.

/**
 *
 * @param {Buffer | string} attach
 * @param {string} description
 */
const addAttach = async (attach, description) => { ... }

provide a new method 'addAttach' in the package, in the test case you can add an image attach by using this method, and those images will show in the corresponding test case.
image

will update more detail in the readme.

New version (2.0.0) released. You can have a try now.

Amazing - great idea, thanks for providing!

Works perfectly! Thanks a lot!

Is there a way to attach html instead of a screenshot?

Is there a way to attach html instead of a screenshot?

Not support currently. maybe we can support it if it is a common use case.

This would be great, but maybe call it attachAsset and make it possible to add more than one