@@ -38,35 +38,30 @@ describe('resolveConfig', () => {
3838 outputFormat : 'pot' ,
3939 } ;
4040 let spies : SpyInstance [ ] ;
41- let processExitSpy : SpyInstance ;
42- let consoleLogSpy : SpyInstance ;
43- let defaultConfig = _defaultConfig ( ) ;
41+ const defaultConfig = _defaultConfig ( ) ;
4442
4543 beforeAll ( ( ) => {
4644 mockedGloblConfig = { } ;
47- processExitSpy = spyOnProcess ( 'exit' ) ;
48- consoleLogSpy = spyOnConsole ( 'log' ) ;
49- spies = [ processExitSpy , consoleLogSpy ] ;
45+ spies = [ spyOnProcess ( 'exit' ) , spyOnConsole ( 'log' ) ] ;
5046 } ) ;
5147
5248 afterAll ( ( ) => {
53- processExitSpy . mockRestore ( ) ;
54- consoleLogSpy . mockRestore ( ) ;
49+ spies . forEach ( ( s ) => s . mockRestore ( ) ) ;
5550 } ) ;
5651
5752 function resolvePath ( configPath : string [ ] ) : string [ ] ;
5853 function resolvePath ( configPath : string ) : string ;
5954 function resolvePath ( configPath : string , asArray : true ) : string [ ] ;
6055 function resolvePath ( configPath : string | string [ ] , asArray = false ) {
61- const resolve = ( p ) => path . resolve ( process . cwd ( ) , sourceRoot , p ) ;
56+ const resolve = ( p : string ) => path . resolve ( process . cwd ( ) , sourceRoot , p ) ;
6257 if ( Array . isArray ( configPath ) ) {
6358 return configPath . map ( resolve ) ;
6459 }
6560
6661 return asArray ? [ resolve ( configPath ) ] : resolve ( configPath ) ;
6762 }
6863
69- function assertConfig ( expected , inline = { } ) {
64+ function assertConfig < T > ( expected : T , inline = { } ) {
7065 const { scopes, ...config } = resolveConfig ( inline ) ;
7166 expect ( config ) . toEqual ( expected ) ;
7267 expect ( scopes ) . toBeDefined ( ) ;
@@ -142,6 +137,7 @@ describe('resolveConfig', () => {
142137
143138 describe ( 'validate directories' , ( ) => {
144139 function shouldFail ( prop : string , msg : 'pathDoesntExist' | 'pathIsNotDir' ) {
140+ const [ processExitSpy , consoleLogSpy ] = spies ;
145141 expect ( processExitSpy ) . toHaveBeenCalled ( ) ;
146142 expect ( consoleLogSpy ) . toHaveBeenCalledWith (
147143 chalk . bgRed . black ( `${ prop } ${ messages [ msg ] } ` ) ,
@@ -150,9 +146,7 @@ describe('resolveConfig', () => {
150146 }
151147
152148 function shouldPass ( ) {
153- [ processExitSpy , consoleLogSpy ] . forEach ( ( s ) =>
154- expect ( s ) . not . toHaveBeenCalled ( ) ,
155- ) ;
149+ spies . forEach ( ( s ) => expect ( s ) . not . toHaveBeenCalled ( ) ) ;
156150 clearSpies ( ) ;
157151 }
158152
@@ -169,8 +163,7 @@ describe('resolveConfig', () => {
169163 shouldFail ( 'Input' , 'pathIsNotDir' ) ;
170164 } ) ;
171165
172- it ( 'should fail on invalid translations path' , ( ) => {
173- /* should only fail translation path when in find mode */
166+ it ( 'should pass on invalid translations path in extract mode' , ( ) => {
174167 resolveConfig ( {
175168 input : [ 'src/folder' ] ,
176169 translationsPath : 'noFolder' ,
@@ -183,6 +176,9 @@ describe('resolveConfig', () => {
183176 command : 'extract' ,
184177 } ) ;
185178 shouldPass ( ) ;
179+ } ) ;
180+
181+ it ( 'should fail on invalid translations path in find mode' , ( ) => {
186182 resolveConfig ( {
187183 input : [ 'src/folder' ] ,
188184 translationsPath : 'noFolder' ,
@@ -201,12 +197,12 @@ describe('resolveConfig', () => {
201197 describe ( 'resolveConfigPaths' , ( ) => {
202198 it ( 'should prefix all the paths in the config with the process cwd' , ( ) => {
203199 const config = resolveConfig ( { input : [ 'folder' ] } ) ;
204- const assertPath = ( p ) =>
200+ const assertPath = ( p : string ) =>
205201 expect ( p . startsWith ( path . resolve ( process . cwd ( ) , sourceRoot ) ) ) . toBe (
206202 true ,
207203 ) ;
208204 config . input . forEach ( assertPath ) ;
209- [ 'output' , 'translationsPath' ] . forEach ( ( prop ) =>
205+ ( [ 'output' , 'translationsPath' ] as const ) . forEach ( ( prop ) =>
210206 assertPath ( config [ prop ] ) ,
211207 ) ;
212208 } ) ;
0 commit comments