1616 */
1717import { suite , test , before , after } from 'node:test' ;
1818import { strictEqual , ok , deepStrictEqual } from 'node:assert/strict' ;
19- import { readFileSync } from 'node:fs' ;
20- import { join , dirname } from 'node:path' ;
19+ import { resolve } from 'node:path' ;
2120import { fileURLToPath } from 'node:url' ;
22- import { startHarper , teardownHarper } from '@harperfast/integration-testing' ;
21+ import { setupHarperWithFixture , teardownHarper } from '@harperfast/integration-testing' ;
2322import { createApiClient } from '../apiTests/utils/client.mjs' ;
24- import { installAppComponent } from '../apiTests/utils/components.mjs' ;
2523
26- const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
27- const FIXTURE_DIR = join ( __dirname , '../fixtures/custom-resources' ) ;
24+ const __dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
25+ const FIXTURE_PATH = resolve ( __dirname , '../fixtures/custom-resources' ) ;
2826
2927// ---------------------------------------------------------------------------
3028// Helpers
@@ -47,24 +45,28 @@ function restReq(httpURL: string, path: string, method: string, body?: unknown,
4745// ---------------------------------------------------------------------------
4846
4947suite ( 'Custom resource patterns' , { skip : skipSuite } , ( ctx ) => {
50- let client : ReturnType < typeof createApiClient > ;
48+ let _client : ReturnType < typeof createApiClient > ;
5149 let httpURL : string ;
5250
5351 before ( async ( ) => {
54- await startHarper ( ctx , { config : { } , env : { } } ) ;
55- client = createApiClient ( ctx . harper ) ;
52+ await setupHarperWithFixture ( ctx , FIXTURE_PATH , { config : { } , env : { } } ) ;
53+ _client = createApiClient ( ctx . harper ) ;
5654 httpURL = ctx . harper . httpURL ;
5755
58- await installAppComponent ( client , {
59- project : 'customResources' ,
60- files : {
61- 'schema.graphql' : readFileSync ( join ( FIXTURE_DIR , 'schema.graphql' ) , 'utf-8' ) ,
62- 'resources.js' : readFileSync ( join ( FIXTURE_DIR , 'resources.js' ) , 'utf-8' ) ,
63- 'config.yaml' : readFileSync ( join ( FIXTURE_DIR , 'config.yaml' ) , 'utf-8' ) ,
64- } ,
65- probePath : '/WorkItem/' ,
66- restartTimeoutMs : 120_000 ,
67- } ) ;
56+ // Poll until WorkItem route is ready (may take a moment after startHarper resolves)
57+ const deadline = Date . now ( ) + 30_000 ;
58+ while ( Date . now ( ) < deadline ) {
59+ try {
60+ const probe = await fetch ( `${ httpURL } /WorkItem/` , {
61+ method : 'GET' ,
62+ headers : { 'Content-Type' : 'application/json' } ,
63+ } ) ;
64+ if ( probe . status !== 404 ) break ;
65+ } catch {
66+ // connection not yet ready
67+ }
68+ await new Promise ( ( r ) => setTimeout ( r , 200 ) ) ;
69+ }
6870 } ) ;
6971
7072 after ( async ( ) => {
0 commit comments