11jest . mock ( 'fs-extra' ) ;
2+ jest . mock ( '@codeshift/fetcher' ) ;
23
34import fs from 'fs-extra' ;
4- import path from 'path' ;
5+
6+ import { fetchConfig } from '@codeshift/fetcher' ;
57
68import {
79 isValidPackageName ,
@@ -112,58 +114,38 @@ describe('validator', () => {
112114 jest . resetModules ( ) ;
113115 } ) ;
114116
115- it ( 'should validate config' , ( ) => {
116- jest . mock (
117- path . join ( __dirname , 'path' , 'to' , 'codeshift.config.js' ) ,
118- ( ) => ( {
119- __esModule : true ,
120- default : {
121- transforms : {
122- '10.0.0' : 'path/to/transform.js' ,
123- } ,
124- } ,
125- } ) ,
126- { virtual : true } ,
127- ) ;
117+ it ( 'should validate config' , async ( ) => {
118+ ( fetchConfig as jest . Mock ) . mockResolvedValue ( {
119+ transforms : {
120+ '10.0.0' : 'path/to/transform.js' ,
121+ } ,
122+ } ) ;
128123
129- expect ( isValidConfigAtPath ( 'path/to/' ) ) . toEqual ( true ) ;
124+ const result = await isValidConfigAtPath ( 'path/to/' ) ;
125+ expect ( result ) . toEqual ( true ) ;
130126 } ) ;
131127
132- it ( 'should error if config contains invalid transforms' , ( ) => {
133- jest . mock (
134- path . join ( __dirname , 'path' , 'to' , 'codeshift.config.js' ) ,
135- ( ) => ( {
136- __esModule : true ,
137- default : {
138- transforms : {
139- hello : '' ,
140- } ,
141- } ,
142- } ) ,
143- { virtual : true } ,
144- ) ;
128+ it ( 'should error if config contains invalid transforms' , async ( ) => {
129+ ( fetchConfig as jest . Mock ) . mockResolvedValue ( {
130+ transforms : {
131+ hello : '' ,
132+ } ,
133+ } ) ;
145134
146- expect ( ( ) => isValidConfigAtPath ( 'path/to/' ) ) . toThrowError (
135+ await expect ( isValidConfigAtPath ( 'path/to/' ) ) . rejects . toThrowError (
147136 `Invalid transform ids found for config at "path/to/".
148137Please make sure all transforms are identified by a valid semver version. ie 10.0.0` ,
149138 ) ;
150139 } ) ;
151140
152- it ( 'should error if config contains invalid presets' , ( ) => {
153- jest . mock (
154- path . join ( __dirname , 'path' , 'to' , 'codeshift.config.js' ) ,
155- ( ) => ( {
156- __esModule : true ,
157- default : {
158- presets : {
159- 'foo bar' : '' ,
160- } ,
161- } ,
162- } ) ,
163- { virtual : true } ,
164- ) ;
141+ it ( 'should error if config contains invalid presets' , async ( ) => {
142+ ( fetchConfig as jest . Mock ) . mockResolvedValue ( {
143+ presets : {
144+ 'foo bar' : '' ,
145+ } ,
146+ } ) ;
165147
166- expect ( ( ) => isValidConfigAtPath ( 'path/to/' ) ) . toThrowError (
148+ await expect ( isValidConfigAtPath ( 'path/to/' ) ) . rejects . toThrowError (
167149 `Invalid preset ids found for config at "path/to/".
168150Please make sure all presets are kebab case and contain no spaces or special characters. ie sort-imports-by-scope` ,
169151 ) ;
@@ -196,6 +178,7 @@ Please make sure all presets are kebab case and contain no spaces or special cha
196178 try {
197179 await isValidPackageJson ( 'path/to/' ) ;
198180 } catch ( error ) {
181+ // @ts -ignore
199182 expect ( error . message ) . toMatch (
200183 'No main entrypoint provided in package.json' ,
201184 ) ;
@@ -210,6 +193,7 @@ Please make sure all presets are kebab case and contain no spaces or special cha
210193 try {
211194 await isValidPackageJson ( 'path/to/' ) ;
212195 } catch ( error ) {
196+ // @ts -ignore
213197 expect ( error . message ) . toMatch (
214198 'No package name provided in package.json' ,
215199 ) ;
0 commit comments