@@ -172,17 +172,45 @@ test('missingConfigurationPrompt does run config if user agrees', async () => {
172
172
expect ( runConfigCmd ) . toBeCalledTimes ( 1 )
173
173
} )
174
174
175
- test ( 'canAccessConfigPath' , async ( ) => {
176
- vi . mocked ( fs . access )
177
- . mockRejectedValueOnce ( new Error ( 'not found' ) )
178
- . mockRejectedValueOnce ( new Error ( 'not found' ) )
179
- . mockRejectedValueOnce ( new Error ( 'not found' ) )
180
- . mockResolvedValue ( 'Yay' as any )
181
- expect ( await canAccessConfigPath ( '/foo/bar' ) ) . toBe ( '/foo/bar.mts' )
182
- expect ( fs . access ) . toBeCalledWith ( '/foo/bar.js' )
183
- expect ( fs . access ) . toBeCalledWith ( '/foo/bar.ts' )
184
- expect ( fs . access ) . toBeCalledWith ( '/foo/bar.mjs' )
185
- expect ( fs . access ) . toBeCalledWith ( '/foo/bar.mts' )
175
+ describe ( 'canAccessConfigPath' , ( ) => {
176
+ beforeEach ( ( ) => {
177
+ vi . mocked ( fs . access ) . mockClear ( )
178
+ } )
179
+ test ( 'no extension only' , async ( ) => {
180
+ vi . mocked ( fs . access )
181
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
182
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
183
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
184
+ . mockResolvedValue ( 'Yay' as any )
185
+ expect ( await canAccessConfigPath ( '/foo/bar' ) ) . toBe ( '/foo/bar.mts' )
186
+ expect ( fs . access ) . not . toBeCalledWith ( '/foo/bar' )
187
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.js' )
188
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.ts' )
189
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.mjs' )
190
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.mts' )
191
+ } )
192
+
193
+ test ( 'with full path of the existed file' , async ( ) => {
194
+ vi . mocked ( fs . access )
195
+ . mockResolvedValue ( 'Yay' as any )
196
+ expect ( await canAccessConfigPath ( '/foo/bar' , '/foo/bar.ts' ) ) . toBe ( '/foo/bar.ts' )
197
+ expect ( fs . access ) . toHaveBeenCalledTimes ( 1 )
198
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.ts' )
199
+ } )
200
+
201
+ test ( 'with full path of the not existed file' , async ( ) => {
202
+ vi . mocked ( fs . access )
203
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
204
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
205
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
206
+ . mockRejectedValueOnce ( new Error ( 'not found' ) )
207
+ . mockResolvedValue ( 'Yay' as any )
208
+ expect ( await canAccessConfigPath ( '/foo/bar' , '/foo/bar.ts' ) ) . toBe ( '/foo/bar.mts' )
209
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.js' )
210
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.ts' )
211
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.mjs' )
212
+ expect ( fs . access ) . toBeCalledWith ( '/foo/bar.mts' )
213
+ } )
186
214
} )
187
215
188
216
describe ( 'Serenity/JS project generation' , ( ) => {
0 commit comments