@@ -2,13 +2,15 @@ jest.mock("fs", () => ({
22 readFileSync : jest . fn ( ) ,
33 realpathSync : { } ,
44 existsSync : jest . fn ( ) ,
5+ statSync : jest . fn ( ) ,
6+ stat : jest . fn ( ) ,
57} ) )
68jest . mock ( "path" , ( ) => {
79 const path = jest . requireActual ( "path" )
810 return { ...path , resolve : jest . fn ( path . resolve ) }
911} )
1012
11- import { typescriptify , lookupTSConfig , dirContains } from "../transpiler"
13+ import { typescriptify , lookupTSConfig , dirContains , babelify } from "../transpiler"
1214import * as fs from "fs"
1315import * as path from "path"
1416
@@ -87,3 +89,25 @@ describe("dirContains", () => {
8789 } )
8890 }
8991} )
92+
93+ describe ( "babelify" , ( ) => {
94+ it ( "does not throw when a filepath is ignored due to babel options, and should return the content unchanged" , ( ) => {
95+ const dangerfile = `import { a } from 'lodash';
96+ a();`
97+
98+ const existsSyncMock = fs . existsSync as jest . Mock
99+ const actualFs = jest . requireActual ( "fs" ) as typeof fs
100+ existsSyncMock . mockImplementation ( ( path ) => path === "/a/b/babel.config.js" || actualFs . existsSync ( path ) )
101+ jest . mock (
102+ "/a/b/babel.config.js" ,
103+ ( ) => {
104+ return { ignore : [ "/a/b" ] }
105+ } ,
106+ { virtual : true }
107+ )
108+ const act = ( ) => babelify ( dangerfile , "a/b/" , [ ] )
109+
110+ expect ( act ) . not . toThrow ( )
111+ expect ( act ( ) ) . toEqual ( dangerfile )
112+ } )
113+ } )
0 commit comments