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

fix(reporters): write buffered stdout/stderr on process exit #6932

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Nov 19, 2024

Description

  • When logger.ts writes errors for unhandled rejections, it exits immediatelly. The windowed-renderer intercepts all process.stdout/err writes and buffers them. The buffered content must be written before exit.

private registerUnhandledRejection() {
const onUnhandledRejection = (err: unknown) => {
process.exitCode = 1
this.printError(err, {
fullStack: true,
type: 'Unhandled Rejection',
})
this.error('\n\n')
process.exit()
}

  • I wasn't able to come up with failing test case for this. We are overriding process.exit during tests. 🤔

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 97875c3
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/673ee87e5dcffd0008ca0a55
😎 Deploy Preview https://deploy-preview-6932--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

sheremet-va
sheremet-va previously approved these changes Nov 19, 2024
Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be happy if we can remove signal-exit, but it's also fine to merge it as is

@AriPerkkio
Copy link
Member Author

Do we want to implement our own signal-exit? We are already using it via log-update > cli-cursor > restore-cursor > signal-exit.

@sheremet-va
Copy link
Member

Do we want to implement our own signal-exit? We are already using it via log-update > cli-cursor > restore-cursor > signal-exit.

I was hoping we would be able to drop it when log-update is removed 😄

@sheremet-va
Copy link
Member

If we need it for stdout handling, then sure let's keep it

@AriPerkkio
Copy link
Member Author

AriPerkkio commented Nov 19, 2024

I can take a look at removing it completely once rest of log-update usage is removed. Though I'm not familiar with process.reallyExit and don't know why signal-exit overwrites it. Ideally we would not override anything, just hook into exit and the signals.

But what we need is to be able to restore CLI cursor always, and make sure log buffer is flushed on exit.

@AriPerkkio
Copy link
Member Author

Looking at how picospinner does this, I think we can follow their implementation: https://github.com/tinylibs/picospinner/pull/2/files (cc. @43081j)

I'll try in this PR to replace signal-exit with zero-deps solution.

@@ -175,6 +174,38 @@ export class WindowRenderer {
private write(message: string, type: 'output' | 'error' = 'output') {
(this.streams[type] as Writable['write'])(message)
}

private addProcessExitListeners() {
Copy link
Member Author

@AriPerkkio AriPerkkio Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point it's ok to have this here in windowedRenderer. But later on it might make sense to move this to logger.ts instead. 🤔

So that logger.ts would handle cursor hiding and showing. It shoud also expose callback that reporters could hook into, so that windowedRenderer could call flushBuffer on exit too.

@AriPerkkio AriPerkkio merged commit 80cde2a into vitest-dev:main Nov 26, 2024
17 checks passed
@AriPerkkio AriPerkkio deleted the fix/summary-unhandled-errors branch November 26, 2024 05:55
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.

3 participants