Respect ROARR_LOG while running Jest UI tests
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Currently, `ROARR_LOG` is not respected while running Jest tests as Jest runner mocks `window` object while running tests. While any `console.log` within jest can be turned off with `--silent` there's no way to prevent logs generated by roarr.
Suggestion:
Update [createLogger](https://github.com/gajus/roarr/blob/297560490bf89dc950c5929a213e70373a218202/src/factories/createLogger.ts#L127) conditional check with...
```
if (
typeof process !== 'undefined' && (
!isBrowser() // Not running in a browser
|| process.env.JEST_WORKER_ID !== undefined // Running in Jest test environment
|| process.env.SOME_OTHER_ID !== undefined // Running in other test environment
)
) { ... }
```
...to allow ROARR_LOG to be respected across test environments that are mocking `window`.
Ref: https://jestjs.io/docs/environment-variables
Ways to get around this is to downgrade from 7.21.0 (7.5.0 worked as it uses `isNodeEnvironment` check. Haven't tested all versions in between) or to override ROARR.write in jest node environment ([not recommended](https://github.com/gajus/roarr#overriding-globalthisroarrwrite-in-nodejs))
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.