Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions packages/host/tests/helpers/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ export class TestRealmAdapter implements RealmAdapter {
throw new Error('bug: loader needs to be set in test adapter');
}

// Nothing to prepare means nothing to prepare it with. The loader here is
// constructed per test realm, so its module cache is empty and this import
// evaluates card-api and its whole graph — measured at ~280ms, paid on
// every setup whether or not there is an object to mark saved or shim.
// Contents given as source strings, and realms given no contents at all,
// populate nothing.
if (this.#potentialModulesAndInstances.length === 0) {
this.#ready.fulfill();
return;
}

let cardApi = await this.#loader.import<CardAPI>(
'@cardstack/base/card-api',
);
Expand Down
84 changes: 52 additions & 32 deletions packages/host/tests/helpers/index.gts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ export async function setupIntegrationTestRealm({
realmURL,
permissions,
mockMatrixUtils,
skipBootIndex,
startMatrix = true,
fileSizeLimitBytes,
audioSizeLimitBytes,
Expand All @@ -1232,6 +1233,15 @@ export async function setupIntegrationTestRealm({
realmURL?: string;
permissions?: RealmPermissions;
mockMatrixUtils: MockUtils;
// Mount and serve without a from-scratch boot index. A realm's boot index
// costs ~676ms regardless of how little it has to index, so a test that
// never reads the search index — one that renders a card it constructed, or
// exercises a component — need not pay for one. Definitions still resolve,
// lazily through the prerenderer on first lookup.
//
// Not the default: a test that queries, or that reads a card by id through
// the store, needs the index populated and fails without it.
skipBootIndex?: true;
startMatrix?: boolean;
fileSizeLimitBytes?: number;
audioSizeLimitBytes?: number;
Expand All @@ -1247,6 +1257,7 @@ export async function setupIntegrationTestRealm({
isAcceptanceTest: false,
permissions: permissions as RealmPermissions,
mockMatrixUtils,
skipBootIndex,
startMatrix,
fileSizeLimitBytes,
audioSizeLimitBytes,
Expand Down Expand Up @@ -1282,6 +1293,7 @@ async function setupTestRealm({
isAcceptanceTest,
permissions = { '*': ['read', 'write'] },
mockMatrixUtils,
skipBootIndex,
startMatrix = true,
fileSizeLimitBytes,
audioSizeLimitBytes,
Expand All @@ -1292,6 +1304,7 @@ async function setupTestRealm({
isAcceptanceTest?: boolean;
permissions?: RealmPermissions;
mockMatrixUtils: MockUtils;
skipBootIndex?: true;
startMatrix?: boolean;
fileSizeLimitBytes?: number;
audioSizeLimitBytes?: number;
Expand Down Expand Up @@ -1359,39 +1372,46 @@ async function setupTestRealm({
createPrerenderAuth,
});

realm = new Realm({
url: realmURL,
adapter,
secretSeed: testRealmSecretSeed,
virtualNetwork,
dbAdapter,
queue,
matrixClient: new MatrixClient({
matrixURL: baseTestMatrix.url,
username: testRealmServerMatrixUsername,
seed: testRealmSecretSeed,
}),
realmServerURL: ensureTrailingSlash(ENV.realmServerURL),
definitionLookup,
cardSizeLimitBytes: Number(
process.env.CARD_SIZE_LIMIT_BYTES ?? DEFAULT_CARD_SIZE_LIMIT_BYTES,
),
fileSizeLimitBytes:
fileSizeLimitBytes ??
Number(
process.env.FILE_SIZE_LIMIT_BYTES ?? DEFAULT_FILE_SIZE_LIMIT_BYTES,
),
audioSizeLimitBytes:
audioSizeLimitBytes ??
Number(
process.env.AUDIO_SIZE_LIMIT_BYTES ?? DEFAULT_AUDIO_SIZE_LIMIT_BYTES,
),
videoSizeLimitBytes:
videoSizeLimitBytes ??
Number(
process.env.VIDEO_SIZE_LIMIT_BYTES ?? DEFAULT_VIDEO_SIZE_LIMIT_BYTES,
realm = new Realm(
{
url: realmURL,
adapter,
secretSeed: testRealmSecretSeed,
virtualNetwork,
dbAdapter,
queue,
matrixClient: new MatrixClient({
matrixURL: baseTestMatrix.url,
username: testRealmServerMatrixUsername,
seed: testRealmSecretSeed,
}),
realmServerURL: ensureTrailingSlash(ENV.realmServerURL),
definitionLookup,
cardSizeLimitBytes: Number(
process.env.CARD_SIZE_LIMIT_BYTES ?? DEFAULT_CARD_SIZE_LIMIT_BYTES,
),
});
fileSizeLimitBytes:
fileSizeLimitBytes ??
Number(
process.env.FILE_SIZE_LIMIT_BYTES ?? DEFAULT_FILE_SIZE_LIMIT_BYTES,
),
audioSizeLimitBytes:
audioSizeLimitBytes ??
Number(
process.env.AUDIO_SIZE_LIMIT_BYTES ?? DEFAULT_AUDIO_SIZE_LIMIT_BYTES,
),
videoSizeLimitBytes:
videoSizeLimitBytes ??
Number(
process.env.VIDEO_SIZE_LIMIT_BYTES ?? DEFAULT_VIDEO_SIZE_LIMIT_BYTES,
),
},
// Realm reads its behavioural options from this second argument. Spreading
// one into the first argument type-checks — object spreads bypass
// excess-property checking — and is then dropped by a destructuring that
// never names it, so the option silently does nothing.
{ ...(skipBootIndex ? { skipBootIndex } : {}) },
);

// Register the realm early so realm-server mock _info lookups can resolve
// without falling back to real network fetches.
Expand Down
7 changes: 7 additions & 0 deletions packages/host/tests/integration/components/computed-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module('Integration | computeds', function (hooks) {
}

await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: {
'test-cards.gts': { Post, Person },
Expand Down Expand Up @@ -223,6 +224,7 @@ module('Integration | computeds', function (hooks) {
}

await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: {
'test-cards.gts': { Family, Person },
Expand Down Expand Up @@ -301,6 +303,7 @@ module('Integration | computeds', function (hooks) {
}

await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: {
'test-cards.gts': { Family, Person },
Expand Down Expand Up @@ -483,6 +486,7 @@ module('Integration | computeds', function (hooks) {
}

await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: {
'test-cards.gts': { Post, Author },
Expand Down Expand Up @@ -541,6 +545,7 @@ module('Integration | computeds', function (hooks) {
}

await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: {
'test-cards.gts': { Article, Tag },
Expand Down Expand Up @@ -614,6 +619,7 @@ module('Integration | computeds', function (hooks) {
}

await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: {
'test-cards.gts': { Blog, Category },
Expand Down Expand Up @@ -669,6 +675,7 @@ module('Integration | computeds', function (hooks) {
static displayName = 'Article';
}
await setupIntegrationTestRealm({
skipBootIndex: true,
mockMatrixUtils,
contents: { 'test-cards.gts': { Article } },
});
Expand Down
Loading
Loading