@moltenship/calendar-testing 2.0.0-beta.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +42 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ the registry views, your policies and your save logic.
|
|
|
22
22
|
read the `Announcer`; `placementOf(event)` says where an event shows, as comparable text.
|
|
23
23
|
- **Agents.** An AI agent's steps run through ui-sdk's real bridge inside `calendar.act`, with no
|
|
24
24
|
model involved, and `results` says each change's input was `"agent"`. See
|
|
25
|
-
[Changes an agent makes](https://time.molten.sh/docs/testing#changes-an-agent-makes).
|
|
25
|
+
[Changes an agent makes](https://time.molten.sh/docs/react/testing#changes-an-agent-makes).
|
|
26
26
|
|
|
27
27
|
It uses only the public API of `@moltenship/calendar` and `@moltenship/calendar-recurrence`, and
|
|
28
28
|
depends on no test runner: it works in Vitest with jsdom or happy-dom, and in Vitest's browser
|
|
@@ -66,7 +66,7 @@ pnpm add -D @moltenship/calendar-testing
|
|
|
66
66
|
|
|
67
67
|
## Documentation
|
|
68
68
|
|
|
69
|
-
- [Testing](https://time.molten.sh/docs/testing)
|
|
69
|
+
- [Testing](https://time.molten.sh/docs/react/testing)
|
|
70
70
|
- [Repository](https://github.com/Moltenship/time)
|
|
71
71
|
|
|
72
72
|
## License
|
package/dist/index.d.mts
CHANGED
|
@@ -530,6 +530,8 @@ export declare function renderCalendar<TEvent, TResource, TViewDef extends AnyCa
|
|
|
530
530
|
* then that mentions hydration counts. React's development build logs those warnings and its
|
|
531
531
|
* production build doesn't, so test with the development build. The server render runs in the
|
|
532
532
|
* test's own environment, so code that checks for `window` takes its browser branch there too.
|
|
533
|
+
* Without the Popover API, as in jsdom, its methods do nothing until the calendar unmounts, as
|
|
534
|
+
* they would in a browser with no popup open.
|
|
533
535
|
*/
|
|
534
536
|
export declare function hydrateCalendar<TEvent, TResource, TViewDef extends AnyCalendarView, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId>(Calendar: CalendarFactory<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>, options?: RenderCalendarOptions<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>): Promise<HydratedCalendarHarness<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>>;
|
|
535
537
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1121,7 +1121,7 @@ function setUp(Calendar, initialOptions) {
|
|
|
1121
1121
|
if (observed === void 0) throw new Error("The calendar hasn't rendered yet.");
|
|
1122
1122
|
return observed;
|
|
1123
1123
|
}
|
|
1124
|
-
function harness(container, root, recoverableErrors, ownsContainer) {
|
|
1124
|
+
function harness(container, root, recoverableErrors, ownsContainer, onUnmount) {
|
|
1125
1125
|
let active = true;
|
|
1126
1126
|
const ensureMounted = () => {
|
|
1127
1127
|
if (!active) throw new Error("The calendar was unmounted.");
|
|
@@ -1142,6 +1142,7 @@ function setUp(Calendar, initialOptions) {
|
|
|
1142
1142
|
mounted.delete(entry);
|
|
1143
1143
|
await act(async () => root.unmount());
|
|
1144
1144
|
if (ownsContainer) container.remove();
|
|
1145
|
+
onUnmount?.();
|
|
1145
1146
|
} };
|
|
1146
1147
|
mounted.add(entry);
|
|
1147
1148
|
const { dispose: _dispose, ...inspect } = inspection;
|
|
@@ -1236,6 +1237,34 @@ async function renderCalendar(Calendar, options = {}) {
|
|
|
1236
1237
|
await act(async () => root.render(element()));
|
|
1237
1238
|
return rendered;
|
|
1238
1239
|
}
|
|
1240
|
+
/** How many mounted calendars borrow the Popover API's methods, which go when the last unmounts. */
|
|
1241
|
+
let popoverApiBorrowers = 0;
|
|
1242
|
+
/**
|
|
1243
|
+
* Gives an environment without the Popover API, such as jsdom, methods that do nothing, and
|
|
1244
|
+
* returns what takes them away again. Browsers have the API; without it ui-sdk's popups render in
|
|
1245
|
+
* a portal, which a server render can't.
|
|
1246
|
+
*/
|
|
1247
|
+
function lendPopoverApi() {
|
|
1248
|
+
if (typeof HTMLElement === "undefined") return () => {};
|
|
1249
|
+
const prototype = HTMLElement.prototype;
|
|
1250
|
+
if (popoverApiBorrowers === 0) {
|
|
1251
|
+
if (typeof prototype.showPopover === "function") return () => {};
|
|
1252
|
+
prototype.showPopover = () => {};
|
|
1253
|
+
prototype.hidePopover = () => {};
|
|
1254
|
+
prototype.togglePopover = () => false;
|
|
1255
|
+
}
|
|
1256
|
+
popoverApiBorrowers += 1;
|
|
1257
|
+
let returned = false;
|
|
1258
|
+
return () => {
|
|
1259
|
+
if (returned) return;
|
|
1260
|
+
returned = true;
|
|
1261
|
+
popoverApiBorrowers -= 1;
|
|
1262
|
+
if (popoverApiBorrowers > 0) return;
|
|
1263
|
+
delete prototype.showPopover;
|
|
1264
|
+
delete prototype.hidePopover;
|
|
1265
|
+
delete prototype.togglePopover;
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1239
1268
|
/** Whether a console message is one of React's hydration warnings. */
|
|
1240
1269
|
function isHydrationWarning(args) {
|
|
1241
1270
|
return args.some((arg) => typeof arg === "string" && /hydrat/iu.test(arg));
|
|
@@ -1248,10 +1277,19 @@ function isHydrationWarning(args) {
|
|
|
1248
1277
|
* then that mentions hydration counts. React's development build logs those warnings and its
|
|
1249
1278
|
* production build doesn't, so test with the development build. The server render runs in the
|
|
1250
1279
|
* test's own environment, so code that checks for `window` takes its browser branch there too.
|
|
1280
|
+
* Without the Popover API, as in jsdom, its methods do nothing until the calendar unmounts, as
|
|
1281
|
+
* they would in a browser with no popup open.
|
|
1251
1282
|
*/
|
|
1252
1283
|
async function hydrateCalendar(Calendar, options = {}) {
|
|
1253
1284
|
const { element, harness } = setUp(Calendar, options);
|
|
1254
|
-
const
|
|
1285
|
+
const returnPopoverApi = lendPopoverApi();
|
|
1286
|
+
let serverMarkup;
|
|
1287
|
+
try {
|
|
1288
|
+
serverMarkup = renderToString(element(), { identifierPrefix: options.identifierPrefix });
|
|
1289
|
+
} catch (error) {
|
|
1290
|
+
returnPopoverApi();
|
|
1291
|
+
throw error;
|
|
1292
|
+
}
|
|
1255
1293
|
const { container, owns } = containerFor(options);
|
|
1256
1294
|
container.innerHTML = serverMarkup;
|
|
1257
1295
|
const problems = [];
|
|
@@ -1277,11 +1315,12 @@ async function hydrateCalendar(Calendar, options = {}) {
|
|
|
1277
1315
|
await act(async () => root?.unmount());
|
|
1278
1316
|
} catch {}
|
|
1279
1317
|
if (owns) container.remove();
|
|
1318
|
+
returnPopoverApi();
|
|
1280
1319
|
throw error;
|
|
1281
1320
|
} finally {
|
|
1282
1321
|
console.error = consoleError;
|
|
1283
1322
|
}
|
|
1284
|
-
const hydrated = harness(container, root, recoverableErrors, owns);
|
|
1323
|
+
const hydrated = harness(container, root, recoverableErrors, owns, returnPopoverApi);
|
|
1285
1324
|
if (problems.length > 0) {
|
|
1286
1325
|
await hydrated.unmount();
|
|
1287
1326
|
throw new HydrationMismatchError(problems, serverMarkup);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moltenship/calendar-testing",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Test helpers for apps built on Moltenship Time: a deterministic environment, typed builders and fixtures, a render and hydration harness, queries, and keyboard and pointer drivers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"calendar",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"typescript",
|
|
14
14
|
"vitest"
|
|
15
15
|
],
|
|
16
|
-
"homepage": "https://time.molten.sh/docs/testing",
|
|
16
|
+
"homepage": "https://time.molten.sh/docs/react/testing",
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/Moltenship/time/issues"
|
|
19
19
|
},
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@moltenship/calendar": "2.0.0
|
|
43
|
-
"@moltenship/calendar-recurrence": "2.0.0
|
|
42
|
+
"@moltenship/calendar": "2.0.0",
|
|
43
|
+
"@moltenship/calendar-recurrence": "2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/react": "19.3.0",
|