[No QA] Clearing logs in unit tests#70095
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
9187c7a to
4add60f
Compare
|
|
|
I have read the CLA Document and I hereby sign the CLA |
50804d2 to
438ba69
Compare
|
@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
| const isVerbose = process.argv.includes('verbose') || process.env.JEST_VERBOSE === 'true'; | ||
|
|
||
| if (!isVerbose) { | ||
| jest.spyOn(console, 'log').mockImplementation(() => {}); |
There was a problem hiding this comment.
Do we need this if we also have it in setupAfterEnv?
There was a problem hiding this comment.
yes, I checked and if its only in either of them there is still debug logs.. only when I use it in both of them its clearing all of those.
There was a problem hiding this comment.
That shouldn't happen ideally. Have we tried removing this and only keeping setupAfterEnv?
There was a problem hiding this comment.
I changed it, as I move the logic to setup.ts
438ba69 to
dc12a41
Compare
mananjadhav
left a comment
There was a problem hiding this comment.
Left a few comments.
| jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
| jest.spyOn(console, 'info').mockImplementation(() => {}); | ||
| jest.spyOn(console, 'debug').mockImplementation(() => {}); | ||
| jest.spyOn(console, 'warn').mockImplementation(() => {}); |
There was a problem hiding this comment.
I understand hiding others but do we really want to hide warn as well?
cc - @roryabraham
There was a problem hiding this comment.
No strong opinion. I think it would make sense to hide log, info, debug, but not warn or error
There was a problem hiding this comment.
Then again, I think if you want to see more detail, you run with --verbose. In CI we really only want to see error I guess. I think this is fine as-is
There was a problem hiding this comment.
Okay thanks for confirming.
| // eslint-disable-next-line no-console | ||
| console.log('DEBUG', ...params); | ||
| }); | ||
| const isVerbose = process.argv.includes('verbose') || process.env.JEST_VERBOSE === 'true'; |
There was a problem hiding this comment.
Does it by any chance conflict with Jest verbose option? I don't have a specific use case in my head but do you think it would cause issue?
There was a problem hiding this comment.
I removed process.argv.includes('verbose') anyway. I didn't come up with use case as well.
@roryabraham what do you think ?
| // eslint-disable-next-line no-console | ||
| console.log('DEBUG', ...params); | ||
| }); | ||
| const isVerbose = process.argv.includes('verbose') || process.env.JEST_VERBOSE === 'true'; |
There was a problem hiding this comment.
Other places we're using --verbose and here only verbose?
There was a problem hiding this comment.
I double checked and now it should be ok
|
|
||
| const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; | ||
|
|
||
| beforeEach(() => { |
There was a problem hiding this comment.
I have 2 concerns with using beforeEach.
-
Essentially this will be executing before every test and it's kinda like an overhead for something that is to be done global? We generally use
beforeEachfor isolation so that each test gets its own fresh setup -
If you globally mock in
beforeEach, then restoring for just one test requires extra juggling. This might be required when someone is testing it locally may be a bunch of tests?
There was a problem hiding this comment.
Im now using only setup.ts, the code from this file has been removed.
| @@ -40,16 +41,24 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ | |||
| }, | |||
| })); | |||
|
|
|||
| // Turn off the console logs for timing events. They are not relevant for unit tests and create a lot of noise | |||
| jest.spyOn(console, 'debug').mockImplementation((...params: string[]) => { | |||
There was a problem hiding this comment.
@roryabraham These logs were always hidden earlier. Now when verbose is enabled, these logs will be printed. I am assuming we're fine with that? Confirming because of the comment.
They are not relevant for unit tests and create a lot of noise
|
@elirangoshen I was verifying the result of the test runs but if you check the Jest GH action you'll see
|
|
@elirangoshen what do you think of mocking instead of spyOn. The reason being |
Great idea. I implemented it it and added Could you check it now ? |
|
The code is fine, but we've got failing tests because of the changes. @elirangoshen Can you please check those? |
Im currently working on a task with more priority but Ill take a look as soon as I could, I've notice it thanks |
|
@elirangoshen any updates here? Should we close this and reopen when you're ready? |
ebabf30 to
46712f4
Compare
Ill take a look now.
Im still working on other issue but today I could work on this one as well. There's more failing tests and I still couldn't resolve those it seems that each test mocking usually those tests using this command : Ill check what else I can do @mananjadhav |
|
npm has a |
So there's multiple failing tests, mostly one who trying to mock Sample of such logs is: While i'm able to fix it in some of the failing tests files, I'm not able to fix it in al of them, and even if I will I don't think its good idea, as I think its better to modifying only general jest files like Do you think I can do different implementation , or maybe revert to what I did before as there was not failing tests? When I revert to use Maybe its minor extra logs and its still better to use @roryabraham maybe we can remove it from WIP ? |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.2.29-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.2.29-5 🚀
|

Explanation of Change
Clearing logs in unit tests
Fixed Issues
$ #70676
PROPOSAL: Clearing console logs from unit tests
Background:
Unit tests often include many logs that can provide insight on what's happening in that test. In JavaScript, console logs are generally divided into four levels:
debuginfo(this is generally the default used by console.log)warnerrorIf you are running a full test suite, you're likely to be most interested in error logs, because they will be the ones that show you which tests are failing and why. If you're running or debugging an individual test, you're more likely to be interested in all logs.
Problem
When running our jest tests, the large volume of logs across all tests makes it difficult to quickly see which tests failed and why. This prevents us from quickly resolving issues when tests fail on a PR, which in turn can delay the merge and deploy of the PR.
Solution
Silence
debug,info, andwarnlogs by default in our jest tests. This will greatly reduce the volume of logs and make it easier to quickly identify which tests failed and why. Enable developers to see all log levels by passing the--verboseflag to jest; that way we can still dive into more detail in an individual test for debugging purposes.Tests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop