Skip to content

Commit f016d5e

Browse files
committedMar 14, 2024
Implement loader-specific module shimming via virtual network
1 parent 4be4575 commit f016d5e

File tree

9 files changed

+217
-265
lines changed

9 files changed

+217
-265
lines changed
 

‎packages/host/tests/acceptance/interact-submode-test.gts

+4
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ module('Acceptance | interact submode tests', function (hooks) {
313313
assert.dom('[data-test-search-sheet]').doesNotHaveClass('results'); // Search closed
314314

315315
// The card appears on a new stack
316+
await waitFor('[data-test-operator-mode-stack]');
317+
316318
assert.dom('[data-test-operator-mode-stack]').exists({ count: 1 });
317319
assert
318320
.dom(
@@ -640,6 +642,7 @@ module('Acceptance | interact submode tests', function (hooks) {
640642
assert.dom('[data-test-search-sheet]').doesNotHaveClass('prompt'); // Search closed
641643

642644
// There are now 2 stacks
645+
643646
assert.dom('[data-test-operator-mode-stack]').exists({ count: 2 });
644647
assert.dom('[data-test-operator-mode-stack="0"]').includesText('Mango'); // Mango goes on the left stack
645648
assert.dom('[data-test-operator-mode-stack="1"]').includesText('Fadhlan');
@@ -668,6 +671,7 @@ module('Acceptance | interact submode tests', function (hooks) {
668671
assert.dom('[data-test-search-sheet]').doesNotHaveClass('prompt'); // Search closed
669672

670673
// There are now 2 stacks
674+
await waitFor('[data-test-operator-mode-stack="0"]');
671675
assert.dom('[data-test-operator-mode-stack]').exists({ count: 2 });
672676
assert.dom('[data-test-operator-mode-stack="0"]').includesText('Fadhlan');
673677
assert.dom('[data-test-operator-mode-stack="1"]').includesText('Mango'); // Mango gets move onto the right stack

‎packages/host/tests/helpers/index.gts

+1-17
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ async function setupTestRealm({
481481
for (const [path, mod] of Object.entries(contents)) {
482482
if (path.endsWith('.gts') && typeof mod !== 'string') {
483483
let moduleURLString = `${realmURL}${path.replace(/\.gts$/, '')}`;
484-
await shimModule(moduleURLString, mod as object, loader);
484+
loader.shimModule(moduleURLString, mod as object);
485485
}
486486
}
487487
let api = await loader.import<CardAPI>(`${baseRealm.url}card-api`);
@@ -573,22 +573,6 @@ export async function saveCard(instance: CardDef, id: string, loader: Loader) {
573573
return doc;
574574
}
575575

576-
export async function shimModule(
577-
moduleURL: string,
578-
module: Record<string, any>,
579-
loader: Loader,
580-
) {
581-
if (loader) {
582-
loader.shimModule(moduleURL, module);
583-
}
584-
await Promise.all(
585-
Object.keys(module).map(async (name) => {
586-
let m = await loader.import<any>(moduleURL);
587-
m[name];
588-
}),
589-
);
590-
}
591-
592576
export function setupCardLogs(
593577
hooks: NestedHooks,
594578
apiThunk: () => Promise<CardAPI>,

‎packages/host/tests/integration/components/card-basics-test.gts

+33-50
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
cleanWhiteSpace,
3535
p,
3636
testRealmURL,
37-
shimModule,
3837
setupCardLogs,
3938
saveCard,
4039
} from '../../helpers';
@@ -163,7 +162,7 @@ module('Integration | card-basics', function (hooks) {
163162
</template>
164163
};
165164
}
166-
await shimModule(`${testRealmURL}test-cards`, { Post, Person }, loader);
165+
loader.shimModule(`${testRealmURL}test-cards`, { Post, Person });
167166

168167
let helloWorld = new Post({
169168
title: 'First Post',
@@ -413,7 +412,7 @@ module('Integration | card-basics', function (hooks) {
413412
};
414413
}
415414

416-
await shimModule(`${testRealmURL}test-cards`, { Guest, Person }, loader);
415+
loader.shimModule(`${testRealmURL}test-cards`, { Guest, Person });
417416

418417
let g1 = new Guest({
419418
name: 'Madeleine',
@@ -470,7 +469,7 @@ module('Integration | card-basics', function (hooks) {
470469
class Person extends CardDef {
471470
@field firstName = contains(StringField);
472471
}
473-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
472+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
474473

475474
// deserialize a card with an ID to mark it as "saved"
476475
let card = new Person({ firstName: 'Mango' });
@@ -782,7 +781,7 @@ module('Integration | card-basics', function (hooks) {
782781
@field firstName = contains(StringField);
783782
@field pet = linksTo(Pet);
784783
}
785-
await shimModule(`${testRealmURL}test-cards`, { Person, Pet }, loader);
784+
loader.shimModule(`${testRealmURL}test-cards`, { Person, Pet });
786785

787786
let mango = new Pet({
788787
firstName: 'Mango',
@@ -879,7 +878,7 @@ module('Integration | card-basics', function (hooks) {
879878
@field firstName = contains(StringField);
880879
@field pets = linksToMany(Pet);
881880
}
882-
await shimModule(`${testRealmURL}test-cards`, { Person, Pet }, loader);
881+
loader.shimModule(`${testRealmURL}test-cards`, { Person, Pet });
883882

884883
let mango = new Pet({
885884
firstName: 'Mango',
@@ -967,7 +966,7 @@ module('Integration | card-basics', function (hooks) {
967966
// @ts-expect-error Have to purposefully bypass type-checking in order to get into this runtime error state
968967
@field pet = linksTo(StringField);
969968
}
970-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
969+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
971970

972971
try {
973972
new Person({ firstName: 'Hassan', pet: 'Mango' });
@@ -1006,11 +1005,7 @@ module('Integration | card-basics', function (hooks) {
10061005
@field firstName = contains(StringField);
10071006
@field pet = linksTo(Pet);
10081007
}
1009-
await shimModule(
1010-
`${testRealmURL}test-cards`,
1011-
{ Person, Pet, NotAPet },
1012-
loader,
1013-
);
1008+
loader.shimModule(`${testRealmURL}test-cards`, { Person, Pet, NotAPet });
10141009

10151010
let door = new NotAPet({ firstName: 'door' });
10161011
try {
@@ -1060,7 +1055,7 @@ module('Integration | card-basics', function (hooks) {
10601055
</template>
10611056
};
10621057
}
1063-
await shimModule(`${testRealmURL}test-cards`, { Person, Pet }, loader);
1058+
loader.shimModule(`${testRealmURL}test-cards`, { Person, Pet });
10641059

10651060
let vanGogh = new Pet({ firstName: 'Van Gogh' });
10661061
let mango = new Pet({ firstName: 'Mango', friend: vanGogh });
@@ -1149,7 +1144,7 @@ module('Integration | card-basics', function (hooks) {
11491144
</template>
11501145
};
11511146
}
1152-
await shimModule(`${testRealmURL}test-cards`, { Post, Person }, loader);
1147+
loader.shimModule(`${testRealmURL}test-cards`, { Post, Person });
11531148

11541149
let helloWorld = new Post({
11551150
author: new Person({
@@ -1196,16 +1191,12 @@ module('Integration | card-basics', function (hooks) {
11961191
</template>
11971192
};
11981193
}
1199-
await shimModule(
1200-
`${testRealmURL}test-cards`,
1201-
{
1202-
Post,
1203-
Person,
1204-
TestNumber,
1205-
TestString,
1206-
},
1207-
loader,
1208-
);
1194+
loader.shimModule(`${testRealmURL}test-cards`, {
1195+
Post,
1196+
Person,
1197+
TestNumber,
1198+
TestString,
1199+
});
12091200

12101201
let helloWorld = new Post({
12111202
author: new Person({ firstName: 'Arthur', number: 10 }),
@@ -1234,7 +1225,7 @@ module('Integration | card-basics', function (hooks) {
12341225
@field title = contains(title);
12351226
@field author = contains(Person);
12361227
}
1237-
await shimModule(`${testRealmURL}test-cards`, { Post, Person }, loader);
1228+
loader.shimModule(`${testRealmURL}test-cards`, { Post, Person });
12381229

12391230
let helloWorld = new Post({
12401231
title: 'First Post',
@@ -1260,7 +1251,7 @@ module('Integration | card-basics', function (hooks) {
12601251
},
12611252
});
12621253
}
1263-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
1254+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
12641255
let helloWorld = new Person({
12651256
firstName: 'Arthur',
12661257
lastName: 'M',
@@ -1300,7 +1291,7 @@ module('Integration | card-basics', function (hooks) {
13001291
</template>
13011292
};
13021293
}
1303-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
1294+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
13041295
let helloWorld = new Person({ firstName: 'Arthur', age: 10 });
13051296

13061297
await renderCard(loader, helloWorld, 'atom');
@@ -1376,7 +1367,7 @@ module('Integration | card-basics', function (hooks) {
13761367
</template>
13771368
};
13781369
}
1379-
await shimModule(`${testRealmURL}test-cards`, { Family, Person }, loader);
1370+
loader.shimModule(`${testRealmURL}test-cards`, { Family, Person });
13801371

13811372
let abdelRahmans = new Family({
13821373
people: [
@@ -1452,7 +1443,7 @@ module('Integration | card-basics', function (hooks) {
14521443
</template>
14531444
};
14541445
}
1455-
await shimModule(`${testRealmURL}test-cards`, { Family, Person }, loader);
1446+
loader.shimModule(`${testRealmURL}test-cards`, { Family, Person });
14561447

14571448
let abdelRahmans = new Family({
14581449
people: [
@@ -1498,7 +1489,7 @@ module('Integration | card-basics', function (hooks) {
14981489
</template>
14991490
};
15001491
}
1501-
await shimModule(`${testRealmURL}test-cards`, { Family, Person }, loader);
1492+
loader.shimModule(`${testRealmURL}test-cards`, { Family, Person });
15021493
let mango = new Person({
15031494
firstName: 'Mango',
15041495
});
@@ -1559,16 +1550,12 @@ module('Integration | card-basics', function (hooks) {
15591550
};
15601551
}
15611552

1562-
await shimModule(
1563-
`${testRealmURL}test-cards`,
1564-
{
1565-
Person,
1566-
Employee,
1567-
Customer,
1568-
Group,
1569-
},
1570-
loader,
1571-
);
1553+
loader.shimModule(`${testRealmURL}test-cards`, {
1554+
Person,
1555+
Employee,
1556+
Customer,
1557+
Group,
1558+
});
15721559

15731560
let group = new Group({
15741561
people: [
@@ -1708,7 +1695,7 @@ module('Integration | card-basics', function (hooks) {
17081695
@field firstName = contains(StringField);
17091696
@field languagesSpoken = containsMany(StringField);
17101697
}
1711-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
1698+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
17121699
assert.throws(
17131700
() => new Person({ languagesSpoken: 'english' }),
17141701
/Expected array for field value languagesSpoken/,
@@ -1735,7 +1722,7 @@ module('Integration | card-basics', function (hooks) {
17351722
@field title = contains(StringField);
17361723
@field author = contains(Person);
17371724
}
1738-
await shimModule(`${testRealmURL}test-cards`, { Post, Person }, loader);
1725+
loader.shimModule(`${testRealmURL}test-cards`, { Post, Person });
17391726

17401727
let helloWorld = new Post({
17411728
title: 'My Post',
@@ -1777,7 +1764,7 @@ module('Integration | card-basics', function (hooks) {
17771764
},
17781765
});
17791766
}
1780-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
1767+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
17811768

17821769
let mango = new Person({ firstName: 'Mango', isCool: true });
17831770
let root = await renderCard(loader, mango, 'isolated');
@@ -1797,7 +1784,7 @@ module('Integration | card-basics', function (hooks) {
17971784
@field isCool = contains(BooleanField);
17981785
@field isHuman = contains(BooleanField);
17991786
}
1800-
await shimModule(`${testRealmURL}test-cards`, { Person }, loader);
1787+
loader.shimModule(`${testRealmURL}test-cards`, { Person });
18011788
let mango = new Person({
18021789
firstName: 'Mango',
18031790
isCool: true,
@@ -1903,7 +1890,7 @@ module('Integration | card-basics', function (hooks) {
19031890
</template>
19041891
};
19051892
}
1906-
await shimModule(`${testRealmURL}test-cards`, { Post, Person }, loader);
1893+
loader.shimModule(`${testRealmURL}test-cards`, { Post, Person });
19071894

19081895
let helloWorld = new Post({
19091896
title: 'First Post',
@@ -2199,11 +2186,7 @@ module('Integration | card-basics', function (hooks) {
21992186
@field favoritePlaces = linksToMany(Country);
22002187
}
22012188

2202-
await shimModule(
2203-
`${testRealmURL}test-cards`,
2204-
{ Country, ContactCard },
2205-
loader,
2206-
);
2189+
loader.shimModule(`${testRealmURL}test-cards`, { Country, ContactCard });
22072190

22082191
let us = new Country({ countryName: 'United States', flag: '🇺🇸' });
22092192
let canada = new Country({ countryName: 'Canada', flag: '🇨🇦' });

‎packages/host/tests/integration/components/card-editor-test.gts

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { CardDef } from 'https://cardstack.com/base/card-api';
2424

2525
import {
2626
testRealmURL,
27-
shimModule,
2827
setupCardLogs,
2928
setupLocalIndexing,
3029
saveCard,
@@ -238,7 +237,7 @@ module('Integration | card-editor', function (hooks) {
238237
</template>
239238
};
240239
}
241-
await shimModule(`${testRealmURL}test-cards`, { TestCard }, loader);
240+
loader.shimModule(`${testRealmURL}test-cards`, { TestCard });
242241
let card = new TestCard({ firstName: 'Mango', lastName: 'Abdel-Rahman' });
243242
await saveCard(card, `${testRealmURL}test-cards/test-card`, loader);
244243

@@ -281,7 +280,7 @@ module('Integration | card-editor', function (hooks) {
281280
</template>
282281
};
283282
}
284-
await shimModule(`${testRealmURL}test-cards`, { TestCard }, loader);
283+
loader.shimModule(`${testRealmURL}test-cards`, { TestCard });
285284

286285
let card = new TestCard({ firstName: 'Mango' });
287286
await saveCard(card, `${testRealmURL}test-cards/test-card`, loader);
@@ -331,7 +330,7 @@ module('Integration | card-editor', function (hooks) {
331330
</template>
332331
};
333332
}
334-
await shimModule(`${testRealmURL}test-cards`, { TestCard }, loader);
333+
loader.shimModule(`${testRealmURL}test-cards`, { TestCard });
335334
let card = new TestCard({ firstName: 'Mango' });
336335
await saveCard(card, `${testRealmURL}test-cards/test-card`, loader);
337336
await renderComponent(

0 commit comments

Comments
 (0)