11import { describe , it , expect , vi , beforeEach } from 'vitest' ;
22import { HonoServerPlugin } from './hono-plugin' ;
33import { PluginContext } from '@objectstack/core' ;
4- import { createHonoApp } from '@objectstack/hono' ;
54import { HonoHttpServer } from './adapter' ;
65
76vi . mock ( 'fs' , async ( importOriginal ) => {
@@ -12,11 +11,6 @@ vi.mock('fs', async (importOriginal) => {
1211 } ;
1312} ) ;
1413
15- // Mock dependencies
16- vi . mock ( '@objectstack/hono' , ( ) => ( {
17- createHonoApp : vi . fn ( ) ,
18- } ) ) ;
19-
2014vi . mock ( '@hono/node-server/serve-static' , ( ) => ( {
2115 serveStatic : vi . fn ( ( ) => ( c : any , next : any ) => next ( ) )
2216} ) ) ;
@@ -64,10 +58,6 @@ describe('HonoServerPlugin', () => {
6458 hook : vi . fn ( ) ,
6559 getService : vi . fn ( )
6660 } ;
67-
68- ( createHonoApp as any ) . mockReturnValue ( {
69- // Mock Hono App structure if needed
70- } ) ;
7161 } ) ;
7262
7363 it ( 'should initialize and register server' , async ( ) => {
@@ -78,49 +68,28 @@ describe('HonoServerPlugin', () => {
7868 expect ( HonoHttpServer ) . toHaveBeenCalled ( ) ;
7969 } ) ;
8070
81- it ( 'should create and mount Hono app on start ' , async ( ) => {
71+ it ( 'should register IHttpServer service on init ' , async ( ) => {
8272 const plugin = new HonoServerPlugin ( ) ;
8373 await plugin . init ( context as PluginContext ) ;
84- await plugin . start ( context as PluginContext ) ;
85-
86- expect ( createHonoApp ) . toHaveBeenCalledWith ( expect . objectContaining ( {
87- kernel : kernel ,
88- prefix : '/api/v1'
89- } ) ) ;
9074
91- // Access the mocked server instance
92- const serverInstance = ( HonoHttpServer as any ) . mock . instances [ 0 ] ;
93- expect ( serverInstance . mount ) . toHaveBeenCalledWith ( '/' , expect . anything ( ) ) ;
75+ expect ( context . registerService ) . toHaveBeenCalledWith ( 'http.server' , expect . any ( Object ) ) ;
76+ expect ( context . registerService ) . toHaveBeenCalledWith ( 'http-server' , expect . any ( Object ) ) ;
9477 } ) ;
9578
96- it ( 'should respect REST server configuration for prefix' , async ( ) => {
97- const plugin = new HonoServerPlugin ( {
98- restConfig : {
99- api : {
100- version : 'v2' ,
101- basePath : '/custom'
102- }
103- }
104- } ) ;
105-
79+ it ( 'should start without errors' , async ( ) => {
80+ const plugin = new HonoServerPlugin ( ) ;
10681 await plugin . init ( context as PluginContext ) ;
10782 await plugin . start ( context as PluginContext ) ;
10883
109- expect ( createHonoApp ) . toHaveBeenCalledWith ( expect . objectContaining ( {
110- prefix : '/custom/v2'
111- } ) ) ;
84+ // Plugin should register kernel:ready hook to start listening
85+ expect ( context . hook ) . toHaveBeenCalledWith ( 'kernel:ready' , expect . any ( Function ) ) ;
11286 } ) ;
11387
114- it ( 'should handle errors during app creation' , async ( ) => {
115- ( createHonoApp as any ) . mockImplementation ( ( ) => {
116- throw new Error ( 'Creation failed' ) ;
117- } ) ;
118-
88+ it ( 'should handle errors gracefully on start' , async ( ) => {
89+ // Simulate a start that doesn't crash even without routes
11990 const plugin = new HonoServerPlugin ( ) ;
12091 await plugin . init ( context as PluginContext ) ;
121- await plugin . start ( context as PluginContext ) ;
122-
123- expect ( logger . error ) . toHaveBeenCalledWith ( 'Failed to create standard Hono app' , expect . any ( Error ) ) ;
92+ await expect ( plugin . start ( context as PluginContext ) ) . resolves . not . toThrow ( ) ;
12493 } ) ;
12594
12695 it ( 'should configure static files and SPA fallback when enabled' , async ( ) => {
0 commit comments