Skip to content

monkey-patch console.log and console.warn for all tests #11265

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

Merged
merged 7 commits into from
Apr 22, 2024

Conversation

Rich-Harris
Copy link
Member

At present we do one of two things with logs in tests:

  • monkey-patch console.log and console.warn on a per-test basis. this involves lots of repetitious ugly code
  • have a separate log.js file that exports a log array and do log.push instead of console.log. this is also repetitious (and requires a before_test or after_test hook to reset between different test modes), and is particularly annoying because in order to quickly try something out in the playground you need to rewrite the test if you want to actually see the logs

This PR makes things much simpler: we can access logs and warnings directly inside the test function.

If something gets logged before the test runs, and the test doesn't use logs, then the logs get stashed away, and replayed when either console.log is first called inside the test or, if that doesn't happen, after the test has run, meaning that temporary logs will always be visible and in the correct order.

Draft because I haven't yet converted all the tests that use the old way of doing things

Copy link

changeset-bot bot commented Apr 20, 2024

⚠️ No Changeset found

Latest commit: d6858a6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Rich-Harris Rich-Harris marked this pull request as ready for review April 20, 2024 16:54
@Rich-Harris Rich-Harris merged commit fd5f5bb into main Apr 22, 2024
8 checks passed
@Rich-Harris Rich-Harris deleted the intercept-logs branch April 22, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant