Skip to content

Commit

Permalink
fix: process.stdout could be undefined on Windows (fix #1292) (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed May 13, 2022
1 parent c491fb4 commit 3179ac9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/core.ts
Expand Up @@ -283,7 +283,7 @@ export class Vitest {
if (this.server.config.clearScreen === false)
return

const repeatCount = process.stdout.rows - 2
const repeatCount = (process.stdout?.rows ?? 0) - 2
const blank = repeatCount > 0 ? '\n'.repeat(repeatCount) : ''
this.console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/diff.ts
Expand Up @@ -3,7 +3,7 @@ import * as diff from 'diff'
import cliTruncate from 'cli-truncate'

export function formatLine(line: string, outputTruncateLength?: number) {
return cliTruncate(line, (outputTruncateLength ?? (process.stdout.columns || 80)) - 4)
return cliTruncate(line, (outputTruncateLength ?? (process.stdout?.columns || 80)) - 4)
}

export interface DiffOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/error.ts
Expand Up @@ -189,7 +189,7 @@ export function generateCodeFrame(
let count = 0
let res: string[] = []

const columns = process.stdout.columns || 80
const columns = process.stdout?.columns || 80

function lineNo(no: number | string = '') {
return c.gray(`${String(no).padStart(3, ' ')}| `)
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/renderers/utils.ts
Expand Up @@ -12,7 +12,7 @@ export const pointer = c.yellow(F_POINTER)
export const skipped = c.dim(c.gray(F_DOWN))

export function getCols(delta = 0) {
let length = process.stdout.columns
let length = process.stdout?.columns
if (!length || isNaN(length))
length = 30
return Math.max(length + delta, 0)
Expand Down

0 comments on commit 3179ac9

Please sign in to comment.