@krate/runtime 0.5.0-rc.2 → 0.5.0-rc.4

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.
Files changed (155) hide show
  1. package/dist/actions.d.ts +7 -0
  2. package/dist/actions.js +21 -3
  3. package/dist/actions.test.js +8 -410
  4. package/dist/after.d.ts +28 -0
  5. package/dist/after.js +48 -0
  6. package/dist/after.test.js +58 -0
  7. package/dist/assets-static.d.ts +10 -1
  8. package/dist/assets-static.js +10 -2
  9. package/dist/base-path.js +4 -3
  10. package/dist/builtin-tags.d.ts +12 -0
  11. package/dist/builtin-tags.js +42 -0
  12. package/dist/builtin-tags.test.js +12 -0
  13. package/dist/cache-adapter.test.js +4 -203
  14. package/dist/cache-scope.d.ts +2 -0
  15. package/dist/cache.test.js +1 -197
  16. package/dist/cloudflare-workers.d.ts +2 -0
  17. package/dist/cloudflare-workers.js +27 -0
  18. package/dist/dev-overlay.d.ts +54 -3
  19. package/dist/dev-overlay.js +469 -76
  20. package/dist/dom.js +3 -1
  21. package/dist/events.test.js +2 -407
  22. package/dist/handler-html.test.js +1 -202
  23. package/dist/handler-routing.js +3 -0
  24. package/dist/handler-segments.d.ts +6 -0
  25. package/dist/handler-segments.js +16 -2
  26. package/dist/handler-segments.test.js +8 -200
  27. package/dist/head-tags.d.ts +9 -0
  28. package/dist/head-tags.js +85 -1
  29. package/dist/head-tags.test.js +18 -125
  30. package/dist/index.d.ts +1 -5
  31. package/dist/index.js +3 -0
  32. package/dist/inline-action-token.test.js +31 -0
  33. package/dist/jsx-svg-types.test.js +58 -0
  34. package/dist/jsx-types.d.ts +92 -1
  35. package/dist/krate-core.js +1 -1
  36. package/dist/krate-dev.js +384 -65
  37. package/dist/krate-f-actions.js +1 -1
  38. package/dist/krate-f-navigation.js +1 -1
  39. package/dist/krate-f-router-lite.js +1 -1
  40. package/dist/krate-f-router.js +1 -1
  41. package/dist/krate-features.json +2 -0
  42. package/dist/krate-hydrate-lite.js +5 -5
  43. package/dist/krate-hydrate.js +5 -5
  44. package/dist/krate-runtime.js +5 -5
  45. package/dist/link-base-path.test.js +28 -0
  46. package/dist/node-server.test.js +1 -355
  47. package/dist/platform.d.ts +52 -0
  48. package/dist/platform.js +57 -0
  49. package/dist/platform.test.js +44 -0
  50. package/dist/router-nav.test.js +15 -444
  51. package/dist/router.js +39 -1
  52. package/dist/server-handler.d.ts +48 -0
  53. package/dist/server-handler.js +279 -17
  54. package/dist/server-handler.test.js +54 -388
  55. package/dist/server-renderer.test.js +0 -104
  56. package/dist/server.d.ts +15 -5
  57. package/dist/server.js +149 -22
  58. package/dist/server.test.js +52 -60
  59. package/dist/site-config.d.ts +13 -0
  60. package/dist/site-config.js +28 -0
  61. package/dist/site-config.test.js +30 -0
  62. package/dist/slot.d.ts +12 -0
  63. package/dist/slot.js +23 -0
  64. package/dist/slot.test.js +25 -0
  65. package/dist/ssr-core-behavior.test.js +3 -515
  66. package/dist/testing.d.ts +59 -0
  67. package/dist/testing.js +88 -0
  68. package/dist/testing.test.js +73 -0
  69. package/package.json +9 -1
  70. package/dist/action-context.test.js +0 -72
  71. package/dist/base-path.test.js +0 -88
  72. package/dist/class-component.test.js +0 -462
  73. package/dist/class-helpers.test.js +0 -169
  74. package/dist/context.test.js +0 -57
  75. package/dist/derived.test.js +0 -140
  76. package/dist/dev-overlay.test.js +0 -165
  77. package/dist/discrete.test.js +0 -100
  78. package/dist/dom.test.js +0 -39
  79. package/dist/effect-errors.test.d.ts +0 -1
  80. package/dist/effect-errors.test.js +0 -199
  81. package/dist/effects.test.d.ts +0 -1
  82. package/dist/effects.test.js +0 -485
  83. package/dist/handler-routing.test.d.ts +0 -1
  84. package/dist/handler-routing.test.js +0 -99
  85. package/dist/highlight-bind.test.d.ts +0 -1
  86. package/dist/highlight-bind.test.js +0 -124
  87. package/dist/highlight.test.d.ts +0 -1
  88. package/dist/highlight.test.js +0 -56
  89. package/dist/lanes.test.d.ts +0 -1
  90. package/dist/lanes.test.js +0 -59
  91. package/dist/list.test.d.ts +0 -1
  92. package/dist/list.test.js +0 -435
  93. package/dist/metadata.test.d.ts +0 -1
  94. package/dist/metadata.test.js +0 -167
  95. package/dist/navigation.test.d.ts +0 -1
  96. package/dist/navigation.test.js +0 -130
  97. package/dist/optimistic-lanes.test.d.ts +0 -1
  98. package/dist/optimistic-lanes.test.js +0 -45
  99. package/dist/patterns.test.d.ts +0 -1
  100. package/dist/patterns.test.js +0 -125
  101. package/dist/portal.test.d.ts +0 -1
  102. package/dist/portal.test.js +0 -99
  103. package/dist/react-effects.test.d.ts +0 -1
  104. package/dist/react-effects.test.js +0 -133
  105. package/dist/react-suspense.test.d.ts +0 -1
  106. package/dist/react-suspense.test.js +0 -194
  107. package/dist/react.test.d.ts +0 -1
  108. package/dist/react.test.js +0 -60
  109. package/dist/react19.test.d.ts +0 -1
  110. package/dist/react19.test.js +0 -176
  111. package/dist/reactivity-core.test.d.ts +0 -1
  112. package/dist/reactivity-core.test.js +0 -152
  113. package/dist/reconcile.test.d.ts +0 -1
  114. package/dist/reconcile.test.js +0 -110
  115. package/dist/refs.test.d.ts +0 -1
  116. package/dist/refs.test.js +0 -257
  117. package/dist/router-layout.test.d.ts +0 -1
  118. package/dist/router-layout.test.js +0 -249
  119. package/dist/router-slots.test.d.ts +0 -1
  120. package/dist/router-slots.test.js +0 -144
  121. package/dist/router-speculation.test.d.ts +0 -1
  122. package/dist/router-speculation.test.js +0 -25
  123. package/dist/router-styles.test.d.ts +0 -1
  124. package/dist/router-styles.test.js +0 -98
  125. package/dist/router.test.d.ts +0 -1
  126. package/dist/router.test.js +0 -36
  127. package/dist/server-async.test.d.ts +0 -1
  128. package/dist/server-async.test.js +0 -216
  129. package/dist/server-highlight.test.d.ts +0 -1
  130. package/dist/server-highlight.test.js +0 -32
  131. package/dist/signal-lanes.test.d.ts +0 -1
  132. package/dist/signal-lanes.test.js +0 -32
  133. package/dist/slots.test.d.ts +0 -1
  134. package/dist/slots.test.js +0 -187
  135. package/dist/snapshots.test.d.ts +0 -1
  136. package/dist/snapshots.test.js +0 -208
  137. package/dist/ssr-core.test.d.ts +0 -1
  138. package/dist/ssr-core.test.js +0 -324
  139. package/dist/static-memory.test.d.ts +0 -1
  140. package/dist/static-memory.test.js +0 -26
  141. package/dist/storage.test.d.ts +0 -1
  142. package/dist/storage.test.js +0 -46
  143. package/dist/suspense-actions.test.d.ts +0 -1
  144. package/dist/suspense-actions.test.js +0 -72
  145. package/dist/suspense.test.d.ts +0 -1
  146. package/dist/suspense.test.js +0 -556
  147. /package/dist/{action-context.test.d.ts → after.test.d.ts} +0 -0
  148. /package/dist/{base-path.test.d.ts → builtin-tags.test.d.ts} +0 -0
  149. /package/dist/{class-component.test.d.ts → inline-action-token.test.d.ts} +0 -0
  150. /package/dist/{class-helpers.test.d.ts → jsx-svg-types.test.d.ts} +0 -0
  151. /package/dist/{context.test.d.ts → link-base-path.test.d.ts} +0 -0
  152. /package/dist/{derived.test.d.ts → platform.test.d.ts} +0 -0
  153. /package/dist/{dev-overlay.test.d.ts → site-config.test.d.ts} +0 -0
  154. /package/dist/{discrete.test.d.ts → slot.test.d.ts} +0 -0
  155. /package/dist/{dom.test.d.ts → testing.test.d.ts} +0 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Test helpers, exported from `@krate/runtime/testing`. They call an API route
3
+ * module or a server action in-process, without a running server. Node only
4
+ * (it uses AsyncLocalStorage); import it from your test files, never from app
5
+ * code.
6
+ */
7
+ import { AsyncLocalStorage } from "node:async_hooks";
8
+ const METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
9
+ /**
10
+ * Calls a route module the way the server does: the named export for `method`
11
+ * (HEAD falls back to GET without a body, OPTIONS answers `Allow`), else a
12
+ * default Web-style handler, else a 405 with `Allow`. `target` is a path
13
+ * (`"/api/users/7?x=1"`), an absolute URL, or a ready `Request`.
14
+ */
15
+ export async function callRoute(mod, method, target, options = {}) {
16
+ const request = toRequest(method, target, options);
17
+ const context = { params: options.params ?? {} };
18
+ const named = (m) => (typeof mod[m] === "function" ? mod[m] : undefined);
19
+ const fallback = typeof mod.default === "function" ? mod.default : undefined;
20
+ if (fallback && fallback.length >= 2) {
21
+ throw new TypeError("callRoute: a default export with a (req, res) signature is the legacy Node style and is not supported; export named GET/POST handlers instead");
22
+ }
23
+ const direct = named(method);
24
+ if (direct)
25
+ return direct(request, context);
26
+ if (method === "HEAD" && named("GET")) {
27
+ const res = await named("GET")(request, context);
28
+ return new Response(null, { status: res.status, statusText: res.statusText, headers: res.headers });
29
+ }
30
+ if (fallback && !METHODS.some((m) => named(m)))
31
+ return (await fallback(request, context));
32
+ const allow = METHODS.filter((m) => named(m) || (m === "HEAD" && named("GET")));
33
+ if (allow.indexOf("OPTIONS") < 0)
34
+ allow.push("OPTIONS");
35
+ if (method === "OPTIONS")
36
+ return new Response(null, { status: 204, headers: { Allow: allow.join(", ") } });
37
+ return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow.join(", ") } });
38
+ }
39
+ function toRequest(method, target, options) {
40
+ if (typeof target !== "string")
41
+ return target;
42
+ const url = /^https?:\/\//i.test(target) ? target : "http://localhost" + (target.startsWith("/") ? target : "/" + target);
43
+ const headers = new Headers(options.headers);
44
+ let body = options.body;
45
+ if (options.json !== undefined) {
46
+ body = JSON.stringify(options.json);
47
+ if (!headers.has("content-type"))
48
+ headers.set("content-type", "application/json");
49
+ }
50
+ const hasBody = method !== "GET" && method !== "HEAD" && body !== undefined && body !== null;
51
+ return new Request(url, { method, headers, body: hasBody ? body : undefined });
52
+ }
53
+ const ACTION_STORE = Symbol.for("krate.action.store");
54
+ const als = new AsyncLocalStorage();
55
+ /**
56
+ * Runs a server action function with the request context a real call has, so
57
+ * `cookies()`, `headers()` and `getActionContext()` from `@krate/runtime/server`
58
+ * work. The action is the plain exported function you imported from the module.
59
+ */
60
+ export async function runAction(action, options = {}) {
61
+ const jar = new Map(Object.entries(options.cookies ?? {}));
62
+ const setCookies = [];
63
+ const cookies = {
64
+ get: (name) => jar.get(name),
65
+ getAll: () => Array.from(jar, ([name, value]) => ({ name, value })),
66
+ has: (name) => jar.has(name),
67
+ set: (name, value, opts) => {
68
+ setCookies.push({ name, value: String(value), options: opts, deleted: false });
69
+ jar.set(name, String(value));
70
+ },
71
+ delete: (name, opts) => {
72
+ setCookies.push({ name, value: "", options: opts, deleted: true });
73
+ jar.delete(name);
74
+ },
75
+ };
76
+ const context = {
77
+ actionId: options.actionId ?? "test-action",
78
+ url: options.url ?? "/",
79
+ method: "POST",
80
+ headers: new Headers(options.headers),
81
+ cookies,
82
+ };
83
+ // Published once and left in place: concurrent runAction calls share it, and
84
+ // each call's context lives in its own async scope.
85
+ globalThis[ACTION_STORE] = als;
86
+ const result = await als.run(context, async () => action());
87
+ return { result, setCookies };
88
+ }
@@ -0,0 +1,73 @@
1
+ // @vitest-environment node
2
+ import { describe, expect, it } from "vitest";
3
+ import { cookies, headers, redirect } from "./server.js";
4
+ import { callRoute, runAction } from "./testing.js";
5
+ describe("callRoute", () => {
6
+ const route = {
7
+ async GET(req, ctx) {
8
+ const url = new URL(req.url);
9
+ return Response.json({ id: ctx.params.id, q: url.searchParams.get("q") });
10
+ },
11
+ async POST(req) {
12
+ return Response.json(await req.json(), { status: 201 });
13
+ },
14
+ };
15
+ it("passes the request and route params to a named export", async () => {
16
+ const res = await callRoute(route, "GET", "/api/users/7?q=x", { params: { id: "7" } });
17
+ expect(res.status).toBe(200);
18
+ expect(await res.json()).toEqual({ id: "7", q: "x" });
19
+ });
20
+ it("sends a JSON body", async () => {
21
+ const res = await callRoute(route, "POST", "/api/users", { json: { name: "ada" } });
22
+ expect(res.status).toBe(201);
23
+ expect(await res.json()).toEqual({ name: "ada" });
24
+ });
25
+ it("answers HEAD from GET, OPTIONS and 405 like the server", async () => {
26
+ const head = await callRoute(route, "HEAD", "/api/users/7");
27
+ expect(head.status).toBe(200);
28
+ expect(await head.text()).toBe("");
29
+ const options = await callRoute(route, "OPTIONS", "/api/users");
30
+ expect(options.headers.get("allow")).toBe("GET, POST, HEAD, OPTIONS");
31
+ const missing = await callRoute(route, "DELETE", "/api/users");
32
+ expect(missing.status).toBe(405);
33
+ expect(missing.headers.get("allow")).toContain("GET");
34
+ });
35
+ it("calls a default Web handler for every method and rejects the legacy signature", async () => {
36
+ const any = { default: async (req) => new Response(req.method) };
37
+ expect(await (await callRoute(any, "PUT", "/x")).text()).toBe("PUT");
38
+ const legacy = { default: (_req, res) => res.json({}) };
39
+ await expect(callRoute(legacy, "GET", "/x")).rejects.toThrow(/legacy/);
40
+ });
41
+ });
42
+ describe("runAction", () => {
43
+ it("gives the action cookies() and headers() and records cookie writes", async () => {
44
+ async function login() {
45
+ const jar = cookies();
46
+ const before = jar.get("session");
47
+ jar.set("session", "abc", { httpOnly: true });
48
+ jar.delete("old");
49
+ return { before, agent: headers().get("user-agent") };
50
+ }
51
+ const { result, setCookies } = await runAction(login, {
52
+ cookies: { session: "prev", old: "1" },
53
+ headers: { "user-agent": "vitest" },
54
+ });
55
+ expect(result).toEqual({ before: { name: "session", value: "prev" }, agent: "vitest" });
56
+ expect(setCookies).toEqual([
57
+ { name: "session", value: "abc", options: { httpOnly: true }, deleted: false },
58
+ { name: "old", value: "", options: undefined, deleted: true },
59
+ ]);
60
+ });
61
+ it("rejects with what the action throws, including redirect()", async () => {
62
+ await expect(runAction(async () => redirect("/done"))).rejects.toBeDefined();
63
+ await expect(runAction(async () => { throw new Error("nope"); })).rejects.toThrow("nope");
64
+ });
65
+ it("keeps parallel actions apart", async () => {
66
+ const read = async () => {
67
+ await new Promise((r) => setTimeout(r, 5));
68
+ return cookies().get("who");
69
+ };
70
+ const [a, b] = await Promise.all([runAction(read, { cookies: { who: "a" } }), runAction(read, { cookies: { who: "b" } })]);
71
+ expect([a.result, b.result]).toEqual([{ name: "who", value: "a" }, { name: "who", value: "b" }]);
72
+ });
73
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krate/runtime",
3
- "version": "0.5.0-rc.2",
3
+ "version": "0.5.0-rc.4",
4
4
  "description": "Client-side runtime for Krate - signals, hydration, SPA router, resources, and context.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -78,6 +78,10 @@
78
78
  "types": "./dist/node-server.d.ts",
79
79
  "default": "./dist/node-server.js"
80
80
  },
81
+ "./cloudflare-workers": {
82
+ "types": "./dist/cloudflare-workers.d.ts",
83
+ "default": "./dist/cloudflare-workers.js"
84
+ },
81
85
  "./assets-static": {
82
86
  "types": "./dist/assets-static.d.ts",
83
87
  "default": "./dist/assets-static.js"
@@ -93,6 +97,10 @@
93
97
  "./og": {
94
98
  "types": "./dist/og.d.ts",
95
99
  "default": "./dist/og.js"
100
+ },
101
+ "./testing": {
102
+ "types": "./dist/testing.d.ts",
103
+ "default": "./dist/testing.js"
96
104
  }
97
105
  },
98
106
  "files": [
@@ -1,72 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- import { afterEach, describe, expect, it } from 'vitest';
3
- import { cookies, getActionContext, headers, redirect } from './action-context.js';
4
- import { installRenderStore, withCacheScope } from './cache-scope.js';
5
- import { jsx, renderToString } from './server.js';
6
- const KEY = Symbol.for('krate.action.store');
7
- const REQUEST_KEY = Symbol.for('krate.request.store');
8
- afterEach(() => {
9
- delete globalThis[KEY];
10
- delete globalThis[REQUEST_KEY];
11
- });
12
- describe('server action context', () => {
13
- it('throws outside an action with an actionable message', () => {
14
- expect(getActionContext()).toBeUndefined();
15
- expect(() => headers()).toThrow(/only be called while a server action runs/);
16
- });
17
- it('reads headers and cookies from the sidecar store', () => {
18
- const jar = new Map([['sid', 'abc']]);
19
- const ctx = {
20
- actionId: 'a1',
21
- url: '/__krate/action/a1',
22
- method: 'POST',
23
- headers: new Headers({ 'x-test': 'yes' }),
24
- cookies: {
25
- get: (n) => jar.get(n),
26
- getAll: () => [],
27
- has: (n) => jar.has(n),
28
- set: () => { },
29
- delete: () => { },
30
- },
31
- };
32
- globalThis[KEY] = { getStore: () => ctx };
33
- expect(headers().get('x-test')).toBe('yes');
34
- expect(cookies().get('sid')).toEqual({ name: 'sid', value: 'abc' });
35
- expect(cookies().get('sid')?.value).toBe('abc');
36
- expect(cookies().get('missing')).toBeUndefined();
37
- expect(getActionContext()?.cookies.get('sid')).toEqual({ name: 'sid', value: 'abc' });
38
- expect(getActionContext()?.actionId).toBe('a1');
39
- });
40
- it('marks a render uncacheable when headers or cookies are read', async () => {
41
- const ctx = {
42
- url: '/p',
43
- method: 'GET',
44
- headers: new Headers({ 'x-test': 'yes' }),
45
- cookies: new Map([['sid', 'abc']]),
46
- params: {},
47
- searchParams: {},
48
- };
49
- globalThis[REQUEST_KEY] = { getStore: () => ctx };
50
- installRenderStore(new AsyncLocalStorage());
51
- const { scope } = await withCacheScope('/p', () => {
52
- headers();
53
- cookies();
54
- return 'ok';
55
- });
56
- expect(scope.noStore).toBe(true);
57
- });
58
- it('redirect() throws the marker the sidecar turns into a navigation', () => {
59
- let caught;
60
- try {
61
- redirect('/done');
62
- }
63
- catch (e) {
64
- caught = e;
65
- }
66
- expect(caught.__krateRedirect).toBe('/done');
67
- });
68
- it('does not render client function actions as attributes', () => {
69
- const html = renderToString(jsx('form', { action: async () => { }, children: 'x' }));
70
- expect(html).toBe('<form>x</form>');
71
- });
72
- });
@@ -1,88 +0,0 @@
1
- import { describe, it, expect, afterEach, vi } from 'vitest';
2
- import { basePath, withBase } from './base-path';
3
- import { h } from './dom';
4
- import { Link, renderToString, jsx } from './server';
5
- import { initRouter, destroyRouter, navigate, krateRouter } from './router';
6
- function setBase(bp) {
7
- globalThis.__KRATE_CFG__ = bp === undefined ? undefined : { basePath: bp, viewTransitions: false };
8
- }
9
- describe('base path helpers', () => {
10
- afterEach(() => setBase(undefined));
11
- it('normalizes the configured value', () => {
12
- setBase(undefined);
13
- expect(basePath()).toBe('');
14
- setBase('/');
15
- expect(basePath()).toBe('');
16
- setBase('repo/');
17
- expect(basePath()).toBe('/repo');
18
- });
19
- it('prefixes only root-relative URLs', () => {
20
- setBase('/repo');
21
- expect(withBase('/a?x=1#y')).toBe('/repo/a?x=1#y');
22
- for (const u of ['//cdn.test/a', 'https://e.test/a', 'rel', '#top', '?q=1', '', 'mailto:a@b.c']) {
23
- expect(withBase(u)).toBe(u);
24
- }
25
- });
26
- it('leaves URLs alone at the root', () => {
27
- setBase('');
28
- expect(withBase('/a')).toBe('/a');
29
- });
30
- });
31
- describe('<Link> rendering under a base path', () => {
32
- afterEach(() => setBase(undefined));
33
- it('prefixes a client-created link', () => {
34
- setBase('/repo');
35
- const a = h('a', { href: '/about', 'data-krate-link': true });
36
- expect(a.getAttribute('href')).toBe('/repo/about');
37
- });
38
- it('prefixes a reactive href each time', () => {
39
- setBase('/repo');
40
- const a = h('a', { href: () => '/x', 'data-krate-link': true });
41
- expect(a.getAttribute('href')).toBe('/repo/x');
42
- });
43
- it('leaves a plain anchor as written', () => {
44
- setBase('/repo');
45
- const a = h('a', { href: '/about' });
46
- expect(a.getAttribute('href')).toBe('/about');
47
- });
48
- it('prefixes a server-rendered link and leaves external ones', async () => {
49
- setBase('/repo');
50
- expect(await renderToString(jsx(Link, { href: '/about', children: 'a' }))).toContain('href="/repo/about"');
51
- expect(await renderToString(jsx(Link, { href: 'https://e.test/', children: 'a' }))).toContain('href="https://e.test/"');
52
- });
53
- });
54
- describe('navigation under a base path', () => {
55
- afterEach(() => {
56
- destroyRouter();
57
- setBase(undefined);
58
- vi.unstubAllGlobals();
59
- });
60
- it('prefixes a navigation that falls back to a document load', () => {
61
- destroyRouter();
62
- setBase('/repo');
63
- const assign = vi.fn();
64
- const replace = vi.fn();
65
- vi.stubGlobal('location', { assign, replace, href: 'http://x.test/repo/' });
66
- expect(navigate('/about')).toBe(true);
67
- expect(assign).toHaveBeenCalledWith('/repo/about');
68
- navigate('/about', { replace: true });
69
- expect(replace).toHaveBeenCalledWith('/repo/about');
70
- void krateRouter.push('/a');
71
- expect(assign).toHaveBeenCalledWith('/repo/a');
72
- navigate('https://e.test/');
73
- expect(assign).toHaveBeenCalledWith('https://e.test/');
74
- });
75
- it('scopes the speculation rules to the base path', () => {
76
- HTMLScriptElement.supports = (t) => t === 'speculationrules';
77
- setBase('/repo');
78
- document.head.innerHTML = '<title>x</title>';
79
- document.body.innerHTML = '<div id="root"></div>';
80
- initRouter();
81
- const rules = JSON.parse(document.querySelector('script[type="speculationrules"]').textContent);
82
- expect(rules.prefetch[0].where.and).toEqual([
83
- { href_matches: '/repo/*' },
84
- { not: { href_matches: '/repo/__krate/*' } },
85
- { not: { href_matches: '/repo/api/*' } },
86
- ]);
87
- });
88
- });