toiljs 0.0.116 → 0.0.118
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/CHANGELOG.md +14 -0
- package/README.md +16 -7
- package/build/backend/.tsbuildinfo +1 -1
- package/build/cli/.tsbuildinfo +1 -1
- package/build/cli/index.js +2375 -258
- package/build/client/.tsbuildinfo +1 -1
- package/build/client/auth.d.ts +3 -0
- package/build/client/auth.js +19 -10
- package/build/client/dev/devtools.js +1 -1
- package/build/client/dev/error-overlay.js +1 -1
- package/build/client/index.d.ts +1 -1
- package/build/client/index.js +1 -1
- package/build/client/navigation/navigation.js +28 -3
- package/build/client/routing/Router.js +5 -2
- package/build/client/routing/mount.js +1 -1
- package/build/compiler/.tsbuildinfo +1 -1
- package/build/compiler/auth-emails.js +7 -3
- package/build/compiler/emails.js +1 -1
- package/build/compiler/index.d.ts +1 -0
- package/build/compiler/index.js +26 -5
- package/build/compiler/pages.js +2 -3
- package/build/compiler/prerender.d.ts +3 -8
- package/build/compiler/prerender.js +88 -127
- package/build/compiler/ssg.js +3 -4
- package/build/compiler/template-build.js +3 -4
- package/build/compiler/toil-docs.generated.js +8 -7
- package/build/compiler/vite.js +4 -6
- package/build/devserver/.tsbuildinfo +1 -1
- package/build/devserver/db/database.js +7 -3
- package/build/devserver/db/types.js +1 -1
- package/build/devserver/production.js +4 -3
- package/build/devserver/runtime/crypto.d.ts +1 -1
- package/build/io/.tsbuildinfo +1 -1
- package/build/logger/.tsbuildinfo +1 -1
- package/build/shared/.tsbuildinfo +1 -1
- package/examples/basic/client/routes/analytics.tsx +7 -5
- package/examples/basic/client/routes/pq.tsx +2 -1
- package/examples/basic/server/tsconfig.json +1 -3
- package/package.json +45 -44
- package/presets/no-uint8array-tostring.js +120 -153
- package/presets/oxlint.d.ts +5 -0
- package/presets/oxlint.js +224 -0
- package/server/auth/AuthController.ts +53 -14
- package/server/auth/FactorSettings.ts +41 -0
- package/server/auth/SessionEpochs.ts +58 -0
- package/server/auth/SessionRevocations.ts +13 -0
- package/server/globals/auth.ts +27 -2
- package/server/runtime/tsconfig.json +1 -3
- package/tsconfig.json +2 -11
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
- package/.github/ISSUE_TEMPLATE/config.yml +0 -8
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
- package/.github/changelog-config.json +0 -45
- package/.github/dependabot.yml +0 -27
- package/.github/workflows/ci.yml +0 -222
- package/.vscode/settings.json +0 -10
- package/docs/README.md +0 -107
- package/docs/auth/README.md +0 -104
- package/docs/auth/configuration.md +0 -105
- package/docs/auth/emails.md +0 -92
- package/docs/auth/extending.md +0 -202
- package/docs/auth/how-it-works.md +0 -138
- package/docs/auth/usage.md +0 -188
- package/docs/backend/README.md +0 -143
- package/docs/backend/data.md +0 -351
- package/docs/backend/rest.md +0 -402
- package/docs/backend/rpc.md +0 -226
- package/docs/background/README.md +0 -114
- package/docs/background/daemons.md +0 -276
- package/docs/background/derive.md +0 -179
- package/docs/cli/README.md +0 -379
- package/docs/concepts/ai-guide.md +0 -132
- package/docs/concepts/config.md +0 -416
- package/docs/concepts/decorators.md +0 -127
- package/docs/concepts/security.md +0 -108
- package/docs/concepts/tiers.md +0 -166
- package/docs/concepts/types.md +0 -216
- package/docs/database/README.md +0 -143
- package/docs/database/capacity.md +0 -350
- package/docs/database/counters.md +0 -174
- package/docs/database/documents.md +0 -277
- package/docs/database/events.md +0 -307
- package/docs/database/membership.md +0 -246
- package/docs/database/setup.md +0 -155
- package/docs/database/unique.md +0 -216
- package/docs/database/views.md +0 -246
- package/docs/frontend/README.md +0 -104
- package/docs/frontend/components.md +0 -286
- package/docs/frontend/data-fetching.md +0 -260
- package/docs/frontend/images.md +0 -148
- package/docs/frontend/metadata.md +0 -344
- package/docs/frontend/navigation.md +0 -296
- package/docs/frontend/rendering.md +0 -236
- package/docs/frontend/routing.md +0 -346
- package/docs/frontend/scripts.md +0 -118
- package/docs/frontend/search.md +0 -191
- package/docs/frontend/styling.md +0 -147
- package/docs/frontend/toil-global.md +0 -216
- package/docs/getting-started/README.md +0 -81
- package/docs/getting-started/create-project.md +0 -131
- package/docs/getting-started/deploy.md +0 -101
- package/docs/getting-started/first-app.md +0 -215
- package/docs/getting-started/installation.md +0 -124
- package/docs/getting-started/migrating.md +0 -125
- package/docs/getting-started/project-structure.md +0 -163
- package/docs/introduction/README.md +0 -66
- package/docs/introduction/design-principles.md +0 -81
- package/docs/introduction/distributed.md +0 -91
- package/docs/introduction/how-it-works.md +0 -121
- package/docs/introduction/hyperscale.md +0 -70
- package/docs/introduction/modern-stack.md +0 -85
- package/docs/introduction/vs-other-frameworks.md +0 -64
- package/docs/introduction/why-toil.md +0 -99
- package/docs/llms.txt +0 -95
- package/docs/realtime/README.md +0 -102
- package/docs/realtime/channels.md +0 -211
- package/docs/realtime/streams.md +0 -369
- package/docs/services/README.md +0 -60
- package/docs/services/analytics.md +0 -279
- package/docs/services/caching.md +0 -175
- package/docs/services/cookies.md +0 -235
- package/docs/services/crypto.md +0 -209
- package/docs/services/email.md +0 -289
- package/docs/services/environment.md +0 -141
- package/docs/services/ratelimit.md +0 -174
- package/docs/services/time.md +0 -85
- package/eslint.config.js +0 -57
- package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
- package/presets/eslint.js +0 -88
- package/src/backend/index.ts +0 -204
- package/src/cli/configure.ts +0 -363
- package/src/cli/create.ts +0 -924
- package/src/cli/db.ts +0 -158
- package/src/cli/diagnostics.ts +0 -665
- package/src/cli/doctor.ts +0 -982
- package/src/cli/features.ts +0 -170
- package/src/cli/index.ts +0 -326
- package/src/cli/notify.ts +0 -120
- package/src/cli/proc.ts +0 -56
- package/src/cli/ui.ts +0 -169
- package/src/cli/update.ts +0 -248
- package/src/cli/updates.ts +0 -92
- package/src/cli/validate.ts +0 -31
- package/src/cli/version-check.ts +0 -125
- package/src/client/auth.ts +0 -869
- package/src/client/channel/channel.ts +0 -146
- package/src/client/components/Form.tsx +0 -65
- package/src/client/components/Image.tsx +0 -160
- package/src/client/components/Script.tsx +0 -113
- package/src/client/components/Slot.tsx +0 -21
- package/src/client/dev/devtools.tsx +0 -1089
- package/src/client/dev/error-overlay.tsx +0 -225
- package/src/client/errors.ts +0 -11
- package/src/client/head/head.ts +0 -182
- package/src/client/head/metadata.ts +0 -110
- package/src/client/index.ts +0 -130
- package/src/client/navigation/Link.tsx +0 -108
- package/src/client/navigation/NavLink.tsx +0 -86
- package/src/client/navigation/navigation.ts +0 -235
- package/src/client/navigation/prefetch.ts +0 -169
- package/src/client/navigation/scroll.ts +0 -53
- package/src/client/routing/Router.tsx +0 -216
- package/src/client/routing/action.ts +0 -122
- package/src/client/routing/error-boundary.tsx +0 -43
- package/src/client/routing/hooks.ts +0 -140
- package/src/client/routing/lazy.ts +0 -77
- package/src/client/routing/loader.ts +0 -381
- package/src/client/routing/match.ts +0 -47
- package/src/client/routing/mount.tsx +0 -90
- package/src/client/routing/params-context.ts +0 -10
- package/src/client/routing/slot-context.ts +0 -7
- package/src/client/rpc.ts +0 -97
- package/src/client/search/search.ts +0 -189
- package/src/client/search/use-page-search.ts +0 -73
- package/src/client/ssr/markers.tsx +0 -172
- package/src/client/stream/client.ts +0 -237
- package/src/client/types.ts +0 -73
- package/src/compiler/auth-emails.ts +0 -312
- package/src/compiler/config.ts +0 -369
- package/src/compiler/docs.ts +0 -127
- package/src/compiler/email-preview.ts +0 -314
- package/src/compiler/emails.ts +0 -404
- package/src/compiler/fonts.ts +0 -89
- package/src/compiler/generate.ts +0 -471
- package/src/compiler/image-blur.ts +0 -42
- package/src/compiler/image-report.ts +0 -88
- package/src/compiler/index.ts +0 -1362
- package/src/compiler/pages.ts +0 -49
- package/src/compiler/plugin.ts +0 -391
- package/src/compiler/prerender.ts +0 -263
- package/src/compiler/routes.ts +0 -170
- package/src/compiler/seo.ts +0 -415
- package/src/compiler/sri.ts +0 -144
- package/src/compiler/ssg.ts +0 -177
- package/src/compiler/ssr-codegen.ts +0 -85
- package/src/compiler/template-build.ts +0 -676
- package/src/compiler/template.ts +0 -262
- package/src/compiler/toil-docs.generated.ts +0 -77
- package/src/compiler/vite.ts +0 -245
- package/src/devserver/analytics/index.ts +0 -317
- package/src/devserver/config/dotenv.ts +0 -102
- package/src/devserver/config/env.ts +0 -30
- package/src/devserver/config/ratelimit.ts +0 -123
- package/src/devserver/daemon/catalog.ts +0 -120
- package/src/devserver/daemon/cron.ts +0 -87
- package/src/devserver/daemon/host.ts +0 -134
- package/src/devserver/daemon/index.ts +0 -369
- package/src/devserver/daemon/runtime.ts +0 -48
- package/src/devserver/db/catalog.ts +0 -109
- package/src/devserver/db/database.ts +0 -1834
- package/src/devserver/db/derives.ts +0 -121
- package/src/devserver/db/index.ts +0 -20
- package/src/devserver/db/routeKinds.ts +0 -191
- package/src/devserver/db/types.ts +0 -168
- package/src/devserver/email/caps.ts +0 -0
- package/src/devserver/email/config.ts +0 -141
- package/src/devserver/email/console.ts +0 -348
- package/src/devserver/email/index.ts +0 -155
- package/src/devserver/email/providers.ts +0 -131
- package/src/devserver/email/status.ts +0 -23
- package/src/devserver/email/validate.ts +0 -37
- package/src/devserver/email/wire.ts +0 -55
- package/src/devserver/http/cache.ts +0 -0
- package/src/devserver/http/envelope.ts +0 -157
- package/src/devserver/http/proxy.ts +0 -172
- package/src/devserver/http/runtime.ts +0 -387
- package/src/devserver/index.ts +0 -43
- package/src/devserver/production-ipc.ts +0 -63
- package/src/devserver/production-worker.ts +0 -83
- package/src/devserver/production.ts +0 -718
- package/src/devserver/runtime/crypto.ts +0 -587
- package/src/devserver/runtime/host.ts +0 -427
- package/src/devserver/runtime/module.ts +0 -442
- package/src/devserver/server.ts +0 -251
- package/src/devserver/ssr.ts +0 -208
- package/src/devserver/stream/catalog.ts +0 -106
- package/src/devserver/stream/host.ts +0 -42
- package/src/devserver/stream/index.ts +0 -301
- package/src/devserver/stream/manager.ts +0 -167
- package/src/devserver/stream/router.ts +0 -101
- package/src/devserver/stream/wire.ts +0 -58
- package/src/devserver/stream/ws.ts +0 -78
- package/src/devserver/wasm/sections.ts +0 -59
- package/src/devserver/wasm/surface.ts +0 -115
- package/src/io/FastMap.ts +0 -151
- package/src/io/FastSet.ts +0 -113
- package/src/io/codec.ts +0 -362
- package/src/io/index.ts +0 -10
- package/src/io/lengths.ts +0 -14
- package/src/io/types.ts +0 -19
- package/src/logger/index.ts +0 -22
- package/src/shared/index.ts +0 -46
- package/test/analytics-dev.test.ts +0 -113
- package/test/assembly/aspect-shim.ts +0 -33
- package/test/assembly/cookie.spec.ts +0 -303
- package/test/assembly/example.spec.ts +0 -22
- package/test/assembly/ssr.spec.ts +0 -95
- package/test/assembly.test.ts +0 -59
- package/test/auth-emails.test.ts +0 -118
- package/test/built-ssr.test.ts +0 -148
- package/test/channel.test.ts +0 -21
- package/test/config-host-port.test.ts +0 -59
- package/test/configure.test.ts +0 -94
- package/test/daemon-build.test.ts +0 -278
- package/test/daemon-catalog.test.ts +0 -349
- package/test/daemon-emulation.test.ts +0 -256
- package/test/db.test.ts +0 -0
- package/test/devserver-database.test.ts +0 -1102
- package/test/devserver-email.test.ts +0 -306
- package/test/devserver-pqauth.test.ts +0 -93
- package/test/devserver-secrets.test.ts +0 -63
- package/test/devserver.test.ts +0 -259
- package/test/doctor.test.ts +0 -298
- package/test/dom/Image.test.tsx +0 -144
- package/test/dom/Link.test.tsx +0 -67
- package/test/dom/NavLink.test.tsx +0 -37
- package/test/dom/Script.test.tsx +0 -48
- package/test/dom/action.test.tsx +0 -146
- package/test/dom/error-overlay.test.tsx +0 -44
- package/test/dom/loader.test.tsx +0 -121
- package/test/dom/navigation.test.ts +0 -59
- package/test/dom/revalidate.test.tsx +0 -38
- package/test/dom/route-head.test.tsx +0 -56
- package/test/dom/router-loading.test.tsx +0 -44
- package/test/dom/scroll.test.ts +0 -56
- package/test/dom/slot.test.tsx +0 -131
- package/test/dom/use-metadata.test.tsx +0 -58
- package/test/dom/view-transitions.test.tsx +0 -53
- package/test/dynamic-routing.test.ts +0 -132
- package/test/email-console.test.ts +0 -86
- package/test/email-preview.test.ts +0 -73
- package/test/emails.test.ts +0 -58
- package/test/errors.test.ts +0 -21
- package/test/example-guestbook.test.ts +0 -123
- package/test/features.test.ts +0 -149
- package/test/fixtures/bignum-wire/spec.ts +0 -25
- package/test/fixtures/daemon-app.ts +0 -65
- package/test/fixtures/stream-echo.ts +0 -26
- package/test/fixtures/stream-gate.ts +0 -28
- package/test/fixtures/stream-trap.ts +0 -18
- package/test/fixtures/stream-typed.ts +0 -41
- package/test/fonts.test.ts +0 -28
- package/test/global-setup.ts +0 -17
- package/test/head.test.ts +0 -42
- package/test/image-blur.test.ts +0 -50
- package/test/io.test.ts +0 -117
- package/test/metadata.test.ts +0 -40
- package/test/navlink.test.ts +0 -28
- package/test/pages.test.ts +0 -105
- package/test/placeholder.test.ts +0 -9
- package/test/pqauth-e2e.test.ts +0 -216
- package/test/pqauth-email.test.ts +0 -801
- package/test/prerender.test.ts +0 -116
- package/test/prettier-plugin.test.ts +0 -46
- package/test/routes.test.ts +0 -76
- package/test/rpc-bignum-wire.test.ts +0 -164
- package/test/rpc-dispatch.test.ts +0 -132
- package/test/rpc-kinds.test.ts +0 -18
- package/test/rpc.test.ts +0 -66
- package/test/search.test.ts +0 -114
- package/test/seo.test.ts +0 -175
- package/test/slot-layouts.test.ts +0 -69
- package/test/sri.test.ts +0 -129
- package/test/ssg.test.ts +0 -36
- package/test/ssr-hydration.test.tsx +0 -122
- package/test/ssr-render.test.ts +0 -197
- package/test/ssr-template.test.tsx +0 -482
- package/test/stream-emulation.test.ts +0 -479
- package/test/ui.test.ts +0 -40
- package/test/update.test.ts +0 -58
- package/test/validate.test.ts +0 -42
- package/test/version-check.test.ts +0 -130
- package/tests/data-parity/generated-parity.ts +0 -99
- package/tests/data-parity/parity.ts +0 -80
- package/tests/data-parity/spec.ts +0 -46
package/test/dom/Image.test.tsx
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { cleanup, fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Image } from '../../src/client/components/Image';
|
|
6
|
-
|
|
7
|
-
afterEach(cleanup);
|
|
8
|
-
|
|
9
|
-
describe('Image', () => {
|
|
10
|
-
it('lazy-loads and decodes async by default, with the given dimensions', () => {
|
|
11
|
-
const { getByAltText } = render(
|
|
12
|
-
<Image
|
|
13
|
-
src="/a.png"
|
|
14
|
-
alt="a"
|
|
15
|
-
width={200}
|
|
16
|
-
height={100}
|
|
17
|
-
/>,
|
|
18
|
-
);
|
|
19
|
-
const img = getByAltText('a') as HTMLImageElement;
|
|
20
|
-
expect(img.getAttribute('src')).toBe('/a.png');
|
|
21
|
-
expect(img.getAttribute('loading')).toBe('lazy');
|
|
22
|
-
expect(img.getAttribute('decoding')).toBe('async');
|
|
23
|
-
expect(img.getAttribute('width')).toBe('200');
|
|
24
|
-
expect(img.getAttribute('height')).toBe('100');
|
|
25
|
-
expect(img.getAttribute('fetchpriority')).toBe('auto');
|
|
26
|
-
// width+height reserve space via an explicit aspect-ratio (survives responsive `width:100%`).
|
|
27
|
-
expect(img.style.aspectRatio).toBe('200 / 100');
|
|
28
|
-
expect(img.className).toBe('');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('priority images load eagerly with high fetch priority', () => {
|
|
32
|
-
const { getByAltText } = render(
|
|
33
|
-
<Image
|
|
34
|
-
src="/hero.png"
|
|
35
|
-
alt="hero"
|
|
36
|
-
priority
|
|
37
|
-
/>,
|
|
38
|
-
);
|
|
39
|
-
const img = getByAltText('hero') as HTMLImageElement;
|
|
40
|
-
expect(img.getAttribute('loading')).toBe('eager');
|
|
41
|
-
expect(img.getAttribute('fetchpriority')).toBe('high');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('fill wraps the image in a box; the image lays out via a class, not inline styles', () => {
|
|
45
|
-
const { getByAltText } = render(
|
|
46
|
-
<Image
|
|
47
|
-
src="/bg.png"
|
|
48
|
-
alt="bg"
|
|
49
|
-
fill
|
|
50
|
-
objectFit="cover"
|
|
51
|
-
/>,
|
|
52
|
-
);
|
|
53
|
-
const img = getByAltText('bg') as HTMLImageElement;
|
|
54
|
-
expect(img.hasAttribute('width')).toBe(false);
|
|
55
|
-
expect(img.hasAttribute('height')).toBe(false);
|
|
56
|
-
// The fill layout comes from a shipped, overridable CSS class, NOT inline positioning.
|
|
57
|
-
expect(img.classList.contains('toil-img-fill')).toBe(true);
|
|
58
|
-
expect(img.style.position).toBe('');
|
|
59
|
-
// objectFit is genuinely per-instance, so it stays inline.
|
|
60
|
-
expect(img.style.objectFit).toBe('cover');
|
|
61
|
-
// The image is wrapped in a <span> box the caller sizes, so it fills the box, not the page.
|
|
62
|
-
const box = img.parentElement as HTMLElement;
|
|
63
|
-
expect(box.tagName).toBe('SPAN');
|
|
64
|
-
expect(box.classList.contains('toil-img-fill-box')).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('puts the caller className/size on the fill box, the fill class on the image', () => {
|
|
68
|
-
const { getByAltText } = render(
|
|
69
|
-
<Image
|
|
70
|
-
src="/bg.png"
|
|
71
|
-
alt="bg2"
|
|
72
|
-
fill
|
|
73
|
-
width={400}
|
|
74
|
-
height={300}
|
|
75
|
-
className="hero"
|
|
76
|
-
/>,
|
|
77
|
-
);
|
|
78
|
-
const img = getByAltText('bg2') as HTMLImageElement;
|
|
79
|
-
const box = img.parentElement as HTMLElement;
|
|
80
|
-
// The caller's className + size land on the box (what they size); the image just fills it.
|
|
81
|
-
expect(box.classList.contains('hero')).toBe(true);
|
|
82
|
-
expect(box.classList.contains('toil-img-fill-box')).toBe(true);
|
|
83
|
-
expect(box.style.width).toBe('400px');
|
|
84
|
-
expect(box.style.height).toBe('300px');
|
|
85
|
-
expect(img.classList.contains('toil-img-fill')).toBe(true);
|
|
86
|
-
expect(img.getAttribute('style')).toBe(null);
|
|
87
|
-
expect(img.hasAttribute('width')).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('shows a blur placeholder until the image loads', () => {
|
|
91
|
-
const { getByAltText } = render(
|
|
92
|
-
<Image
|
|
93
|
-
src="/p.png"
|
|
94
|
-
alt="p"
|
|
95
|
-
width={10}
|
|
96
|
-
height={10}
|
|
97
|
-
placeholder="blur"
|
|
98
|
-
blurDataURL="data:image/x"
|
|
99
|
-
/>,
|
|
100
|
-
);
|
|
101
|
-
const img = getByAltText('p') as HTMLImageElement;
|
|
102
|
-
expect(img.classList.contains('toil-img-blur')).toBe(true);
|
|
103
|
-
expect(img.style.backgroundImage).toContain('data:image/x');
|
|
104
|
-
fireEvent.load(img);
|
|
105
|
-
expect(img.style.backgroundImage).toBe('');
|
|
106
|
-
expect(img.classList.contains('toil-img-blur')).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('falls back to a skeleton shimmer when placeholder="blur" has no blurDataURL', () => {
|
|
110
|
-
const { getByAltText } = render(
|
|
111
|
-
<Image src="/s.png" alt="s" width={10} height={10} placeholder="blur" />,
|
|
112
|
-
);
|
|
113
|
-
const img = getByAltText('s') as HTMLImageElement;
|
|
114
|
-
// never a silent no-op: a neutral skeleton paints (not the blur class, no background image)
|
|
115
|
-
expect(img.classList.contains('toil-img-skeleton')).toBe(true);
|
|
116
|
-
expect(img.classList.contains('toil-img-blur')).toBe(false);
|
|
117
|
-
expect(img.style.backgroundImage).toBe('');
|
|
118
|
-
fireEvent.load(img);
|
|
119
|
-
expect(img.classList.contains('toil-img-skeleton')).toBe(false);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('reserves space with an aspect-ratio derived from width+height', () => {
|
|
123
|
-
const { getByAltText } = render(<Image src="/a.png" alt="a" width={400} height={300} />);
|
|
124
|
-
const img = getByAltText('a') as HTMLImageElement;
|
|
125
|
-
expect(img.style.aspectRatio).toBe('400 / 300');
|
|
126
|
-
expect(img.getAttribute('width')).toBe('400');
|
|
127
|
-
expect(img.getAttribute('height')).toBe('300');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('reads src/dimensions/blur from a ?toil import object', () => {
|
|
131
|
-
const { getByAltText } = render(
|
|
132
|
-
<Image
|
|
133
|
-
src={{ src: '/hero.webp', width: 40, height: 30, blurDataURL: 'data:image/blur' }}
|
|
134
|
-
alt="h"
|
|
135
|
-
placeholder="blur"
|
|
136
|
-
/>,
|
|
137
|
-
);
|
|
138
|
-
const img = getByAltText('h') as HTMLImageElement;
|
|
139
|
-
expect(img.getAttribute('src')).toBe('/hero.webp');
|
|
140
|
-
expect(img.style.aspectRatio).toBe('40 / 30');
|
|
141
|
-
expect(img.classList.contains('toil-img-blur')).toBe(true);
|
|
142
|
-
expect(img.style.backgroundImage).toContain('data:image/blur');
|
|
143
|
-
});
|
|
144
|
-
});
|
package/test/dom/Link.test.tsx
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { cleanup, fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Link } from '../../src/client/navigation/Link';
|
|
6
|
-
|
|
7
|
-
afterEach(cleanup);
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
window.history.replaceState({}, '', '/');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe('Link', () => {
|
|
13
|
-
it('intercepts a plain internal click (client nav, default prevented)', () => {
|
|
14
|
-
const { getByText } = render(<Link href="/about">go</Link>);
|
|
15
|
-
const prevented = !fireEvent.click(getByText('go'));
|
|
16
|
-
expect(prevented).toBe(true);
|
|
17
|
-
expect(window.location.pathname).toBe('/about');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('does not intercept external links', () => {
|
|
21
|
-
const { getByText } = render(<Link href="https://example.com">ext</Link>);
|
|
22
|
-
const notPrevented = fireEvent.click(getByText('ext'));
|
|
23
|
-
expect(notPrevented).toBe(true);
|
|
24
|
-
expect(window.location.pathname).toBe('/');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('does not intercept modified (cmd/ctrl) clicks', () => {
|
|
28
|
-
const { getByText } = render(<Link href="/about">go</Link>);
|
|
29
|
-
const notPrevented = fireEvent.click(getByText('go'), { metaKey: true });
|
|
30
|
-
expect(notPrevented).toBe(true);
|
|
31
|
-
expect(window.location.pathname).toBe('/');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('ignores a click when href is missing (data-driven href to a page that does not exist)', () => {
|
|
35
|
-
// A runtime-undefined href (e.g. `routeMap[missingKey]`) used to throw on `href.startsWith`
|
|
36
|
-
// inside the click handler. React reports a handler throw as an uncaught *window* error (what
|
|
37
|
-
// the dev overlay surfaces), not a synchronous throw, so assert no such error fires. The anchor
|
|
38
|
-
// is inert now: the click is left to the browser, the page stays put.
|
|
39
|
-
const errors: string[] = [];
|
|
40
|
-
const onError = (e: ErrorEvent): void => {
|
|
41
|
-
errors.push(e.message || String(e.error));
|
|
42
|
-
};
|
|
43
|
-
window.addEventListener('error', onError);
|
|
44
|
-
try {
|
|
45
|
-
const { getByText } = render(<Link href={undefined as unknown as string as never}>x</Link>);
|
|
46
|
-
fireEvent.click(getByText('x'));
|
|
47
|
-
} finally {
|
|
48
|
-
window.removeEventListener('error', onError);
|
|
49
|
-
}
|
|
50
|
-
expect(errors).toEqual([]);
|
|
51
|
-
expect(window.location.pathname).toBe('/');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('forwards anchor attributes (rel, target)', () => {
|
|
55
|
-
const { getByText } = render(
|
|
56
|
-
<Link
|
|
57
|
-
href="https://x.com"
|
|
58
|
-
target="_blank"
|
|
59
|
-
rel="noopener noreferrer">
|
|
60
|
-
x
|
|
61
|
-
</Link>,
|
|
62
|
-
);
|
|
63
|
-
const a = getByText('x') as HTMLAnchorElement;
|
|
64
|
-
expect(a.getAttribute('rel')).toBe('noopener noreferrer');
|
|
65
|
-
expect(a.target).toBe('_blank');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { cleanup, render } from '@testing-library/react';
|
|
3
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { NavLink } from '../../src/client/navigation/NavLink';
|
|
6
|
-
|
|
7
|
-
afterEach(cleanup);
|
|
8
|
-
|
|
9
|
-
describe('NavLink', () => {
|
|
10
|
-
it('adds the active class + aria-current on the current route', () => {
|
|
11
|
-
window.history.replaceState({}, '', '/about');
|
|
12
|
-
const { getByText } = render(<NavLink href="/about">about</NavLink>);
|
|
13
|
-
const a = getByText('about') as HTMLAnchorElement;
|
|
14
|
-
expect(a.className).toContain('active');
|
|
15
|
-
expect(a.getAttribute('aria-current')).toBe('page');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('is not active on a different route', () => {
|
|
19
|
-
window.history.replaceState({}, '', '/home');
|
|
20
|
-
const { getByText } = render(<NavLink href="/about">about</NavLink>);
|
|
21
|
-
const a = getByText('about') as HTMLAnchorElement;
|
|
22
|
-
expect(a.className).not.toContain('active');
|
|
23
|
-
expect(a.getAttribute('aria-current')).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('supports a function className', () => {
|
|
27
|
-
window.history.replaceState({}, '', '/about');
|
|
28
|
-
const { getByText } = render(
|
|
29
|
-
<NavLink
|
|
30
|
-
href="/about"
|
|
31
|
-
className={({ isActive }) => (isActive ? 'on' : 'off')}>
|
|
32
|
-
about
|
|
33
|
-
</NavLink>,
|
|
34
|
-
);
|
|
35
|
-
expect((getByText('about') as HTMLAnchorElement).className).toBe('on');
|
|
36
|
-
});
|
|
37
|
-
});
|
package/test/dom/Script.test.tsx
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { cleanup, render } from '@testing-library/react';
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Script } from '../../src/client/components/Script';
|
|
6
|
-
|
|
7
|
-
afterEach(cleanup);
|
|
8
|
-
|
|
9
|
-
const scriptsFor = (key: string): HTMLScriptElement[] =>
|
|
10
|
-
Array.from(document.querySelectorAll<HTMLScriptElement>(`script[data-toil-script="${key}"]`));
|
|
11
|
-
|
|
12
|
-
describe('Script', () => {
|
|
13
|
-
it('injects an async external script on mount (afterInteractive)', () => {
|
|
14
|
-
render(<Script src="https://cdn.example.com/a.js" />);
|
|
15
|
-
const els = scriptsFor('https://cdn.example.com/a.js');
|
|
16
|
-
expect(els).toHaveLength(1);
|
|
17
|
-
expect(els[0].async).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('dedups: the same src is only injected once across instances', () => {
|
|
21
|
-
const src = 'https://cdn.example.com/dedup.js';
|
|
22
|
-
render(
|
|
23
|
-
<>
|
|
24
|
-
<Script src={src} />
|
|
25
|
-
<Script src={src} />
|
|
26
|
-
</>,
|
|
27
|
-
);
|
|
28
|
-
expect(scriptsFor(src)).toHaveLength(1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('injects an inline script body and fires onLoad + onReady', () => {
|
|
32
|
-
const onLoad = vi.fn();
|
|
33
|
-
const onReady = vi.fn();
|
|
34
|
-
render(
|
|
35
|
-
<Script
|
|
36
|
-
id="inline-1"
|
|
37
|
-
onLoad={onLoad}
|
|
38
|
-
onReady={onReady}>
|
|
39
|
-
{'window.__toilTest = 1;'}
|
|
40
|
-
</Script>,
|
|
41
|
-
);
|
|
42
|
-
const els = scriptsFor('inline-1');
|
|
43
|
-
expect(els).toHaveLength(1);
|
|
44
|
-
expect(els[0].textContent).toBe('window.__toilTest = 1;');
|
|
45
|
-
expect(onLoad).toHaveBeenCalledOnce();
|
|
46
|
-
expect(onReady).toHaveBeenCalledOnce();
|
|
47
|
-
});
|
|
48
|
-
});
|
package/test/dom/action.test.tsx
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { act, cleanup, fireEvent, render, renderHook, waitFor } from '@testing-library/react';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { useAction } from '../../src/client/routing/action';
|
|
6
|
-
import { Form } from '../../src/client/components/Form';
|
|
7
|
-
import { clearLoaderData, loaderKey, readRouteData } from '../../src/client/routing/loader';
|
|
8
|
-
import type { RouteDef } from '../../src/client/types';
|
|
9
|
-
|
|
10
|
-
afterEach(cleanup);
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
clearLoaderData();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('useAction', () => {
|
|
16
|
-
it('goes idle → pending → success and returns the result', async () => {
|
|
17
|
-
const onSuccess = vi.fn();
|
|
18
|
-
const { result } = renderHook(() =>
|
|
19
|
-
useAction((n: number) => Promise.resolve(n * 2), { revalidate: false, onSuccess }),
|
|
20
|
-
);
|
|
21
|
-
expect(result.current.pending).toBe(false);
|
|
22
|
-
|
|
23
|
-
let returned: number | undefined;
|
|
24
|
-
await act(async () => {
|
|
25
|
-
returned = await result.current.run(3);
|
|
26
|
-
});
|
|
27
|
-
expect(returned).toBe(6);
|
|
28
|
-
expect(result.current.data).toBe(6);
|
|
29
|
-
expect(result.current.error).toBeUndefined();
|
|
30
|
-
expect(onSuccess).toHaveBeenCalledWith(6);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('captures errors instead of rejecting, and calls onError', async () => {
|
|
34
|
-
const onError = vi.fn();
|
|
35
|
-
const { result } = renderHook(() =>
|
|
36
|
-
useAction(
|
|
37
|
-
() => {
|
|
38
|
-
throw new Error('boom');
|
|
39
|
-
},
|
|
40
|
-
{ revalidate: false, onError },
|
|
41
|
-
),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
let returned: unknown = 'sentinel';
|
|
45
|
-
await act(async () => {
|
|
46
|
-
returned = await result.current.run();
|
|
47
|
-
});
|
|
48
|
-
expect(returned).toBeUndefined();
|
|
49
|
-
expect((result.current.error as Error).message).toBe('boom');
|
|
50
|
-
expect(onError).toHaveBeenCalledOnce();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('reset() returns to idle', async () => {
|
|
54
|
-
const { result } = renderHook(() => useAction(() => 'x', { revalidate: false }));
|
|
55
|
-
await act(async () => {
|
|
56
|
-
await result.current.run();
|
|
57
|
-
});
|
|
58
|
-
expect(result.current.data).toBe('x');
|
|
59
|
-
act(() => {
|
|
60
|
-
result.current.reset();
|
|
61
|
-
});
|
|
62
|
-
expect(result.current.data).toBeUndefined();
|
|
63
|
-
expect(result.current.pending).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('revalidate: true invalidates cached loader data', async () => {
|
|
67
|
-
const route: RouteDef = {
|
|
68
|
-
pattern: '/x',
|
|
69
|
-
load: () =>
|
|
70
|
-
Promise.resolve({
|
|
71
|
-
default: () => null,
|
|
72
|
-
loader: () => ({ n: 1 }),
|
|
73
|
-
revalidate: false,
|
|
74
|
-
}),
|
|
75
|
-
};
|
|
76
|
-
const key = loaderKey('/x', '');
|
|
77
|
-
// Seed the cache (suspends once, then resolves).
|
|
78
|
-
try {
|
|
79
|
-
readRouteData(route, {}, key, 1);
|
|
80
|
-
} catch (thrown) {
|
|
81
|
-
await (thrown as Promise<void>);
|
|
82
|
-
}
|
|
83
|
-
// Cached now: a re-read returns synchronously (no throw).
|
|
84
|
-
expect(() => readRouteData(route, {}, key, 1)).not.toThrow();
|
|
85
|
-
|
|
86
|
-
const { result } = renderHook(() => useAction(() => 'done', { revalidate: true }));
|
|
87
|
-
await act(async () => {
|
|
88
|
-
await result.current.run();
|
|
89
|
-
});
|
|
90
|
-
// Cache was cleared → reading again suspends (throws a promise).
|
|
91
|
-
expect(() => readRouteData(route, {}, key, 1)).toThrow();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('Form', () => {
|
|
96
|
-
it('submits FormData (no reload) and exposes pending state', async () => {
|
|
97
|
-
let received: FormDataEntryValue | null = null;
|
|
98
|
-
const action = vi.fn((data: FormData) => {
|
|
99
|
-
received = data.get('title');
|
|
100
|
-
});
|
|
101
|
-
const { getByText, getByPlaceholderText } = render(
|
|
102
|
-
<Form
|
|
103
|
-
action={action}
|
|
104
|
-
revalidate={false}>
|
|
105
|
-
{({ pending }) => (
|
|
106
|
-
<>
|
|
107
|
-
<input
|
|
108
|
-
name="title"
|
|
109
|
-
placeholder="t"
|
|
110
|
-
/>
|
|
111
|
-
<button type="submit">{pending ? 'Saving…' : 'Save'}</button>
|
|
112
|
-
</>
|
|
113
|
-
)}
|
|
114
|
-
</Form>,
|
|
115
|
-
);
|
|
116
|
-
fireEvent.change(getByPlaceholderText('t'), { target: { value: 'Hello' } });
|
|
117
|
-
fireEvent.click(getByText('Save'));
|
|
118
|
-
await waitFor(() => {
|
|
119
|
-
expect(action).toHaveBeenCalledOnce();
|
|
120
|
-
});
|
|
121
|
-
expect(received).toBe('Hello');
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('resets fields after success when resetOnSuccess is set', async () => {
|
|
125
|
-
const { getByText, getByPlaceholderText } = render(
|
|
126
|
-
<Form
|
|
127
|
-
action={() => undefined}
|
|
128
|
-
revalidate={false}
|
|
129
|
-
resetOnSuccess>
|
|
130
|
-
<input
|
|
131
|
-
name="title"
|
|
132
|
-
placeholder="t"
|
|
133
|
-
defaultValue=""
|
|
134
|
-
/>
|
|
135
|
-
<button type="submit">Save</button>
|
|
136
|
-
</Form>,
|
|
137
|
-
);
|
|
138
|
-
const input = getByPlaceholderText('t') as HTMLInputElement;
|
|
139
|
-
fireEvent.change(input, { target: { value: 'typed' } });
|
|
140
|
-
expect(input.value).toBe('typed');
|
|
141
|
-
fireEvent.click(getByText('Save'));
|
|
142
|
-
await waitFor(() => {
|
|
143
|
-
expect(input.value).toBe('');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { act, cleanup, fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
DevErrorBoundary,
|
|
7
|
-
DevErrorOverlay,
|
|
8
|
-
initDevErrorOverlay,
|
|
9
|
-
} from '../../src/client/dev/error-overlay';
|
|
10
|
-
|
|
11
|
-
afterEach(cleanup);
|
|
12
|
-
|
|
13
|
-
function Boom(): never {
|
|
14
|
-
throw new Error('render boom');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('dev error overlay', () => {
|
|
18
|
-
it('surfaces an uncaught render error', () => {
|
|
19
|
-
// React logs caught boundary errors to console.error, silence it for a clean test run.
|
|
20
|
-
const spy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
21
|
-
const { getByRole } = render(
|
|
22
|
-
<>
|
|
23
|
-
<DevErrorBoundary>
|
|
24
|
-
<Boom />
|
|
25
|
-
</DevErrorBoundary>
|
|
26
|
-
<DevErrorOverlay />
|
|
27
|
-
</>,
|
|
28
|
-
);
|
|
29
|
-
expect(getByRole('alert').textContent).toContain('render boom');
|
|
30
|
-
spy.mockRestore();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('surfaces an unhandled window error and dismisses it', async () => {
|
|
34
|
-
initDevErrorOverlay();
|
|
35
|
-
const { findByRole, queryByRole, getByText } = render(<DevErrorOverlay />);
|
|
36
|
-
act(() => {
|
|
37
|
-
window.dispatchEvent(new ErrorEvent('error', { error: new Error('async boom') }));
|
|
38
|
-
});
|
|
39
|
-
const alert = await findByRole('alert');
|
|
40
|
-
expect(alert.textContent).toContain('async boom');
|
|
41
|
-
fireEvent.click(getByText('Dismiss'));
|
|
42
|
-
expect(queryByRole('alert')).toBeNull();
|
|
43
|
-
});
|
|
44
|
-
});
|
package/test/dom/loader.test.tsx
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import type { Revalidate } from '../../src/client/routing/loader';
|
|
5
|
-
import {
|
|
6
|
-
clearLoaderData,
|
|
7
|
-
invalidateLoaderData,
|
|
8
|
-
type LoaderData,
|
|
9
|
-
loaderKey,
|
|
10
|
-
readRouteData,
|
|
11
|
-
} from '../../src/client/routing/loader';
|
|
12
|
-
import type { RouteDef } from '../../src/client/types';
|
|
13
|
-
|
|
14
|
-
/** Reads route data, awaiting the suspending promise once if it's pending. */
|
|
15
|
-
async function read(route: RouteDef, key: string, epoch: number): Promise<unknown> {
|
|
16
|
-
try {
|
|
17
|
-
return readRouteData(route, {}, key, epoch).data;
|
|
18
|
-
} catch (thrown) {
|
|
19
|
-
if (thrown instanceof Promise) {
|
|
20
|
-
await thrown;
|
|
21
|
-
return readRouteData(route, {}, key, epoch).data;
|
|
22
|
-
}
|
|
23
|
-
throw thrown;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** A route whose `load()` count tells us how many times the loader actually ran. */
|
|
28
|
-
function makeRoute(revalidate?: Revalidate): { route: RouteDef; loads: () => number } {
|
|
29
|
-
let loads = 0;
|
|
30
|
-
const route: RouteDef = {
|
|
31
|
-
pattern: '/x',
|
|
32
|
-
load: () => {
|
|
33
|
-
loads += 1;
|
|
34
|
-
return Promise.resolve({
|
|
35
|
-
default: () => null,
|
|
36
|
-
loader: () => ({ n: loads }),
|
|
37
|
-
revalidate,
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
return { route, loads: () => loads };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
clearLoaderData();
|
|
46
|
-
});
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
vi.useRealTimers();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('loader caching', () => {
|
|
52
|
-
it('reuses cached data on re-read within the same navigation (loader runs once)', async () => {
|
|
53
|
-
const { route, loads } = makeRoute();
|
|
54
|
-
const key = loaderKey('/x', '');
|
|
55
|
-
await read(route, key, 1);
|
|
56
|
-
await read(route, key, 1);
|
|
57
|
-
expect(loads()).toBe(1);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('a route with no loader stays cached across navigations (never re-suspends)', async () => {
|
|
61
|
-
let loads = 0;
|
|
62
|
-
const route: RouteDef = {
|
|
63
|
-
pattern: '/p',
|
|
64
|
-
load: () => {
|
|
65
|
-
loads += 1;
|
|
66
|
-
return Promise.resolve({ default: () => null });
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
const key = loaderKey('/p', '');
|
|
70
|
-
await read(route, key, 1);
|
|
71
|
-
await read(route, key, 2);
|
|
72
|
-
await read(route, key, 3);
|
|
73
|
-
expect(loads).toBe(1);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('refetches on a new navigation under the default policy', async () => {
|
|
77
|
-
const { route, loads } = makeRoute();
|
|
78
|
-
const key = loaderKey('/x', '');
|
|
79
|
-
await read(route, key, 1);
|
|
80
|
-
await read(route, key, 2);
|
|
81
|
-
expect(loads()).toBe(2);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('revalidate=false caches across navigations', async () => {
|
|
85
|
-
const { route, loads } = makeRoute(false);
|
|
86
|
-
const key = loaderKey('/x', '');
|
|
87
|
-
await read(route, key, 1);
|
|
88
|
-
await read(route, key, 2);
|
|
89
|
-
expect(loads()).toBe(1);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('numeric revalidate caches until the staleTime elapses', async () => {
|
|
93
|
-
vi.useFakeTimers();
|
|
94
|
-
const { route, loads } = makeRoute(1); // 1 second
|
|
95
|
-
const key = loaderKey('/x', '');
|
|
96
|
-
await read(route, key, 1);
|
|
97
|
-
await read(route, key, 2); // still fresh
|
|
98
|
-
expect(loads()).toBe(1);
|
|
99
|
-
vi.advanceTimersByTime(1500); // now stale
|
|
100
|
-
await read(route, key, 3);
|
|
101
|
-
expect(loads()).toBe(2);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('invalidateLoaderData(href) forces a refetch of that route', async () => {
|
|
105
|
-
const { route, loads } = makeRoute(false);
|
|
106
|
-
const key = loaderKey('/x', '');
|
|
107
|
-
await read(route, key, 1);
|
|
108
|
-
invalidateLoaderData('/x');
|
|
109
|
-
await read(route, key, 1);
|
|
110
|
-
expect(loads()).toBe(2);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('useLoaderData type inference', () => {
|
|
115
|
-
it('LoaderData<typeof loader> resolves to the loader return type', () => {
|
|
116
|
-
const loader = async () => Promise.resolve({ a: 1, b: 'x' as string | null });
|
|
117
|
-
expectTypeOf<LoaderData<typeof loader>>().toEqualTypeOf<{ a: number; b: string | null }>();
|
|
118
|
-
// An explicit type still passes straight through.
|
|
119
|
-
expectTypeOf<LoaderData<{ id: number }>>().toEqualTypeOf<{ id: number }>();
|
|
120
|
-
});
|
|
121
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
back,
|
|
6
|
-
isNavigationPending,
|
|
7
|
-
navigate,
|
|
8
|
-
navigationEpoch,
|
|
9
|
-
settleNavigation,
|
|
10
|
-
subscribeLocation,
|
|
11
|
-
} from '../../src/client/navigation/navigation';
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
window.history.replaceState({}, '', '/');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('navigate', () => {
|
|
18
|
-
it('updates the location and notifies subscribers', () => {
|
|
19
|
-
let calls = 0;
|
|
20
|
-
const off = subscribeLocation(() => {
|
|
21
|
-
calls += 1;
|
|
22
|
-
});
|
|
23
|
-
navigate('/about');
|
|
24
|
-
expect(window.location.pathname).toBe('/about');
|
|
25
|
-
expect(calls).toBe(1);
|
|
26
|
-
off();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('replace updates the location too', () => {
|
|
30
|
-
navigate('/replaced', { replace: true });
|
|
31
|
-
expect(window.location.pathname).toBe('/replaced');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('increments the navigation epoch', () => {
|
|
35
|
-
const before = navigationEpoch();
|
|
36
|
-
navigate('/a');
|
|
37
|
-
expect(navigationEpoch()).toBe(before + 1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('is pending after navigate, settled after settleNavigation', () => {
|
|
41
|
-
navigate('/pending');
|
|
42
|
-
expect(isNavigationPending()).toBe(true);
|
|
43
|
-
settleNavigation();
|
|
44
|
-
expect(isNavigationPending()).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('back() triggers a notification', () => {
|
|
48
|
-
navigate('/one');
|
|
49
|
-
navigate('/two');
|
|
50
|
-
let popped = 0;
|
|
51
|
-
const off = subscribeLocation(() => {
|
|
52
|
-
popped += 1;
|
|
53
|
-
});
|
|
54
|
-
back();
|
|
55
|
-
// jsdom fires popstate synchronously for history.back within the same task.
|
|
56
|
-
expect(popped).toBeGreaterThanOrEqual(0);
|
|
57
|
-
off();
|
|
58
|
-
});
|
|
59
|
-
});
|