@@ -13,7 +13,6 @@ afterEach(() => {
1313 fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
1414 }
1515 vi . resetModules ( ) ;
16- vi . doUnmock ( "jiti" ) ;
1716} ) ;
1817
1918function createTempDir ( ) : string {
@@ -38,7 +37,7 @@ describe("channel plugin module loader helpers", () => {
3837 expect ( isJavaScriptModulePath ( "/tmp/entry.ts" ) ) . toBe ( false ) ;
3938 } ) ;
4039
41- it ( "uses native require for eligible JavaScript modules before falling back to Jiti" , async ( ) => {
40+ it ( "uses native require for eligible JavaScript modules without creating Jiti" , async ( ) => {
4241 const createJiti = vi . fn ( ( ) => vi . fn ( ( ) => ( { ok : false } ) ) ) ;
4342 vi . resetModules ( ) ;
4443 vi . doMock ( "jiti" , ( ) => ( {
@@ -57,45 +56,34 @@ describe("channel plugin module loader helpers", () => {
5756 loaderModule . loadChannelPluginModule ( {
5857 modulePath,
5958 rootDir,
60- shouldTryNativeRequire : ( ) => true ,
6159 } ) ,
6260 ) . toEqual ( { ok : true } ) ;
6361 expect ( createJiti ) . not . toHaveBeenCalled ( ) ;
6462 } ) ;
6563
66- it ( "creates the runtime-supported Jiti boundary for Windows dist loads" , async ( ) => {
67- const createJiti = vi . fn ( ( ) => vi . fn ( ( ) => ( { ok : true } ) ) ) ;
64+ it ( "rejects TypeScript modules without creating Jiti" , async ( ) => {
65+ const createJiti = vi . fn ( ( ) => {
66+ throw new Error ( "channel module loader must not create jiti" ) ;
67+ } ) ;
6868 vi . resetModules ( ) ;
6969 vi . doMock ( "jiti" , ( ) => ( {
7070 createJiti,
7171 } ) ) ;
72- const platformSpy = vi . spyOn ( process , "platform" , "get" ) . mockReturnValue ( "win32" ) ;
73-
74- try {
75- const loaderModule = await importFreshModule < typeof import ( "./module-loader.js" ) > (
76- import . meta. url ,
77- "./module-loader.js?scope=windows-dist-jiti" ,
78- ) ;
79- const rootDir = createTempDir ( ) ;
80- const modulePath = path . join ( rootDir , "dist" , "extensions" , "demo" , "index.js" ) ;
81- fs . mkdirSync ( path . dirname ( modulePath ) , { recursive : true } ) ;
82- fs . writeFileSync ( modulePath , "export const ok = true;\n" , "utf8" ) ;
72+ const loaderModule = await importFreshModule < typeof import ( "./module-loader.js" ) > (
73+ import . meta. url ,
74+ "./module-loader.js?scope=source-ts-native-hook" ,
75+ ) ;
76+ const rootDir = createTempDir ( ) ;
77+ const modulePath = path . join ( rootDir , "extensions" , "demo" , "index.ts" ) ;
78+ fs . mkdirSync ( path . dirname ( modulePath ) , { recursive : true } ) ;
79+ fs . writeFileSync ( modulePath , "export const ok = true;\n" , "utf8" ) ;
8380
84- const loaded = loaderModule . loadChannelPluginModule ( {
81+ expect ( ( ) =>
82+ loaderModule . loadChannelPluginModule ( {
8583 modulePath,
8684 rootDir,
87- shouldTryNativeRequire : ( ) => false ,
88- } ) ;
89-
90- expect ( loaded ) . toMatchObject ( { ok : true } ) ;
91- expect ( createJiti ) . toHaveBeenCalledWith (
92- expect . any ( String ) ,
93- expect . objectContaining ( {
94- tryNative : false ,
95- } ) ,
96- ) ;
97- } finally {
98- platformSpy . mockRestore ( ) ;
99- }
85+ } ) ,
86+ ) . toThrow ( / m u s t b e b u i l t J a v a S c r i p t / u) ;
87+ expect ( createJiti ) . not . toHaveBeenCalled ( ) ;
10088 } ) ;
10189} ) ;
0 commit comments