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:
-
This would help in quickly moving through the logs.
Cmd + F
forFAIL 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: -
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. TheshowPaths
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](https://private-user-images.githubusercontent.com/29686866/287948269-dfce56cd-5bac-4b1b-9829-e55f82ea23a8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg5MjkxNzcsIm5iZiI6MTcxODkyODg3NywicGF0aCI6Ii8yOTY4Njg2Ni8yODc5NDgyNjktZGZjZTU2Y2QtNWJhYy00YjFiLTk4MjktZTU1ZjgyZWEyM2E4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIxVDAwMTQzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQzNzAyMjc5MTNhYmVmYWU4NGJhNzJmODBmMTk4ZDI4MTA0OThhZDZhZjMxMTFkY2I2Nzc4NjEzNGY4MTg0NGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.40JMCIXFryDcoFlB2eMEqksZD8I4YhphBs5aME3PoTg)
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.