1- import { join } from 'node:path'
1+ import { sep } from 'node:path'
22import { run } from 'jscodeshift/src/Runner'
33import prompts from 'prompts'
44import { transform } from '../transform'
55
6+ const defaultOptions = {
7+ dry : true ,
8+ silent : true ,
9+ }
10+
11+ const getSystemPath = ( inputPath : string ) => inputPath . replaceAll ( '/' , sep )
12+
613jest . mock ( 'jscodeshift/src/Runner' , ( ) => ( {
714 run : jest . fn ( ) ,
815} ) )
@@ -18,13 +25,13 @@ describe('interactive mode', () => {
1825 prompts . inject ( [ 'magic-redirect' ] )
1926 prompts . inject ( [ './transforms/__testfixtures__' ] )
2027
21- await transform ( undefined , undefined , { dry : true , silent : true } )
28+ await transform ( undefined , undefined , defaultOptions )
2229
2330 expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
2431 expect ( run ) . toHaveBeenCalledTimes ( 1 )
2532 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__') ) ] ) ,
2835 {
2936 babel : false ,
3037 dry : true ,
@@ -41,16 +48,13 @@ describe('interactive mode', () => {
4148
4249 prompts . inject ( [ 'magic-redirect' ] )
4350
44- await transform ( 'bad-codemod' , './transforms/__testfixtures__' , {
45- dry : true ,
46- silent : true ,
47- } )
51+ await transform ( 'bad-codemod' , './transforms/__testfixtures__' , defaultOptions )
4852
4953 expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
5054 expect ( run ) . toHaveBeenCalledTimes ( 1 )
5155 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__') ) ] ) ,
5458 {
5559 babel : false ,
5660 dry : true ,
@@ -67,21 +71,22 @@ describe('interactive mode', () => {
6771
6872 prompts . inject ( [ '__testfixtures__' ] )
6973
70- await transform ( 'magic-redirect' , undefined , {
71- dry : true ,
72- silent : true ,
73- } )
74+ await transform ( 'magic-redirect' , undefined , defaultOptions )
7475
7576 expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
7677 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+ )
8590 } )
8691} )
8792
@@ -93,20 +98,21 @@ describe('Non-Interactive Mode', () => {
9398 it ( 'Transforms code with codemodName and source params provided' , async ( ) => {
9499 const spyOnConsole = jest . spyOn ( console , 'log' ) . mockImplementation ( )
95100
96- await transform ( 'magic-redirect' , '__testfixtures__' , {
97- dry : true ,
98- silent : true ,
99- } )
101+ await transform ( 'magic-redirect' , '__testfixtures__' , defaultOptions )
100102
101103 expect ( spyOnConsole ) . not . toHaveBeenCalled ( )
102104 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+ )
111117 } )
112118} )
0 commit comments