Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Get detailed metadata from expect matchers in reporters #4547

Open
esamattis opened this issue Sep 27, 2017 · 8 comments
Open

Comments

@esamattis
Copy link

esamattis commented Sep 27, 2017

I'd like to generate HTML reports from jest-image-snapshot with the diff images.

But doing it from a customer Jest reporter does not seem to be possible because because custom matchers such as the toMatchImageSnapshot cannot pass extra metadata (path to the snapshot diff file) to the reporters.

I'd like to be able to return the filename here and read it somehow in a onTestResult() method of a reporter.

Ref americanexpress/jest-image-snapshot#13

@cpojer
Copy link
Member

cpojer commented Sep 27, 2017

I'm trying to figure out what the implications are for returning the file name here, and what the downsides are, but I cannot think clearly right now. I definitely think we should find a way to support this.

@aaronabramov and @thymikee do you guys have any thoughts about this?

@thymikee
Copy link
Collaborator

Hm, this is another key in the object, so as long as we keep all properties initialized (at least in core matchers), we should still have this code monomorphic and perf shouldn't degrade I think.
And some metadata may really be useful to create more powerful matchers.

@cpojer
Copy link
Member

cpojer commented Sep 27, 2017

I took a break and have some more clarity. My concern was mostly around what exposing a file name will mean: Does returning an absolute path cause issues with caching? Should it be relative to the rootDir? More importantly: will this enable people to store more metadata in different files, without appropriate hooks to clean them up when a snapshot/test is removed? I worry that this is opening a can of worms that allows people to do crazy things and that we may need to provide a fuller API to hook into Jest that gives access to the cleanup hook etc.

@esamattis
Copy link
Author

Hmm, I'm bit confused. I meant just adding possibility pass any metadata from a (custom) matcher to the (custom) reporters. Why does it matter if it's filename or any other string/object?

@anescobar1991
Copy link

anescobar1991 commented Sep 27, 2017

@cpojer jest-snapshot returns a few extra properties but I am not sure that custom reporters have access to these.

I think the ability for any metadata to be returned by a matcher and for reporters to pick up these properties is what @epeli is asking for. From the looks of the code comment in jest-snapshot this may already be possible though?

@Prior99
Copy link

Prior99 commented Apr 12, 2018

@anescobar1991 did you ever figure out whether it's possible? I tried to access the data passed to actual and expected from the matcher but with no results.

@SimenB
Copy link
Member

SimenB commented Feb 3, 2019

Related #7594

@JCMais
Copy link

JCMais commented Jun 21, 2023

I am trying to add custom metadata inside a test to be read by a custom reporter (like test category, severity, etc), is this issue related to this in any way?

What is the current status of this?

It is still open but was assigned to the v26 milestone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants