Skip to content

Commit 141a86a

Browse files
authoredJun 28, 2023
fix: run mode stuck in TTY terminals (#3690)
1 parent 0d5ec0f commit 141a86a

File tree

12 files changed

+88
-1
lines changed

12 files changed

+88
-1
lines changed
 

‎packages/vitest/src/node/cli-api.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ export async function startVitest(
8787
return ctx
8888
}
8989

90+
let stdinCleanup
9091
if (process.stdin.isTTY)
91-
registerConsoleShortcuts(ctx)
92+
stdinCleanup = registerConsoleShortcuts(ctx)
9293

9394
ctx.onServerRestart((reason) => {
9495
ctx.report('onServerRestart', reason)
@@ -115,6 +116,7 @@ export async function startVitest(
115116
if (ctx.shouldKeepServer())
116117
return ctx
117118

119+
stdinCleanup?.()
118120
await ctx.close()
119121
return ctx
120122
}

‎packages/vitest/src/node/stdin.ts

+4
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ export function registerConsoleShortcuts(ctx: Vitest) {
140140
}
141141

142142
on()
143+
144+
return function cleanup() {
145+
off()
146+
}
143147
}

‎pnpm-lock.yaml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/coverage-test/testing.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ for (const threads of threadsConfig) {
6464
exit()
6565
}
6666
else if (process.exitCode) {
67+
process.exitCode = null
6768
console.warn(`Browser tests failed, retrying ${1 + retry}/${retries.length - 1}...`)
6869
}
6970
else {

‎test/run/fixtures/example.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from 'vitest'
2+
3+
import { getHelloWorld } from './example'
4+
5+
test('getHello', async () => {
6+
expect(getHelloWorld()).toBe('Hello world')
7+
})

‎test/run/fixtures/example.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getHelloWorld() {
2+
return 'Hello world'
3+
}

‎test/run/fixtures/math.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from 'vitest'
2+
3+
import { sum } from './math'
4+
5+
test('sum', () => {
6+
expect(sum(1, 2)).toBe(3)
7+
})

‎test/run/fixtures/math.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sum(a: number, b: number) {
2+
return a + b
3+
}

‎test/run/fixtures/vitest.config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
// Patch stdin on the process so that we can fake it to seem like a real interactive terminal and pass the TTY checks
4+
process.stdin.isTTY = true
5+
process.stdin.setRawMode = () => process.stdin
6+
7+
export default defineConfig({
8+
test: {
9+
watch: false,
10+
reporters: 'verbose',
11+
teardownTimeout: 5_000,
12+
},
13+
})

‎test/run/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@vitest/test-run",
3+
"private": true,
4+
"scripts": {
5+
"test": "vitest"
6+
},
7+
"devDependencies": {
8+
"vite": "latest",
9+
"vitest": "workspace:*"
10+
}
11+
}

‎test/run/test/tty.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect, test } from 'vitest'
2+
import { runVitestCli } from '../../test-utils'
3+
4+
test('run mode does not get stuck when TTY', async () => {
5+
const vitest = await runVitestCli('--root', 'fixtures')
6+
await vitest.isDone
7+
8+
expect(vitest.stdout).toContain('✓ example.test.ts')
9+
expect(vitest.stdout).toContain('✓ math.test.ts')
10+
expect(vitest.stdout).toContain('2 passed')
11+
12+
// Regression #3642
13+
expect(vitest.stderr).not.toContain('close timed out')
14+
expect(vitest.stderr).toBe('')
15+
})

‎test/run/vitest.config.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
reporters: 'verbose',
6+
include: ['test/**/*.test.*'],
7+
chaiConfig: {
8+
truncateThreshold: 0,
9+
},
10+
testTimeout: process.env.CI ? 30_000 : 10_000,
11+
},
12+
})

0 commit comments

Comments
 (0)
Please sign in to comment.