@@ -25,6 +25,7 @@ const testName = 'healthEndpoints';
2525const gemVersion = packageJson . version ;
2626const { protocolVersion } = packageJson ;
2727const railsEnv = 'test' ;
28+ const originalEnableHealthEndpointsEnv = process . env . RENDERER_ENABLE_HEALTH_ENDPOINTS ;
2829
2930disableHttp2 ( ) ;
3031
@@ -58,6 +59,7 @@ describe('built-in health endpoints', () => {
5859 let app : ReturnType < typeof createWorker > | undefined ;
5960
6061 beforeEach ( async ( ) => {
62+ delete process . env . RENDERER_ENABLE_HEALTH_ENDPOINTS ;
6163 await resetForTest ( testName ) ;
6264 } ) ;
6365
@@ -67,6 +69,11 @@ describe('built-in health endpoints', () => {
6769 } ) ;
6870
6971 afterAll ( async ( ) => {
72+ if ( originalEnableHealthEndpointsEnv === undefined ) {
73+ delete process . env . RENDERER_ENABLE_HEALTH_ENDPOINTS ;
74+ } else {
75+ process . env . RENDERER_ENABLE_HEALTH_ENDPOINTS = originalEnableHealthEndpointsEnv ;
76+ }
7077 await resetForTest ( testName ) ;
7178 } ) ;
7279
@@ -90,6 +97,19 @@ describe('built-in health endpoints', () => {
9097 expect ( JSON . parse ( res . payload ) ) . toEqual ( { status : 'ok' } ) ;
9198 } ) ;
9299
100+ test ( 'GET /health and GET /ready are registered when enabled by environment variable' , async ( ) => {
101+ process . env . RENDERER_ENABLE_HEALTH_ENDPOINTS = 'true' ;
102+ app = createWorker ( ) ;
103+
104+ const healthRes = await app . inject ( ) . get ( '/health' ) . end ( ) ;
105+ expect ( healthRes . statusCode ) . toBe ( 200 ) ;
106+ expect ( JSON . parse ( healthRes . payload ) ) . toEqual ( { status : 'ok' } ) ;
107+
108+ const readyRes = await app . inject ( ) . get ( '/ready' ) . end ( ) ;
109+ expect ( readyRes . statusCode ) . toBe ( 503 ) ;
110+ expect ( JSON . parse ( readyRes . payload ) ) . toEqual ( { status : 'waiting_for_bundle' } ) ;
111+ } ) ;
112+
93113 test ( 'GET /ready returns 503 before a bundle is loaded and 200 after' , async ( ) => {
94114 app = createWorker ( { enableHealthEndpoints : true } ) ;
95115
0 commit comments