Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/host/tests/helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { clearHtmlComponentCache } from '@cardstack/host/lib/html-component';
import type SessionService from '@cardstack/host/services/session';
import { AiAssistantOpen } from '@cardstack/host/utils/local-storage-keys';

import { getTestRealmRegistry } from './test-realm-registry';

import { cleanupMonacoEditorModels } from './index';

// Pin `yaml` into the eager test bundle. `markdown-file-def` parses frontmatter
Expand Down Expand Up @@ -268,6 +270,25 @@ function setupFetchDebugging(hooks: NestedHooks) {
startedAt: Date.now(),
});
try {
// Requests to a registered test realm are answered in-page rather
// than dispatched to the network. The service-worker relay that
// otherwise serves these URLs only intercepts once the worker
// controls the page and its per-module activation has been acked;
// a card component that renders (and fetches) before that window
// closes would otherwise hit the real network and fail, since the
// test-realm host doesn't exist outside the harness. The registry
// is populated at realm construction, so this path has no such
// window. Non-fetch resources (images, workers) still rely on the
// service worker.
for (let [realmUrl, { realm }] of getTestRealmRegistry()) {
if (url.startsWith(realmUrl)) {
let response = await realm.maybeHandle(new Request(input, init));
if (response) {
return response;
}
break;
}
}
return await boundFetch(input, init);
} catch (error) {
let reason = formatErrorForLog(error);
Expand Down
Loading