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]: Method to pass information to a custom reporter #15385

Open
Thomas-Haider opened this issue Nov 19, 2024 · 0 comments
Open

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

Thomas-Haider opened this issue Nov 19, 2024 · 0 comments

Comments

@Thomas-Haider
Copy link

Thomas-Haider commented Nov 19, 2024

🚀 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.

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

No branches or pull requests

1 participant