File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,13 @@ describe("TypeScriptLoader", () => {
99 const fixturesPath = path . resolve ( __dirname , "__fixtures__" ) ;
1010
1111 let loader : Loader ;
12+ let tsNodeSpy = jest . spyOn ( tsnode , "register" ) ;
1213
1314 function readFixtureContent ( file : string ) : string {
1415 return fs . readFileSync ( file ) . toString ( ) ;
1516 }
1617
17- beforeEach ( ( ) => {
18+ beforeAll ( ( ) => {
1819 loader = TypeScriptLoader ( ) ;
1920 } ) ;
2021
@@ -28,6 +29,14 @@ describe("TypeScriptLoader", () => {
2829 expect ( ( ) => loader ( filePath , readFixtureContent ( filePath ) ) ) . toThrowError ( ) ;
2930 } ) ;
3031
32+ it ( "should use the same instance of ts-node across multiple calls" , ( ) => {
33+ const filePath = path . resolve ( fixturesPath , "valid.fixture.ts" ) ;
34+ loader ( filePath , readFixtureContent ( filePath ) ) ;
35+ loader ( filePath , readFixtureContent ( filePath ) ) ;
36+ loader ( filePath , readFixtureContent ( filePath ) ) ;
37+ expect ( tsNodeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
38+ } ) ;
39+
3140 it ( "should throw a TypeScriptCompileError on error" , ( ) => {
3241 try {
3342 const filePath = path . resolve ( fixturesPath , "invalid.fixture.ts" ) ;
Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ import { register, RegisterOptions } from "ts-node";
33import { TypeScriptCompileError } from "./typescript-compile-error" ;
44
55export function TypeScriptLoader ( options ?: RegisterOptions ) : Loader {
6- const tsNodeInstance = register ( { ...options , compilerOptions : { module : "commonjs" } } )
6+ const tsNodeInstance = register ( {
7+ ...options ,
8+ compilerOptions : { module : "commonjs" } ,
9+ } ) ;
710 return ( path : string , content : string ) => {
811 try {
912 // cosmiconfig requires the transpiled configuration to be CJS
10- tsNodeInstance . compile (
11- content ,
12- path
13- ) ;
13+ tsNodeInstance . compile ( content , path ) ;
1414 const result = require ( path ) ;
1515
1616 // `default` is used when exporting using export default, some modules
You can’t perform that action at this time.
0 commit comments