@@ -38,35 +38,30 @@ describe('resolveConfig', () => {
38
38
outputFormat : 'pot' ,
39
39
} ;
40
40
let spies : SpyInstance [ ] ;
41
- let processExitSpy : SpyInstance ;
42
- let consoleLogSpy : SpyInstance ;
43
- let defaultConfig = _defaultConfig ( ) ;
41
+ const defaultConfig = _defaultConfig ( ) ;
44
42
45
43
beforeAll ( ( ) => {
46
44
mockedGloblConfig = { } ;
47
- processExitSpy = spyOnProcess ( 'exit' ) ;
48
- consoleLogSpy = spyOnConsole ( 'log' ) ;
49
- spies = [ processExitSpy , consoleLogSpy ] ;
45
+ spies = [ spyOnProcess ( 'exit' ) , spyOnConsole ( 'log' ) ] ;
50
46
} ) ;
51
47
52
48
afterAll ( ( ) => {
53
- processExitSpy . mockRestore ( ) ;
54
- consoleLogSpy . mockRestore ( ) ;
49
+ spies . forEach ( ( s ) => s . mockRestore ( ) ) ;
55
50
} ) ;
56
51
57
52
function resolvePath ( configPath : string [ ] ) : string [ ] ;
58
53
function resolvePath ( configPath : string ) : string ;
59
54
function resolvePath ( configPath : string , asArray : true ) : string [ ] ;
60
55
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 ) ;
62
57
if ( Array . isArray ( configPath ) ) {
63
58
return configPath . map ( resolve ) ;
64
59
}
65
60
66
61
return asArray ? [ resolve ( configPath ) ] : resolve ( configPath ) ;
67
62
}
68
63
69
- function assertConfig ( expected , inline = { } ) {
64
+ function assertConfig < T > ( expected : T , inline = { } ) {
70
65
const { scopes, ...config } = resolveConfig ( inline ) ;
71
66
expect ( config ) . toEqual ( expected ) ;
72
67
expect ( scopes ) . toBeDefined ( ) ;
@@ -142,6 +137,7 @@ describe('resolveConfig', () => {
142
137
143
138
describe ( 'validate directories' , ( ) => {
144
139
function shouldFail ( prop : string , msg : 'pathDoesntExist' | 'pathIsNotDir' ) {
140
+ const [ processExitSpy , consoleLogSpy ] = spies ;
145
141
expect ( processExitSpy ) . toHaveBeenCalled ( ) ;
146
142
expect ( consoleLogSpy ) . toHaveBeenCalledWith (
147
143
chalk . bgRed . black ( `${ prop } ${ messages [ msg ] } ` ) ,
@@ -150,9 +146,7 @@ describe('resolveConfig', () => {
150
146
}
151
147
152
148
function shouldPass ( ) {
153
- [ processExitSpy , consoleLogSpy ] . forEach ( ( s ) =>
154
- expect ( s ) . not . toHaveBeenCalled ( ) ,
155
- ) ;
149
+ spies . forEach ( ( s ) => expect ( s ) . not . toHaveBeenCalled ( ) ) ;
156
150
clearSpies ( ) ;
157
151
}
158
152
@@ -169,8 +163,7 @@ describe('resolveConfig', () => {
169
163
shouldFail ( 'Input' , 'pathIsNotDir' ) ;
170
164
} ) ;
171
165
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' , ( ) => {
174
167
resolveConfig ( {
175
168
input : [ 'src/folder' ] ,
176
169
translationsPath : 'noFolder' ,
@@ -183,6 +176,9 @@ describe('resolveConfig', () => {
183
176
command : 'extract' ,
184
177
} ) ;
185
178
shouldPass ( ) ;
179
+ } ) ;
180
+
181
+ it ( 'should fail on invalid translations path in find mode' , ( ) => {
186
182
resolveConfig ( {
187
183
input : [ 'src/folder' ] ,
188
184
translationsPath : 'noFolder' ,
@@ -201,12 +197,12 @@ describe('resolveConfig', () => {
201
197
describe ( 'resolveConfigPaths' , ( ) => {
202
198
it ( 'should prefix all the paths in the config with the process cwd' , ( ) => {
203
199
const config = resolveConfig ( { input : [ 'folder' ] } ) ;
204
- const assertPath = ( p ) =>
200
+ const assertPath = ( p : string ) =>
205
201
expect ( p . startsWith ( path . resolve ( process . cwd ( ) , sourceRoot ) ) ) . toBe (
206
202
true ,
207
203
) ;
208
204
config . input . forEach ( assertPath ) ;
209
- [ 'output' , 'translationsPath' ] . forEach ( ( prop ) =>
205
+ ( [ 'output' , 'translationsPath' ] as const ) . forEach ( ( prop ) =>
210
206
assertPath ( config [ prop ] ) ,
211
207
) ;
212
208
} ) ;
0 commit comments