Skip to content

Commit 02b92cc

Browse files
kriszypclaude
andcommitted
test: migrate custom resources test to setupHarperWithFixture
Replace startHarper + installAppComponent + readFileSync with setupHarperWithFixture. Adds a readiness poll for /WorkItem/ after startup since the route registration completes slightly after startHarper resolves when a component is pre-loaded at boot time. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent d1fe17e commit 02b92cc

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

integrationTests/resources/custom-resources.test.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
*/
1717
import { suite, test, before, after } from 'node:test';
1818
import { 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';
2120
import { fileURLToPath } from 'node:url';
22-
import { startHarper, teardownHarper } from '@harperfast/integration-testing';
21+
import { setupHarperWithFixture, teardownHarper } from '@harperfast/integration-testing';
2322
import { 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

4947
suite('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

Comments
 (0)