1
+ import { describe , it , beforeEach , afterEach } from 'node:test' ;
1
2
import assert from 'node:assert' ;
2
3
3
4
import CLI from '../../lib/cli.js' ;
@@ -40,6 +41,8 @@ describe('cli', () => {
40
41
41
42
describe ( 'spinners' , ( ) => {
42
43
beforeEach ( ( ) => {
44
+ stream = new LogStream ( ) ;
45
+ cli = new CLI ( stream ) ;
43
46
cli . startSpinner ( 'foo' ) ;
44
47
} ) ;
45
48
@@ -58,20 +61,34 @@ describe('cli', () => {
58
61
} ) ;
59
62
60
63
describe ( 'write' , ( ) => {
64
+ beforeEach ( ( ) => {
65
+ stream = new LogStream ( ) ;
66
+ cli = new CLI ( stream ) ;
67
+ } ) ;
61
68
it ( 'should write in stream' , ( ) => {
69
+ const stream = new LogStream ( ) ;
70
+ const cli = new CLI ( stream ) ;
62
71
cli . write ( 'Getting commits...' ) ;
63
- assert . strictEqual ( logResult ( ) , 'Getting commits...' ) ;
72
+ assert . strictEqual ( strip ( stream . toString ( ) ) , 'Getting commits...' ) ;
64
73
} ) ;
65
74
} ) ;
66
75
67
76
describe ( 'log' , ( ) => {
77
+ beforeEach ( ( ) => {
78
+ stream = new LogStream ( ) ;
79
+ cli = new CLI ( stream ) ;
80
+ } ) ;
68
81
it ( 'should write in stream' , ( ) => {
69
82
cli . log ( 'Getting commits...' ) ;
70
83
assert . strictEqual ( logResult ( ) , 'Getting commits...\n' ) ;
71
84
} ) ;
72
85
} ) ;
73
86
74
87
describe ( 'table' , ( ) => {
88
+ beforeEach ( ( ) => {
89
+ stream = new LogStream ( ) ;
90
+ cli = new CLI ( stream ) ;
91
+ } ) ;
75
92
it ( 'should print the first element with bold style and padding' , ( ) => {
76
93
cli . table ( 'Title' , 'description' ) ;
77
94
assert . strictEqual ( logResult ( ) ,
@@ -80,6 +97,10 @@ describe('cli', () => {
80
97
} ) ;
81
98
82
99
describe ( 'separator' , ( ) => {
100
+ beforeEach ( ( ) => {
101
+ stream = new LogStream ( ) ;
102
+ cli = new CLI ( stream ) ;
103
+ } ) ;
83
104
it ( 'should print a separator line with the specified text' , ( ) => {
84
105
cli . separator ( 'Separator' ) ;
85
106
assert . strictEqual (
@@ -105,6 +126,10 @@ describe('cli', () => {
105
126
} ) ;
106
127
107
128
describe ( 'ok' , ( ) => {
129
+ beforeEach ( ( ) => {
130
+ stream = new LogStream ( ) ;
131
+ cli = new CLI ( stream ) ;
132
+ } ) ;
108
133
it ( 'should print a success message' , ( ) => {
109
134
cli . ok ( 'Perfect!' ) ;
110
135
assert . strictEqual ( logResult ( ) , ` ${ success } Perfect!\n` ) ;
@@ -118,6 +143,10 @@ describe('cli', () => {
118
143
} ) ;
119
144
120
145
describe ( 'warn' , ( ) => {
146
+ beforeEach ( ( ) => {
147
+ stream = new LogStream ( ) ;
148
+ cli = new CLI ( stream ) ;
149
+ } ) ;
121
150
it ( 'should print a warning message' , ( ) => {
122
151
cli . warn ( 'Warning!' ) ;
123
152
assert . strictEqual ( logResult ( ) , ` ${ warning } Warning!\n` ) ;
@@ -131,6 +160,10 @@ describe('cli', () => {
131
160
} ) ;
132
161
133
162
describe ( 'info' , ( ) => {
163
+ beforeEach ( ( ) => {
164
+ stream = new LogStream ( ) ;
165
+ cli = new CLI ( stream ) ;
166
+ } ) ;
134
167
it ( 'should print an info message' , ( ) => {
135
168
cli . info ( 'Info!' ) ;
136
169
assert . strictEqual ( logResult ( ) , ` ${ info } Info!\n` ) ;
@@ -143,6 +176,10 @@ describe('cli', () => {
143
176
} ) ;
144
177
145
178
describe ( 'error' , ( ) => {
179
+ beforeEach ( ( ) => {
180
+ stream = new LogStream ( ) ;
181
+ cli = new CLI ( stream ) ;
182
+ } ) ;
146
183
it ( 'should print an error message' , ( ) => {
147
184
cli . error ( 'Error!' ) ;
148
185
assert . strictEqual ( logResult ( ) , ` ${ error } Error!\n` ) ;
@@ -183,6 +220,7 @@ describe('cli', () => {
183
220
questionType : cli . QUESTION_TYPE . INPUT
184
221
} ) ;
185
222
assert . strictEqual ( cli . spinner . isSpinning , true ) ;
223
+ cli . stopSpinner ( 'foo' ) ;
186
224
} ) ;
187
225
} ) ;
188
226
0 commit comments