rickhanlonii / jest-silent-reporter

A silent reporter for Jest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Print failed file paths in same format as default reporter

cseas opened this issue · comments

With the default jest reporter, we can search (Cmd + F) for the failed tests through the logs by searching for "FAIL <base directory>".

This helps us instantly get an overview of how many tests have failed and is specially useful when checking test results in GitHub Actions logs.

It'd be great if this reporter printed failed file paths in a similar format.

Current behavior

File paths for failed tests are printed like this in GitHub Actions logs:

/runner/_work/project/root/src/example/__tests__/Example.test.tsx
... followed by stack trace

Expected behavior

Failed file paths printed in this format:

FAIL src/example/__tests__/Example.test.tsx
... followed by stack trace

Can you help me understand the use case better? Since this only prints the failed tests, what's the value of searching for FAIL? All tests listed failed?

There are 2 benefits:

  1. This would help in quickly moving through the logs.
    Cmd + F for FAIL src gives us the total number of tests that failed and a way to quickly move through the logs test by test. This is possible with the default reporter.

    It's not possible to do this with jest-silent-reporter since there's no prefix to search for now. We can try searching for test.ts extension but that also picks up results from the stack trace. For example, the below search from jest-silent-reporter logs gives us 7 results but actually only 1 test failed in this run:

    Screenshot_2023-12-05_at_11_56_25_AM
  2. Keeping the log format consistent with the default reporter.
    The need of moving to jest-silent-reporter is mostly to keep the same logs but just filter out the passed tests. But jest-silent-reporter prints logs in a slightly different format than the default one. The showPaths flag is very useful but it prints absolute paths at the moment hence adding /runner/_work/project/root/ to all printed paths in GitHub Actions.

    The linked PR addresses this as well by printing relative paths using the same logic as the default reporter.


Since this only prints the failed tests

We're experiencing a different behavior. Jest errors from some tests are getting printed in our logs even when the tests are passing. For example, the below log printed from a passed test.

Screenshot 2023-12-05 at 12 14 55 PM

I wouldn't call this a bug since it's an error we need to fix so it's alright if it's getting printed for a passed test. But while we're working on fixing these background errors, we need a way for other devs in the team to quickly find/search the log of the test that actually failed.

what's the value of searching for FAIL?

I added jest-silent-reporter to a pretty large test suite. This reduced our test run's logs from 88k lines to 2k lines but it's still a lot of logs to sift through. That's why we search for the keyword FAIL to quickly move through the logs.

I see, yeah for that use case I recommend forking this library and customizing the output for your use case.