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

Defend against console mocks in TAP reporter #125

Closed
Krinkle opened this issue Nov 7, 2020 · 1 comment
Closed

Defend against console mocks in TAP reporter #125

Krinkle opened this issue Nov 7, 2020 · 1 comment

Comments

@Krinkle
Copy link
Member

Krinkle commented Nov 7, 2020

Ref qunitjs/qunit#1340.

If a project is mocking console.log because the project in question is, like js-reporters, also related to producing output, then at times it can make the test output broken and very hard to debug.

@Krinkle
Copy link
Member Author

Krinkle commented Nov 7, 2020

We could capture and cache a reference to console.log early on and use that, although that makes testing our own output harder since then we can't mock our own console anymore when testing TapReporter whilst using TapReporter. We could workaround that by exposing our cached reference in a pseudu-private property that we can still mock manually.

Alternatively, a bit more elaborate but perhaps cleaner method, is to give TapReporter a constructor parameter with a Writable stream. When used normally, that would default to process.stdout (the Writable stream that console.log uses), and under test we can inject our own instance that we can easily mock.

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

No branches or pull requests

1 participant