@@ -3,7 +3,22 @@ import os from 'os';
3
3
import path from 'path' ;
4
4
import { mockProcessStdout } from 'jest-mock-process' ;
5
5
import main from '@/bin/typescript-demo-lib' ;
6
- import { sleep } from '@/utils' ;
6
+
7
+ if ( process . stdout . isTTY ) {
8
+ // @ts -ignore
9
+ process . stdout . _handle . setBlocking ( true ) ;
10
+ } else if ( os . platform ( ) === 'win32' && ! process . stdout . isTTY ) {
11
+ // @ts -ignore
12
+ process . stdout . _handle . setBlocking ( false ) ;
13
+ }
14
+
15
+ if ( process . stderr . isTTY ) {
16
+ // @ts -ignore
17
+ process . stderr . _handle . setBlocking ( true ) ;
18
+ } else if ( os . platform ( ) === 'win32' && ! process . stderr . isTTY ) {
19
+ // @ts -ignore
20
+ process . stderr . _handle . setBlocking ( false ) ;
21
+ }
7
22
8
23
const uuidRegex = new RegExp (
9
24
'[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}' ,
@@ -26,7 +41,6 @@ describe('main', () => {
26
41
const mockLog = mockProcessStdout ( ) ;
27
42
expect ( await main ( [ '' , '' , '1' , '2' , dataDir ] ) ) . toEqual ( 0 ) ;
28
43
mockLog . mockRestore ( ) ;
29
- await sleep ( 2000 ) ;
30
44
} ) ;
31
45
test ( 'no input' , async ( ) => {
32
46
const mockLog = mockProcessStdout ( ) ;
@@ -47,7 +61,6 @@ describe('main', () => {
47
61
expect ( tmpMockLog ) . toMatch ( uuidRegex ) ;
48
62
expect ( tmpMockLog ) . toContain ( '0 + 0 = 0\n' ) ;
49
63
mockLog . mockRestore ( ) ;
50
- await sleep ( 2000 ) ;
51
64
} ) ;
52
65
test ( 'adds 0 + 1' , async ( ) => {
53
66
const mockLog = mockProcessStdout ( ) ;
@@ -58,7 +71,6 @@ describe('main', () => {
58
71
expect ( tmpMockLog ) . toMatch ( uuidRegex ) ;
59
72
expect ( tmpMockLog ) . toContain ( '0 + 1 = 1\n' ) ;
60
73
mockLog . mockRestore ( ) ;
61
- await sleep ( 2000 ) ;
62
74
} ) ;
63
75
test ( 'adds 1 + 0' , async ( ) => {
64
76
const mockLog = mockProcessStdout ( ) ;
@@ -69,7 +81,6 @@ describe('main', () => {
69
81
expect ( tmpMockLog ) . toMatch ( uuidRegex ) ;
70
82
expect ( tmpMockLog ) . toContain ( '1 + 0 = 1\n' ) ;
71
83
mockLog . mockRestore ( ) ;
72
- await sleep ( 2000 ) ;
73
84
} ) ;
74
85
test ( 'adds 7657 + 238947' , async ( ) => {
75
86
const mockLog = mockProcessStdout ( ) ;
@@ -80,6 +91,5 @@ describe('main', () => {
80
91
expect ( tmpMockLog ) . toMatch ( uuidRegex ) ;
81
92
expect ( tmpMockLog ) . toContain ( '7657 + 238947 = 246604\n' ) ;
82
93
mockLog . mockRestore ( ) ;
83
- await sleep ( 2000 ) ;
84
94
} ) ;
85
95
} ) ;
0 commit comments