@@ -7,14 +7,15 @@ import { TypeScriptCompileError } from "./typescript-compile-error";
77
88describe ( "TypeScriptLoader" , ( ) => {
99 const fixturesPath = path . resolve ( __dirname , "__fixtures__" ) ;
10+ const tsNodeSpy = jest . spyOn ( tsnode , "register" ) ;
1011
1112 let loader : Loader ;
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,13 @@ 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+ expect ( tsNodeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
37+ } ) ;
38+
3139 it ( "should throw a TypeScriptCompileError on error" , ( ) => {
3240 try {
3341 const filePath = path . resolve ( fixturesPath , "invalid.fixture.ts" ) ;
@@ -46,10 +54,16 @@ describe("TypeScriptLoader", () => {
4654 let stub : jest . SpyInstance < tsnode . Service , [ service : tsnode . Service ] > ;
4755
4856 beforeEach ( ( ) => {
49- stub = jest . spyOn ( tsnode , "register" ) . mockImplementation ( ( ) => {
50- // eslint-disable-next-line @typescript-eslint/no-throw-literal
51- throw unknownError ;
52- } ) ;
57+ stub = jest . spyOn ( tsnode , "register" ) . mockImplementation (
58+ ( ) =>
59+ ( {
60+ compile : ( ) : string => {
61+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
62+ throw unknownError ;
63+ } ,
64+ } as any )
65+ ) ;
66+ loader = TypeScriptLoader ( ) ;
5367 } ) ;
5468
5569 afterEach ( ( ) => {
0 commit comments