Skip to content

Commit 416ef01

Browse files
committed
fix(reporters): write buffered stdout/stderr on process exit
1 parent f1babdc commit 416ef01

File tree

4 files changed

+13
-53
lines changed

4 files changed

+13
-53
lines changed

packages/vitest/LICENSE.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,30 +1245,6 @@ Repository: git://github.com/feross/run-parallel.git
12451245
12461246
---------------------------------------
12471247

1248-
## signal-exit
1249-
License: ISC
1250-
By: Ben Coe
1251-
Repository: https://github.com/tapjs/signal-exit.git
1252-
1253-
> The ISC License
1254-
>
1255-
> Copyright (c) 2015, Contributors
1256-
>
1257-
> Permission to use, copy, modify, and/or distribute this software
1258-
> for any purpose with or without fee is hereby granted, provided
1259-
> that the above copyright notice and this permission notice
1260-
> appear in all copies.
1261-
>
1262-
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1263-
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1264-
> OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
1265-
> LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
1266-
> OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
1267-
> WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
1268-
> ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1269-
1270-
---------------------------------------
1271-
12721248
## sisteransi
12731249
License: MIT
12741250
By: Terkel Gjervig

packages/vitest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"expect-type": "^1.1.0",
163163
"magic-string": "^0.30.12",
164164
"pathe": "^1.1.2",
165-
"restore-cursor": "^5.1.0",
165+
"signal-exit": "^3.0.7",
166166
"std-env": "^3.8.0",
167167
"tinybench": "^2.9.0",
168168
"tinyexec": "^0.3.1",

packages/vitest/src/node/reporters/renderers/windowedRenderer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Writable } from 'node:stream'
22
import type { Vitest } from '../../core'
33
import { stripVTControlCharacters } from 'node:util'
4-
import restoreCursor from 'restore-cursor'
4+
5+
// @ts-expect-error -- untyped, cannot use v4 due to other deps
6+
import onExit from 'signal-exit'
57

68
const DEFAULT_RENDER_INTERVAL = 16
79

@@ -46,12 +48,17 @@ export class WindowRenderer {
4648
error: options.logger.errorStream.write.bind(options.logger.errorStream),
4749
}
4850

51+
// Write buffered content on unexpected exits, e.g. direct `process.exit()` calls
52+
onExit(() => {
53+
this.flushBuffer()
54+
this.write(SHOW_CURSOR)
55+
})
56+
4957
this.cleanups.push(
5058
this.interceptStream(process.stdout, 'output'),
5159
this.interceptStream(process.stderr, 'error'),
5260
)
5361

54-
restoreCursor()
5562
this.write(HIDE_CURSOR, 'output')
5663

5764
this.start()

pnpm-lock.yaml

Lines changed: 3 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)