1
- import { join } from 'node:path'
1
+ import { sep } from 'node:path'
2
2
import { run } from 'jscodeshift/src/Runner'
3
3
import prompts from 'prompts'
4
4
import { transform } from '../transform'
5
5
6
+ const defaultOptions = {
7
+ dry : true ,
8
+ silent : true ,
9
+ }
10
+
11
+ const getSystemPath = ( inputPath : string ) => inputPath . replaceAll ( '/' , sep )
12
+
6
13
jest . mock ( 'jscodeshift/src/Runner' , ( ) => ( {
7
14
run : jest . fn ( ) ,
8
15
} ) )
@@ -18,13 +25,13 @@ describe('interactive mode', () => {
18
25
prompts . inject ( [ 'magic-redirect' ] )
19
26
prompts . inject ( [ './transforms/__testfixtures__' ] )
20
27
21
- await transform ( undefined , undefined , { dry : true , silent : true } )
28
+ await transform ( undefined , undefined , defaultOptions )
22
29
23
30
expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
24
31
expect ( run ) . toHaveBeenCalledTimes ( 1 )
25
32
expect ( run ) . toHaveBeenCalledWith (
26
- join ( __dirname , '../../' , ' transforms/magic-redirect.js') ,
27
- [ '. /transforms/__testfixtures__'] ,
33
+ expect . stringContaining ( getSystemPath ( '/ transforms/magic-redirect.js') ) ,
34
+ expect . arrayContaining ( [ expect . stringContaining ( getSystemPath ( ' /transforms/__testfixtures__') ) ] ) ,
28
35
{
29
36
babel : false ,
30
37
dry : true ,
@@ -41,16 +48,13 @@ describe('interactive mode', () => {
41
48
42
49
prompts . inject ( [ 'magic-redirect' ] )
43
50
44
- await transform ( 'bad-codemod' , './transforms/__testfixtures__' , {
45
- dry : true ,
46
- silent : true ,
47
- } )
51
+ await transform ( 'bad-codemod' , './transforms/__testfixtures__' , defaultOptions )
48
52
49
53
expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
50
54
expect ( run ) . toHaveBeenCalledTimes ( 1 )
51
55
expect ( run ) . toHaveBeenCalledWith (
52
- join ( __dirname , '../../' , ' transforms/magic-redirect.js') ,
53
- [ '. /transforms/__testfixtures__'] ,
56
+ expect . stringContaining ( getSystemPath ( '/ transforms/magic-redirect.js') ) ,
57
+ expect . arrayContaining ( [ expect . stringContaining ( getSystemPath ( ' /transforms/__testfixtures__') ) ] ) ,
54
58
{
55
59
babel : false ,
56
60
dry : true ,
@@ -67,21 +71,22 @@ describe('interactive mode', () => {
67
71
68
72
prompts . inject ( [ '__testfixtures__' ] )
69
73
70
- await transform ( 'magic-redirect' , undefined , {
71
- dry : true ,
72
- silent : true ,
73
- } )
74
+ await transform ( 'magic-redirect' , undefined , defaultOptions )
74
75
75
76
expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
76
77
expect ( run ) . toHaveBeenCalledTimes ( 1 )
77
- expect ( run ) . toHaveBeenCalledWith ( join ( __dirname , '../../' , 'transforms/magic-redirect.js' ) , [ '__testfixtures__' ] , {
78
- babel : false ,
79
- dry : true ,
80
- extensions : 'cts,mts,ts,js,mjs,cjs' ,
81
- ignorePattern : '**/node_modules/**' ,
82
- silent : true ,
83
- verbose : 0 ,
84
- } )
78
+ expect ( run ) . toHaveBeenCalledWith (
79
+ expect . stringContaining ( getSystemPath ( '/transforms/magic-redirect.js' ) ) ,
80
+ expect . arrayContaining ( [ expect . stringContaining ( '__testfixtures__' ) ] ) ,
81
+ {
82
+ babel : false ,
83
+ dry : true ,
84
+ extensions : 'cts,mts,ts,js,mjs,cjs' ,
85
+ ignorePattern : '**/node_modules/**' ,
86
+ silent : true ,
87
+ verbose : 0 ,
88
+ } ,
89
+ )
85
90
} )
86
91
} )
87
92
@@ -93,20 +98,21 @@ describe('Non-Interactive Mode', () => {
93
98
it ( 'Transforms code with codemodName and source params provided' , async ( ) => {
94
99
const spyOnConsole = jest . spyOn ( console , 'log' ) . mockImplementation ( )
95
100
96
- await transform ( 'magic-redirect' , '__testfixtures__' , {
97
- dry : true ,
98
- silent : true ,
99
- } )
101
+ await transform ( 'magic-redirect' , '__testfixtures__' , defaultOptions )
100
102
101
103
expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
102
104
expect ( run ) . toHaveBeenCalledTimes ( 1 )
103
- expect ( run ) . toHaveBeenCalledWith ( join ( __dirname , '../../' , 'transforms/magic-redirect.js' ) , [ '__testfixtures__' ] , {
104
- babel : false ,
105
- dry : true ,
106
- extensions : 'cts,mts,ts,js,mjs,cjs' ,
107
- ignorePattern : '**/node_modules/**' ,
108
- silent : true ,
109
- verbose : 0 ,
110
- } )
105
+ expect ( run ) . toHaveBeenCalledWith (
106
+ expect . stringContaining ( getSystemPath ( '/transforms/magic-redirect.js' ) ) ,
107
+ expect . arrayContaining ( [ expect . stringContaining ( '__testfixtures__' ) ] ) ,
108
+ {
109
+ babel : false ,
110
+ dry : true ,
111
+ extensions : 'cts,mts,ts,js,mjs,cjs' ,
112
+ ignorePattern : '**/node_modules/**' ,
113
+ silent : true ,
114
+ verbose : 0 ,
115
+ } ,
116
+ )
111
117
} )
112
118
} )
0 commit comments