jest icon indicating copy to clipboard operation
jest copied to clipboard

[Feature]: Method to pass information to a custom reporter

Open Thomas-Haider opened this issue 1 year ago • 25 comments

🚀 Feature Proposal

Hey, to create more powerful custom reporters in jest it would be extremely helpful to provide an easy possibility to pass information from a jest test to a custom reporter hook (e.g. onTestCaseResult). This will enable people to define metadata for tests such as Author, Ticket, Tags,...

Motivation

Firstly, it will allow the community to build more powerful customer jest reporters as this can be used as an additional source of input for the reporter and are no longer limited by the currently available fields.

Secondly, we have a microservice platform architecture where each "product feature" is wrapped in its own app, which is located in its own repository and is then offered to the customer as part of a platform. To ensure the quality of the individual apps and release the apps with confidence, we have a single source of truth for test coverage and part of this is that we report metadata such as test author, ticket (to map it to a product feature) and tags for each test. However, this is currently only possible via a ugly workaround and results in test name adaptations which is not a good practices and feels like a weird workaround for something relatively "simple".

Workaround I am talking about where the metadata is passed base64 encoded as part of the testname.

  ctc.use({
    author: 'john.doe',
    ticket: 'ABC-123456',
    tags: ['foo', 'bar'],
  });
  it(ctc`simple test`, async () => {
    expect(false).toBeTruthy();
  });

I saw that there is a package called jest-metadata which provides something similar however this requires defining a custom jest-environment which is sadly no option for us as we already have a custom jest-environment which is also shipped to our customers and therefore we can't combine this as our customers should not use this metadata functionality.

Example

Here is an example on how i could imagine it will look like in the code:

describe('test', () => {

  it.reporter({
    author: 'john.doe',
    ticket: 'ABC-123456',
    tags: ['foo', 'bar'],
  });

  it(ctc`simple test 2`, async () => {
    expect(false).toBeTruthy();
  });

  it.reporter({
    author: 'john.test',
    ticket: 'ABC-123456',
    tags: ['foo', 'bar'],
  });

  it(ctc`simple test1`, () => {
    expect(false).toBeTruthy();
  });
});

Calling it.reporter will make the passed information available as part of the test object of the onTestCaseResult(test: Test, testCaseResult: TestCaseResult) hook.

Pitch

It will allow more out-of-the-box variability for custom jest reporters, which would be quite a good thing.

Thomas-Haider avatar Nov 19 '24 13:11 Thomas-Haider

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Dec 19 '24 13:12 github-actions[bot]

+1 on this!

jacoblee93 avatar Jan 11 '25 20:01 jacoblee93

We have a similar use case and are also interested in this feature!

AmsterGet avatar Jan 31 '25 16:01 AmsterGet

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Mar 02 '25 17:03 github-actions[bot]

Up!

AmsterGet avatar Mar 17 '25 10:03 AmsterGet

+1

lifanov-rza avatar Mar 17 '25 13:03 lifanov-rza

+1

zaskina avatar Mar 17 '25 13:03 zaskina

+1

PavGurin avatar Mar 17 '25 14:03 PavGurin

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Apr 16 '25 15:04 github-actions[bot]

+1

JohT avatar Apr 16 '25 18:04 JohT

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar May 16 '25 19:05 github-actions[bot]

Up!

AmsterGet avatar May 16 '25 19:05 AmsterGet

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jun 15 '25 21:06 github-actions[bot]

Up!

AmsterGet avatar Jun 17 '25 11:06 AmsterGet

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 17 '25 12:07 github-actions[bot]

Up!

AmsterGet avatar Jul 17 '25 12:07 AmsterGet

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 16 '25 14:08 github-actions[bot]

Still want this!

jacoblee93 avatar Aug 16 '25 15:08 jacoblee93

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Sep 15 '25 16:09 github-actions[bot]

Up!

AmsterGet avatar Sep 15 '25 16:09 AmsterGet

Up!

chudnyi avatar Sep 18 '25 06:09 chudnyi

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Oct 18 '25 07:10 github-actions[bot]

Up!

AmsterGet avatar Oct 18 '25 20:10 AmsterGet

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Nov 17 '25 21:11 github-actions[bot]

Up!

AmsterGet avatar Nov 18 '25 09:11 AmsterGet