1
1
import pathlib from 'path' ;
2
+ import { Command } from '@commander-js/extra-typings' ;
2
3
import { describe , expect , test , vi } from 'vitest' ;
3
4
import { testMocksDir } from '../../__tests__/fixtures.js' ;
4
5
import * as runner from '../../testing/runner.js' ;
5
6
import * as configs from '../../testing/utils.js' ;
6
- import { getTestCommand } from '../testing.js' ;
7
+ import { getTestCommand , silentOption } from '../testing.js' ;
7
8
import { getCommandRunner } from './testingUtils.js' ;
8
9
9
10
vi . spyOn ( process , 'cwd' ) . mockReturnValue ( testMocksDir ) ;
@@ -29,7 +30,15 @@ describe('Test regular test command', () => {
29
30
30
31
await expect ( runCommand ( '--project' , projectPath , filterPath ) ) . commandSuccess ( ) ;
31
32
expect ( configs . getTestConfiguration ) . toHaveBeenCalledExactlyOnceWith ( projectPath , false ) ;
32
- expect ( runner . runVitest ) . toHaveBeenCalledExactlyOnceWith ( 'test' , [ filterPath ] , [ mockConfig . config ] , { allowOnly : expect . any ( Boolean ) } ) ;
33
+ expect ( runner . runVitest ) . toHaveBeenCalledExactlyOnceWith (
34
+ 'test' ,
35
+ [ filterPath ] ,
36
+ [ mockConfig . config ] ,
37
+ {
38
+ allowOnly : expect . any ( Boolean ) ,
39
+ silent : 'passed-only'
40
+ }
41
+ ) ;
33
42
} ) ;
34
43
35
44
test ( 'Providing both the project directory but no patterns' , async ( ) => {
@@ -47,7 +56,15 @@ describe('Test regular test command', () => {
47
56
48
57
await expect ( runCommand ( '--project' , projectPath ) ) . commandSuccess ( ) ;
49
58
expect ( configs . getTestConfiguration ) . toHaveBeenCalledExactlyOnceWith ( projectPath , false ) ;
50
- expect ( runner . runVitest ) . toHaveBeenCalledExactlyOnceWith ( 'test' , [ ] , [ mockConfig . config ] , { allowOnly : expect . any ( Boolean ) } ) ;
59
+ expect ( runner . runVitest ) . toHaveBeenCalledExactlyOnceWith (
60
+ 'test' ,
61
+ [ ] ,
62
+ [ mockConfig . config ] ,
63
+ {
64
+ allowOnly : expect . any ( Boolean ) ,
65
+ silent : 'passed-only'
66
+ }
67
+ ) ;
51
68
} ) ;
52
69
53
70
test ( 'Expect command to exit with no issues if no tests were found' , async ( ) => {
@@ -81,7 +98,10 @@ describe('Test regular test command', () => {
81
98
'test' ,
82
99
[ ] ,
83
100
[ mockConfig . config ] ,
84
- { allowOnly : false }
101
+ {
102
+ allowOnly : false ,
103
+ silent : 'passed-only'
104
+ }
85
105
) ;
86
106
} ) ;
87
107
@@ -103,10 +123,63 @@ describe('Test regular test command', () => {
103
123
'test' ,
104
124
[ ] ,
105
125
[ mockConfig . config ] ,
106
- { allowOnly : false }
126
+ {
127
+ allowOnly : false ,
128
+ silent : 'passed-only'
129
+ }
107
130
) ;
108
131
} finally {
109
132
vi . unstubAllEnvs ( ) ;
110
133
}
111
134
} ) ;
112
135
} ) ;
136
+
137
+ describe ( 'Test silent option' , ( ) => {
138
+ const runCommand = ( ...args : string [ ] ) => new Promise < undefined | boolean | 'passed-only' > (
139
+ ( resolve , reject ) => {
140
+ const command = new Command ( )
141
+ . exitOverride ( )
142
+ . addOption ( silentOption )
143
+ . action ( option => {
144
+ resolve ( option . silent ) ;
145
+ } ) ;
146
+
147
+ try {
148
+ command . parse ( args , { from : 'user' } ) ;
149
+ } catch ( error ) {
150
+ reject ( error ) ;
151
+ }
152
+ }
153
+ ) ;
154
+
155
+ test ( 'running command without option' , async ( ) => {
156
+ const value = await runCommand ( ) ;
157
+ expect ( value ) . toEqual ( 'passed-only' ) ;
158
+ } ) ;
159
+
160
+ test ( 'running command with without value' , async ( ) => {
161
+ const value = await runCommand ( '--silent' ) ;
162
+ expect ( value ) . toEqual ( true ) ;
163
+ } ) ;
164
+
165
+ test ( 'running command with \'true\'' , async ( ) => {
166
+ const value = await runCommand ( '--silent' , 'true' ) ;
167
+ expect ( value ) . toEqual ( true ) ;
168
+ } ) ;
169
+
170
+ test ( 'running command with \'false\'' , async ( ) => {
171
+ const value = await runCommand ( '--silent' , 'false' ) ;
172
+ expect ( value ) . toEqual ( false ) ;
173
+ } ) ;
174
+
175
+ test ( 'running command with \'passed-only\'' , async ( ) => {
176
+ const value = await runCommand ( '--silent' , 'passed-only' ) ;
177
+ expect ( value ) . toEqual ( 'passed-only' ) ;
178
+ } ) ;
179
+
180
+ test ( 'running command with invalid option' , ( ) => {
181
+ return expect ( runCommand ( '--silent' , 'unknown' ) )
182
+ . rejects
183
+ . toThrowError ( 'Invalid value for silent: unknown' ) ;
184
+ } ) ;
185
+ } ) ;
0 commit comments