6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
9
- /*global jest, jasmine, describe , it, expect, beforeEach*/
9
+ /*global jest, jasmine, xdescribe , it, expect, beforeEach*/
10
10
/*eslint camelcase: 0, no-unused-vars: 0*/
11
11
12
12
jest . autoMockOff ( ) ;
@@ -52,9 +52,9 @@ function run(args, stdin, cwd) {
52
52
describe ( 'jscodeshift CLI' , ( ) => {
53
53
54
54
it ( 'calls the transform and file information' , ( ) => {
55
- const sourceA = createTempFileWith ( 'a' ) ;
56
- const sourceB = createTempFileWith ( 'b\n' ) ;
57
- const sourceC = createTempFileWith ( 'c' ) ;
55
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js' ) ;
56
+ const sourceB = createTempFileWith ( 'b\n' , 'sourceB' , '.js' ) ;
57
+ const sourceC = createTempFileWith ( 'c' , 'sourceC' , '.js' ) ;
58
58
const transformA = createTransformWith (
59
59
'return "transform" + fileInfo.source;'
60
60
) ;
@@ -80,9 +80,9 @@ describe('jscodeshift CLI', () => {
80
80
} ) ;
81
81
82
82
it ( 'takes file list from stdin if --stdin is set' , ( ) => {
83
- const sourceA = createTempFileWith ( 'a' ) ;
84
- const sourceB = createTempFileWith ( 'b\n' ) ;
85
- const sourceC = createTempFileWith ( 'c' ) ;
83
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js' ) ;
84
+ const sourceB = createTempFileWith ( 'b\n' , 'sourceB' , '.js' ) ;
85
+ const sourceC = createTempFileWith ( 'c' , 'sourceC' , '.js' ) ;
86
86
const transformA = createTransformWith (
87
87
'return "transform" + fileInfo.source;'
88
88
) ;
@@ -98,13 +98,13 @@ describe('jscodeshift CLI', () => {
98
98
} ) ;
99
99
100
100
it ( 'does not transform files in a dry run' , ( ) => {
101
- const source = createTempFileWith ( 'a' ) ;
101
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
102
102
const transform = createTransformWith (
103
103
'return "transform" + fileInfo.source;'
104
104
) ;
105
- return run ( [ '-t' , transform , '-d' , source ] ) . then (
105
+ return run ( [ '-t' , transform , '-d' , sourceA ] ) . then (
106
106
( ) => {
107
- expect ( readFile ( source ) . toString ( ) ) . toBe ( 'a' ) ;
107
+ expect ( readFile ( sourceA ) . toString ( ) ) . toBe ( 'a' ) ;
108
108
}
109
109
) ;
110
110
} ) ;
@@ -113,14 +113,14 @@ describe('jscodeshift CLI', () => {
113
113
114
114
// Verifiers that ES6 features are supported either natively or via Babel
115
115
it ( 'supports ES6 features in transform files' , ( ) => {
116
- const source = createTempFileWith ( 'a' ) ;
116
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
117
117
const transform = createTransformWith (
118
118
'const a = 42; return a;'
119
119
) ;
120
120
return Promise . all ( [
121
- run ( [ '-t' , transform , source ] ) . then (
121
+ run ( [ '-t' , transform , sourceA ] ) . then (
122
122
( ) => {
123
- expect ( readFile ( source ) . toString ( ) )
123
+ expect ( readFile ( sourceA ) . toString ( ) )
124
124
. toEqual ( '42' ) ;
125
125
}
126
126
) ,
@@ -129,70 +129,70 @@ describe('jscodeshift CLI', () => {
129
129
130
130
// Verifies that spread is supported, either natively over via Babel
131
131
it ( 'supports property spread in transform files' , ( ) => {
132
- const source = createTempFileWith ( 'a' ) ;
132
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
133
133
const transform = createTransformWith (
134
134
'const a = {...{foo: 42}, bar: 21}; return a.foo;'
135
135
) ;
136
136
return Promise . all ( [
137
- run ( [ '-t' , transform , source ] ) . then (
137
+ run ( [ '-t' , transform , sourceA ] ) . then (
138
138
( ) => {
139
- expect ( readFile ( source ) . toString ( ) )
139
+ expect ( readFile ( sourceA ) . toString ( ) )
140
140
. toEqual ( '42' ) ;
141
141
}
142
142
) ,
143
143
] ) ;
144
144
} ) ;
145
145
146
146
it ( 'supports class properties in transform files' , ( ) => {
147
- const source = createTempFileWith ( 'a' ) ;
147
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
148
148
const transform = createTransformWith ( `
149
149
return (class {
150
150
x = 42;
151
151
}).toString();
152
152
` ) ;
153
153
return Promise . all ( [
154
- run ( [ '-t' , transform , source ] ) . then (
154
+ run ( [ '-t' , transform , sourceA ] ) . then (
155
155
( ) => {
156
- expect ( readFile ( source ) . toString ( ) )
156
+ expect ( readFile ( sourceA ) . toString ( ) )
157
157
. toMatch ( / \( t h i s , \s * [ ' " ] x [ ' " ] / ) ;
158
158
}
159
159
) ,
160
160
] ) ;
161
161
} ) ;
162
162
163
163
it ( 'supports flow type annotations in transform files' , ( ) => {
164
- const source = createTempFileWith ( 'a' ) ;
164
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
165
165
const transform = createTransformWith (
166
166
'return (function() { "use strict"; const a: number = 42; }).toString();'
167
167
) ;
168
168
return Promise . all ( [
169
- run ( [ '-t' , transform , source ] ) . then (
169
+ run ( [ '-t' , transform , sourceA ] ) . then (
170
170
( ) => {
171
- expect ( readFile ( source ) . toString ( ) )
171
+ expect ( readFile ( sourceA ) . toString ( ) )
172
172
. toMatch ( / a \s * = \s * 4 2 / ) ;
173
173
}
174
174
) ,
175
175
] ) ;
176
176
} ) ;
177
177
178
178
it ( 'supports Typescript type annotations in transform files' , ( ) => {
179
- const source = createTempFileWith ( 'a' ) ;
179
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
180
180
const transform = createTransformWith (
181
181
'return (function() { "use strict"; function foo(x: string): x is string {}}).toString();' ,
182
182
'.ts'
183
183
) ;
184
184
return Promise . all ( [
185
- run ( [ '-t' , transform , source ] ) . then (
185
+ run ( [ '-t' , transform , sourceA ] ) . then (
186
186
args => {
187
- expect ( readFile ( source ) . toString ( ) )
187
+ expect ( readFile ( sourceA ) . toString ( ) )
188
188
. toMatch ( / f u n c t i o n \s + f o o \( x \) \s * { } / ) ;
189
189
}
190
190
) ,
191
191
] ) ;
192
192
} ) ;
193
193
194
194
it ( 'transpiles imported Typescript files in transform files' , ( ) => {
195
- const source = createTempFileWith ( 'a' ) ;
195
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
196
196
const helper = createTempFileWith (
197
197
'module.exports = function(x: string): x is string {};' ,
198
198
undefined ,
@@ -203,9 +203,9 @@ describe('jscodeshift CLI', () => {
203
203
'.ts'
204
204
) ;
205
205
return Promise . all ( [
206
- run ( [ '-t' , transform , source ] ) . then (
206
+ run ( [ '-t' , transform , sourceA ] ) . then (
207
207
args => {
208
- expect ( readFile ( source ) . toString ( ) )
208
+ expect ( readFile ( sourceA ) . toString ( ) )
209
209
. toMatch ( / f u n c t i o n \s * \( x \) \s * { } / ) ;
210
210
}
211
211
) ,
@@ -215,26 +215,26 @@ describe('jscodeshift CLI', () => {
215
215
} ) ;
216
216
217
217
it ( 'passes jscodeshift and stats the transform function' , ( ) => {
218
- const source = createTempFileWith ( 'a' ) ;
218
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
219
219
const transform = createTransformWith ( [
220
220
' return String(' ,
221
221
' typeof api.jscodeshift === "function" &&' ,
222
222
' typeof api.stats === "function"' ,
223
223
' );' ,
224
224
] . join ( '\n' ) ) ;
225
- return run ( [ '-t' , transform , source ] ) . then (
225
+ return run ( [ '-t' , transform , sourceA ] ) . then (
226
226
( ) => {
227
- expect ( readFile ( source ) . toString ( ) ) . toBe ( 'true' ) ;
227
+ expect ( readFile ( sourceA ) . toString ( ) ) . toBe ( 'true' ) ;
228
228
}
229
229
) ;
230
230
} ) ;
231
231
232
232
it ( 'passes options along to the transform' , ( ) => {
233
- const source = createTempFileWith ( 'a' ) ;
233
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
234
234
const transform = createTransformWith ( 'return options.foo;' ) ;
235
- return run ( [ '-t' , transform , '--foo=42' , source ] ) . then (
235
+ return run ( [ '-t' , transform , '--foo=42' , sourceA ] ) . then (
236
236
( ) => {
237
- expect ( readFile ( source ) . toString ( ) ) . toBe ( '42' ) ;
237
+ expect ( readFile ( sourceA ) . toString ( ) ) . toBe ( '42' ) ;
238
238
}
239
239
) ;
240
240
} ) ;
@@ -259,8 +259,10 @@ describe('jscodeshift CLI', () => {
259
259
260
260
beforeEach ( ( ) => {
261
261
sources = [ ] ;
262
- sources . push ( createTempFileWith ( 'a' , 'a.js' ) ) ;
263
- sources . push ( createTempFileWith ( 'a' , 'a-test.js' ) ) ;
262
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js' ) ;
263
+ const testIgnoreFile = createTempFileWith ( 'a' , 'a-test' , '.js' ) ;
264
+ sources . push ( sourceA ) ;
265
+ sources . push ( testIgnoreFile ) ;
264
266
// sources.push(createTempFileWith('b', 'src/lib/b.js'));
265
267
} ) ;
266
268
@@ -275,7 +277,7 @@ describe('jscodeshift CLI', () => {
275
277
} ) ;
276
278
277
279
it ( 'supports filename match' , ( ) => {
278
- const pattern = 'a .js' ;
280
+ const pattern = 'sourceA .js' ;
279
281
return run ( [ '-t' , transform , '--ignore-pattern' , pattern ] . concat ( sources ) ) . then (
280
282
( ) => {
281
283
expect ( readFile ( sources [ 0 ] ) . toString ( ) ) . toBe ( 'a' ) ;
@@ -285,7 +287,7 @@ describe('jscodeshift CLI', () => {
285
287
} ) ;
286
288
287
289
it ( 'accepts a list of patterns' , ( ) => {
288
- const patterns = [ '--ignore-pattern' , 'a .js' , '--ignore-pattern' , '*-test.js' ] ;
290
+ const patterns = [ '--ignore-pattern' , 'sourceA .js' , '--ignore-pattern' , '*-test.js' ] ;
289
291
return run ( [ '-t' , transform ] . concat ( patterns ) . concat ( sources ) ) . then (
290
292
( ) => {
291
293
expect ( readFile ( sources [ 0 ] ) . toString ( ) ) . toBe ( 'a' ) ;
@@ -310,7 +312,7 @@ describe('jscodeshift CLI', () => {
310
312
311
313
it ( 'accepts a list of configuration files' , ( ) => {
312
314
const gitignore = createTempFileWith ( [ 'sub/dir/' ] . join ( '\n' ) , '.gitignore' ) ;
313
- const eslintignore = createTempFileWith ( [ '**/*test.js' , 'a .js' ] . join ( '\n' ) , '.eslintignore' ) ;
315
+ const eslintignore = createTempFileWith ( [ '**/*test.js' , 'sourceA .js' ] . join ( '\n' ) , '.eslintignore' ) ;
314
316
const configs = [ '--ignore-config' , gitignore , '--ignore-config' , eslintignore ] ;
315
317
sources . push ( createTempFileWith ( 'subfile' , 'sub/dir/file.js' ) ) ;
316
318
@@ -326,9 +328,9 @@ describe('jscodeshift CLI', () => {
326
328
327
329
describe ( 'output' , ( ) => {
328
330
it ( 'shows workers info and stats at the end by default' , ( ) => {
329
- const source = createTempFileWith ( 'a' ) ;
331
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
330
332
const transform = createTransformWith ( 'return null;' ) ;
331
- return run ( [ '-t' , transform , source ] ) . then (
333
+ return run ( [ '-t' , transform , sourceA ] ) . then (
332
334
out => {
333
335
expect ( out [ 0 ] ) . toContain ( 'Processing 1 files...' ) ;
334
336
expect ( out [ 0 ] ) . toContain ( 'Spawning 1 workers...' ) ;
@@ -341,21 +343,22 @@ describe('jscodeshift CLI', () => {
341
343
} ) ;
342
344
343
345
it ( 'does not ouput anything in silent mode' , ( ) => {
344
- const source = createTempFileWith ( 'a' ) ;
346
+ const sourceA = createTempFileWith ( 'a' , 'sourceA' , '.js ') ;
345
347
const transform = createTransformWith ( 'return null;' ) ;
346
- return run ( [ '-t' , transform , '-s' , source ] ) . then (
348
+ return run ( [ '-t' , transform , '-s' , sourceA ] ) . then (
347
349
out => {
348
350
expect ( out [ 0 ] ) . toEqual ( '' ) ;
349
351
}
350
352
) ;
351
353
} ) ;
352
354
} ) ;
353
355
354
- describe ( '--parser=ts' , ( ) => {
356
+ xdescribe ( '--parser=ts' , ( ) => {
355
357
it ( 'parses TypeScript sources' , ( ) => {
356
- const source = createTempFileWith ( 'type Foo = string | string[];' ) ;
358
+ const source = createTempFileWith ( 'type Foo = string | string[];' , 'source' , '.ts' ) ;
359
+
357
360
const transform = createTransformWith (
358
- 'api.jscodeshift(fileInfo.source)\nreturn "changed";'
361
+ 'api.jscodeshift(fileInfo.source)\n { return "changed" } ;'
359
362
) ;
360
363
return run ( [
361
364
'-t' , transform ,
@@ -375,7 +378,7 @@ describe('jscodeshift CLI', () => {
375
378
it ( 'allows custom parser settings to be passed' , ( ) => {
376
379
// @decorators before export are not supported in the current default
377
380
// config
378
- const source = createTempFileWith ( '@foo\nexport class Bar {}' ) ;
381
+ const source = createTempFileWith ( '@foo\nexport class Bar {}' , 'source' , '.js' ) ;
379
382
const parserConfig = createTempFileWith ( JSON . stringify ( {
380
383
sourceType : 'module' ,
381
384
tokens : true ,
@@ -384,7 +387,7 @@ describe('jscodeshift CLI', () => {
384
387
] ,
385
388
} ) ) ;
386
389
const transform = createTransformWith (
387
- 'api.jscodeshift(fileInfo.source)\nreturn "changed";'
390
+ 'api.jscodeshift(fileInfo.source)\n { return "changed" } ;'
388
391
) ;
389
392
return run ( [
390
393
'-t' , transform ,
0 commit comments