@@ -15,16 +15,14 @@ describe('main', () => {
1515 ( PluginManager as jest . Mock ) . mockReturnValue ( {
1616 install : ( ) => Promise . resolve ( undefined ) ,
1717 require : ( codemodName : string ) => ( {
18- default : {
19- transforms : {
20- '18.0.0' : `${ codemodName } /path/to/18.js` ,
21- '19.0.0' : `${ codemodName } /path/to/19.js` ,
22- '20.0.0' : `${ codemodName } /path/to/20.js` ,
23- } ,
24- presets : {
25- 'update-formatting' : `${ codemodName } /path/to/update-formatting.js` ,
26- 'update-imports' : `${ codemodName } /path/to/update-imports.js` ,
27- } ,
18+ transforms : {
19+ '18.0.0' : `${ codemodName } /path/to/18.js` ,
20+ '19.0.0' : `${ codemodName } /path/to/19.js` ,
21+ '20.0.0' : `${ codemodName } /path/to/20.js` ,
22+ } ,
23+ presets : {
24+ 'update-formatting' : `${ codemodName } /path/to/update-formatting.js` ,
25+ 'update-imports' : `${ codemodName } /path/to/update-imports.js` ,
2826 } ,
2927 } ) ,
3028 uninstallAll : ( ) => Promise . resolve ( ) ,
@@ -333,10 +331,8 @@ describe('main', () => {
333331 ( PluginManager as jest . Mock ) . mockReturnValue ( {
334332 install : ( ) => Promise . resolve ( undefined ) ,
335333 require : ( codemodName : string ) => ( {
336- default : {
337- presets : {
338- 'update-formatting' : `${ codemodName } /path/to/update-formatting.js` ,
339- } ,
334+ presets : {
335+ 'update-formatting' : `${ codemodName } /path/to/update-formatting.js` ,
340336 } ,
341337 } ) ,
342338 uninstallAll : ( ) => Promise . resolve ( ) ,
@@ -360,10 +356,8 @@ describe('main', () => {
360356 install : ( ) => Promise . resolve ( undefined ) ,
361357 // @ts -ignore
362358 require : ( codemodName : string ) => ( {
363- default : {
364- presets : {
365- 'update-formatting' : `${ codemodName } /path/to/update-formatting.js` ,
366- } ,
359+ presets : {
360+ 'update-formatting' : `${ codemodName } /path/to/update-formatting.js` ,
367361 } ,
368362 } ) ,
369363 uninstallAll : ( ) => Promise . resolve ( ) ,
@@ -472,10 +466,8 @@ describe('main', () => {
472466 install : ( ) => Promise . resolve ( undefined ) ,
473467 // @ts -ignore
474468 require : ( codemodName : string ) => ( {
475- default : {
476- transforms : {
477- '20.0.0' : `${ codemodName } /path/to/20.js` ,
478- } ,
469+ transforms : {
470+ '20.0.0' : `${ codemodName } /path/to/20.js` ,
479471 } ,
480472 } ) ,
481473 uninstallAll : ( ) => Promise . resolve ( ) ,
@@ -499,10 +491,8 @@ describe('main', () => {
499491 install : ( ) => Promise . resolve ( undefined ) ,
500492 // @ts -ignore
501493 require : ( codemodName : string ) => ( {
502- default : {
503- transforms : {
504- '20.0.0' : `${ codemodName } /path/to/20.js` ,
505- } ,
494+ transforms : {
495+ '20.0.0' : `${ codemodName } /path/to/20.js` ,
506496 } ,
507497 } ) ,
508498 uninstallAll : ( ) => Promise . resolve ( ) ,
@@ -517,4 +507,37 @@ describe('main', () => {
517507 ) . resolves . not . toThrow ( ) ;
518508 } ) ;
519509 } ) ;
510+
511+ describe ( 'when reading configs using non-cjs exports' , ( ) => {
512+ it ( 'should read configs exported with export default' , async ( ) => {
513+ ( PluginManager as jest . Mock ) . mockReturnValue ( {
514+ install : ( ) => Promise . resolve ( undefined ) ,
515+ // @ts -ignore
516+ require : ( codemodName : string ) => ( {
517+ default : {
518+ transforms : {
519+ '18.0.0' : `${ codemodName } /path/to/18.js` ,
520+ } ,
521+ } ,
522+ } ) ,
523+ uninstallAll : ( ) => Promise . resolve ( ) ,
524+ } ) ;
525+
526+ await main ( [ mockPath ] , {
527+ packages : 'mylib@18.0.0' ,
528+ parser : 'babel' ,
529+ extensions : 'js' ,
530+ } ) ;
531+
532+ expect ( jscodeshift . run ) . toHaveBeenCalledTimes ( 1 ) ;
533+ expect ( jscodeshift . run ) . toHaveBeenCalledWith (
534+ '@codeshift/mod-mylib/path/to/18.js' ,
535+ expect . arrayContaining ( [ mockPath ] ) ,
536+ expect . objectContaining ( {
537+ parser : 'babel' ,
538+ extensions : 'js' ,
539+ } ) ,
540+ ) ;
541+ } ) ;
542+ } ) ;
520543} ) ;
0 commit comments