@krate/runtime 0.5.0-rc.2 → 0.5.0-rc.3
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/dist/actions.d.ts +7 -0
- package/dist/actions.js +21 -3
- package/dist/actions.test.js +8 -410
- package/dist/after.d.ts +28 -0
- package/dist/after.js +48 -0
- package/dist/after.test.js +58 -0
- package/dist/assets-static.d.ts +10 -1
- package/dist/assets-static.js +10 -2
- package/dist/base-path.js +4 -3
- package/dist/builtin-tags.d.ts +12 -0
- package/dist/builtin-tags.js +42 -0
- package/dist/builtin-tags.test.js +12 -0
- package/dist/cache-adapter.test.js +4 -203
- package/dist/cache-scope.d.ts +2 -0
- package/dist/cache.test.js +1 -197
- package/dist/cloudflare-workers.d.ts +2 -0
- package/dist/cloudflare-workers.js +27 -0
- package/dist/dev-overlay.d.ts +54 -3
- package/dist/dev-overlay.js +469 -76
- package/dist/dom.js +3 -1
- package/dist/events.test.js +2 -407
- package/dist/handler-html.test.js +1 -202
- package/dist/handler-routing.js +3 -0
- package/dist/handler-segments.d.ts +6 -0
- package/dist/handler-segments.js +16 -2
- package/dist/handler-segments.test.js +8 -200
- package/dist/head-tags.d.ts +9 -0
- package/dist/head-tags.js +85 -1
- package/dist/head-tags.test.js +18 -125
- package/dist/index.d.ts +1 -5
- package/dist/index.js +3 -0
- package/dist/inline-action-token.test.js +31 -0
- package/dist/jsx-svg-types.test.js +58 -0
- package/dist/jsx-types.d.ts +92 -1
- package/dist/krate-core.js +1 -1
- package/dist/krate-dev.js +384 -65
- package/dist/krate-f-actions.js +1 -1
- package/dist/krate-f-navigation.js +1 -1
- package/dist/krate-f-router-lite.js +1 -1
- package/dist/krate-f-router.js +1 -1
- package/dist/krate-features.json +2 -0
- package/dist/krate-hydrate-lite.js +5 -5
- package/dist/krate-hydrate.js +5 -5
- package/dist/krate-runtime.js +5 -5
- package/dist/link-base-path.test.js +28 -0
- package/dist/node-server.test.js +1 -355
- package/dist/platform.d.ts +52 -0
- package/dist/platform.js +57 -0
- package/dist/platform.test.js +44 -0
- package/dist/router-nav.test.js +15 -444
- package/dist/router.js +39 -1
- package/dist/server-handler.d.ts +48 -0
- package/dist/server-handler.js +272 -16
- package/dist/server-handler.test.js +54 -388
- package/dist/server-renderer.test.js +0 -104
- package/dist/server.d.ts +15 -5
- package/dist/server.js +149 -22
- package/dist/server.test.js +52 -60
- package/dist/site-config.d.ts +13 -0
- package/dist/site-config.js +28 -0
- package/dist/site-config.test.js +30 -0
- package/dist/ssr-core-behavior.test.js +3 -515
- package/dist/testing.d.ts +59 -0
- package/dist/testing.js +88 -0
- package/dist/testing.test.js +73 -0
- package/package.json +9 -1
- package/dist/action-context.test.js +0 -72
- package/dist/base-path.test.js +0 -88
- package/dist/class-component.test.js +0 -462
- package/dist/class-helpers.test.js +0 -169
- package/dist/context.test.js +0 -57
- package/dist/derived.test.js +0 -140
- package/dist/dev-overlay.test.js +0 -165
- package/dist/discrete.test.js +0 -100
- package/dist/dom.test.d.ts +0 -1
- package/dist/dom.test.js +0 -39
- package/dist/effect-errors.test.d.ts +0 -1
- package/dist/effect-errors.test.js +0 -199
- package/dist/effects.test.d.ts +0 -1
- package/dist/effects.test.js +0 -485
- package/dist/handler-routing.test.d.ts +0 -1
- package/dist/handler-routing.test.js +0 -99
- package/dist/highlight-bind.test.d.ts +0 -1
- package/dist/highlight-bind.test.js +0 -124
- package/dist/highlight.test.d.ts +0 -1
- package/dist/highlight.test.js +0 -56
- package/dist/lanes.test.d.ts +0 -1
- package/dist/lanes.test.js +0 -59
- package/dist/list.test.d.ts +0 -1
- package/dist/list.test.js +0 -435
- package/dist/metadata.test.d.ts +0 -1
- package/dist/metadata.test.js +0 -167
- package/dist/navigation.test.d.ts +0 -1
- package/dist/navigation.test.js +0 -130
- package/dist/optimistic-lanes.test.d.ts +0 -1
- package/dist/optimistic-lanes.test.js +0 -45
- package/dist/patterns.test.d.ts +0 -1
- package/dist/patterns.test.js +0 -125
- package/dist/portal.test.d.ts +0 -1
- package/dist/portal.test.js +0 -99
- package/dist/react-effects.test.d.ts +0 -1
- package/dist/react-effects.test.js +0 -133
- package/dist/react-suspense.test.d.ts +0 -1
- package/dist/react-suspense.test.js +0 -194
- package/dist/react.test.d.ts +0 -1
- package/dist/react.test.js +0 -60
- package/dist/react19.test.d.ts +0 -1
- package/dist/react19.test.js +0 -176
- package/dist/reactivity-core.test.d.ts +0 -1
- package/dist/reactivity-core.test.js +0 -152
- package/dist/reconcile.test.d.ts +0 -1
- package/dist/reconcile.test.js +0 -110
- package/dist/refs.test.d.ts +0 -1
- package/dist/refs.test.js +0 -257
- package/dist/router-layout.test.d.ts +0 -1
- package/dist/router-layout.test.js +0 -249
- package/dist/router-slots.test.d.ts +0 -1
- package/dist/router-slots.test.js +0 -144
- package/dist/router-speculation.test.d.ts +0 -1
- package/dist/router-speculation.test.js +0 -25
- package/dist/router-styles.test.d.ts +0 -1
- package/dist/router-styles.test.js +0 -98
- package/dist/router.test.d.ts +0 -1
- package/dist/router.test.js +0 -36
- package/dist/server-async.test.d.ts +0 -1
- package/dist/server-async.test.js +0 -216
- package/dist/server-highlight.test.d.ts +0 -1
- package/dist/server-highlight.test.js +0 -32
- package/dist/signal-lanes.test.d.ts +0 -1
- package/dist/signal-lanes.test.js +0 -32
- package/dist/slots.test.d.ts +0 -1
- package/dist/slots.test.js +0 -187
- package/dist/snapshots.test.d.ts +0 -1
- package/dist/snapshots.test.js +0 -208
- package/dist/ssr-core.test.d.ts +0 -1
- package/dist/ssr-core.test.js +0 -324
- package/dist/static-memory.test.d.ts +0 -1
- package/dist/static-memory.test.js +0 -26
- package/dist/storage.test.d.ts +0 -1
- package/dist/storage.test.js +0 -46
- package/dist/suspense-actions.test.d.ts +0 -1
- package/dist/suspense-actions.test.js +0 -72
- package/dist/suspense.test.d.ts +0 -1
- package/dist/suspense.test.js +0 -556
- /package/dist/{action-context.test.d.ts → after.test.d.ts} +0 -0
- /package/dist/{base-path.test.d.ts → builtin-tags.test.d.ts} +0 -0
- /package/dist/{class-component.test.d.ts → inline-action-token.test.d.ts} +0 -0
- /package/dist/{class-helpers.test.d.ts → jsx-svg-types.test.d.ts} +0 -0
- /package/dist/{context.test.d.ts → link-base-path.test.d.ts} +0 -0
- /package/dist/{derived.test.d.ts → platform.test.d.ts} +0 -0
- /package/dist/{dev-overlay.test.d.ts → site-config.test.d.ts} +0 -0
- /package/dist/{discrete.test.d.ts → testing.test.d.ts} +0 -0
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { applyDynamicRouteParams, compareRouteSpecificity, compileMatcher, goRedirect, headerSourceMatches, isHiddenPath, isInternalOutputPath, matchRedirect, matchRoutePattern, rewriteDestination, } from "./handler-routing.js";
|
|
3
|
-
// The vectors below are copied from the Go host's tests (internal/build
|
|
4
|
-
// serve_test.go, serve_security_test.go, routematch tests) so the portable
|
|
5
|
-
// handler decides like `krate start`.
|
|
6
|
-
describe("redirect matching", () => {
|
|
7
|
-
const cases = [
|
|
8
|
-
["/old", "/old", true],
|
|
9
|
-
["/old", "/old/", false],
|
|
10
|
-
["/old/page", "/old", false],
|
|
11
|
-
["/old/page", "/old/*", true],
|
|
12
|
-
["/old", "/old/*", true],
|
|
13
|
-
["/oldpage", "/old/*", false],
|
|
14
|
-
["/old/", "/old/*", true],
|
|
15
|
-
["/old//double", "/old/*", true],
|
|
16
|
-
["/a", "/b", false],
|
|
17
|
-
];
|
|
18
|
-
for (const [path, source, want] of cases) {
|
|
19
|
-
it(`${path} ~ ${source}`, () => expect(matchRedirect(path, source)).toBe(want));
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
describe("rewriteDestination", () => {
|
|
23
|
-
const cases = [
|
|
24
|
-
["/legacy//evil.com", "/legacy/*", "/:splat", "/evil.com"],
|
|
25
|
-
["/legacy/\\evil.com", "/legacy/*", "/:splat", "/%5Cevil.com"],
|
|
26
|
-
["/u/\\\\evil.com", "/u/:name", "/:name", "/%5C%5Cevil.com"],
|
|
27
|
-
["/legacy/https://evil.com", "/legacy/*", "/:splat", "/https://evil.com"],
|
|
28
|
-
["/legacy/a\nb", "/legacy/*", "/x/:splat", "/x/a%0Ab"],
|
|
29
|
-
["/old/\\evil.com", "/old/*", "/new", "/new/%5Cevil.com"],
|
|
30
|
-
["/go/x", "/go/*", "https://example.com/:splat", "https://example.com/x"],
|
|
31
|
-
["/go/x", "/go/*", "//cdn.example.com/:splat", "//cdn.example.com/x"],
|
|
32
|
-
["/legacy/a b", "/legacy/*", "/new/:splat", "/new/a%20b"],
|
|
33
|
-
["/docs/a/b", "/docs/:path*", "/documentation/:path*", "/documentation/a/b"],
|
|
34
|
-
["/docs", "/docs/:path*", "/documentation/:path*", "/documentation/"],
|
|
35
|
-
["/docs/a", "/docs/:slug?", "/documentation/:slug?", "/documentation/a"],
|
|
36
|
-
["/p/7", "/p/:id", "/item/:id?ref=1", "/item/7?ref=1"],
|
|
37
|
-
["/u/bob", "/u/:name", "/:name", "/bob"],
|
|
38
|
-
["/old", "/old", "/new", "/new"],
|
|
39
|
-
];
|
|
40
|
-
for (const [path, source, dest, want] of cases) {
|
|
41
|
-
it(`${path} ${source} -> ${dest}`, () => expect(rewriteDestination(path, source, dest)).toBe(want));
|
|
42
|
-
}
|
|
43
|
-
it("rejects non-matching optional/plus forms", () => {
|
|
44
|
-
expect(matchRedirect("/docs", "/docs/:path+")).toBe(false);
|
|
45
|
-
expect(matchRedirect("/docs/a/b", "/docs/:slug?")).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("route patterns", () => {
|
|
49
|
-
it("matches params and catch-alls", () => {
|
|
50
|
-
expect(matchRoutePattern("/blog/x", "blog/[slug]")).toEqual({ slug: "x" });
|
|
51
|
-
expect(matchRoutePattern("/docs/a/b", "docs/[...rest]")).toEqual({ rest: "a/b" });
|
|
52
|
-
expect(matchRoutePattern("/docs", "docs/[...rest]")).toBeNull();
|
|
53
|
-
expect(matchRoutePattern("/shop", "shop/[[...filter]]")).toEqual({ filter: "" });
|
|
54
|
-
expect(matchRoutePattern("/blog", "blog/[slug]")).toBeNull();
|
|
55
|
-
});
|
|
56
|
-
it("orders by specificity: static > param > catch-all > optional catch-all", () => {
|
|
57
|
-
const routes = ["/a/[[...x]]", "/a/[...x]", "/a/[x]", "/a/b"];
|
|
58
|
-
expect([...routes].sort(compareRouteSpecificity)).toEqual(["/a/b", "/a/[x]", "/a/[...x]", "/a/[[...x]]"]);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe("paths and headers", () => {
|
|
62
|
-
it("hides internal and dot paths", () => {
|
|
63
|
-
for (const p of ["/api-node/hello.js", "/server-manifest.json", "/%61pi-node/x.js", "/.krate/x", "/a/../.krate/x"]) {
|
|
64
|
-
expect(isInternalOutputPath(p)).toBe(true);
|
|
65
|
-
}
|
|
66
|
-
for (const p of ["/manifest.json", "/api/hello", "/api-nodes/x"])
|
|
67
|
-
expect(isInternalOutputPath(p)).toBe(false);
|
|
68
|
-
expect(isHiddenPath("/.env")).toBe(true);
|
|
69
|
-
expect(isHiddenPath("/.well-known/acme")).toBe(false);
|
|
70
|
-
expect(isHiddenPath("/a/%2eenv")).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
it("matches header sources", () => {
|
|
73
|
-
expect(headerSourceMatches("/about", "/about")).toBe(true);
|
|
74
|
-
expect(headerSourceMatches("/assets/*", "/assets/a/b.js")).toBe(true);
|
|
75
|
-
expect(headerSourceMatches("/a/*/c", "/a/b/c")).toBe(true);
|
|
76
|
-
expect(headerSourceMatches("/a/*/c", "/a/b/d/c")).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
it("compiles the middleware matcher like the Go runtimes", () => {
|
|
79
|
-
expect(compileMatcher("/api/:path*").test("/api/x/y")).toBe(true);
|
|
80
|
-
expect(compileMatcher("/api/:path*").test("/other")).toBe(false);
|
|
81
|
-
expect(compileMatcher("/admin").test("/admin/")).toBe(true);
|
|
82
|
-
expect(() => compileMatcher("nope")).toThrow(/start with/);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe("templates and redirects", () => {
|
|
86
|
-
it("substitutes sentinels and injects params", () => {
|
|
87
|
-
const html = applyDynamicRouteParams("<head></head><p>__KRATE_PARAM_slug__</p>", { slug: "a<b" });
|
|
88
|
-
expect(html).toContain("<p>a<b</p>");
|
|
89
|
-
expect(html).toContain('<script>window.__KRATE_PARAMS__={"slug":"a\\u003cb"}</script></head>');
|
|
90
|
-
});
|
|
91
|
-
it("builds http.Redirect responses", async () => {
|
|
92
|
-
const r = goRedirect("/about", "/old", "GET", 301);
|
|
93
|
-
expect(r.status).toBe(301);
|
|
94
|
-
expect(r.headers.get("location")).toBe("/about");
|
|
95
|
-
expect(await r.text()).toBe('<a href="/about">Moved Permanently</a>.\n\n');
|
|
96
|
-
expect(await goRedirect("rel", "/a/b", "GET", 302).headers.get("location")).toBe("/a/rel");
|
|
97
|
-
expect(goRedirect("/x", "/y", "HEAD", 302).headers.get("content-type")).toContain("text/html");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { krateHighlight, krateHighlightInit } from "./highlight-bind";
|
|
3
|
-
// A fake language chunk: wraps each line in a span so output is easy to read.
|
|
4
|
-
function chunk(calls) {
|
|
5
|
-
return {
|
|
6
|
-
trimSpace: (s) => s.trim(),
|
|
7
|
-
highlight: (code, lang) => {
|
|
8
|
-
calls.push(code);
|
|
9
|
-
if (code.length > 100)
|
|
10
|
-
return null;
|
|
11
|
-
return code
|
|
12
|
-
.split("\n")
|
|
13
|
-
.map((l) => `<span class="line"><span class="cl"><span class="k">${l}</span></span></span>`)
|
|
14
|
-
.join("");
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function mount(initial, lang = "ts") {
|
|
19
|
-
document.body.innerHTML = `<pre class="chroma"><code data-krate-hl="${lang}" class="language-${lang}"><!--k:b-->${initial}<!--/k:b--></code></pre>`;
|
|
20
|
-
const code = document.querySelector("code");
|
|
21
|
-
const start = code.firstChild;
|
|
22
|
-
// What kbindText does: update the text node after the start marker, or add one.
|
|
23
|
-
const set = (s) => {
|
|
24
|
-
if (start.nextSibling && start.nextSibling.nodeType === 3)
|
|
25
|
-
start.nextSibling.textContent = s;
|
|
26
|
-
else
|
|
27
|
-
start.parentNode.insertBefore(document.createTextNode(s), start.nextSibling);
|
|
28
|
-
};
|
|
29
|
-
return { code, start, set };
|
|
30
|
-
}
|
|
31
|
-
const settle = async (ms) => {
|
|
32
|
-
await vi.advanceTimersByTimeAsync(ms);
|
|
33
|
-
await Promise.resolve();
|
|
34
|
-
};
|
|
35
|
-
describe("krateHighlightInit", () => {
|
|
36
|
-
const calls = [];
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
calls.length = 0;
|
|
39
|
-
vi.useFakeTimers();
|
|
40
|
-
window.__KRATE_HL = { ts: "/chunks/hl-ts.js" };
|
|
41
|
-
window.__KRATE_HL_LOAD = async () => chunk(calls);
|
|
42
|
-
});
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
vi.useRealTimers();
|
|
45
|
-
delete window.__KRATE_HL;
|
|
46
|
-
delete window.__KRATE_HL_LOAD;
|
|
47
|
-
document.body.innerHTML = "";
|
|
48
|
-
});
|
|
49
|
-
it("shows the plain text, then swaps in highlighted markup", async () => {
|
|
50
|
-
const { code } = mount("let a = 1");
|
|
51
|
-
krateHighlightInit();
|
|
52
|
-
expect(code.querySelector(".line")).toBeNull();
|
|
53
|
-
await settle(1);
|
|
54
|
-
expect(code.innerHTML).toContain('<span class="k">let a = 1</span>');
|
|
55
|
-
expect(calls).toEqual(["let a = 1"]);
|
|
56
|
-
expect(code.textContent).toBe("let a = 1");
|
|
57
|
-
});
|
|
58
|
-
it("debounces fast updates and keeps the markers", async () => {
|
|
59
|
-
const { code, set } = mount("a");
|
|
60
|
-
krateHighlightInit();
|
|
61
|
-
await settle(1);
|
|
62
|
-
for (const v of ["b", "bc", "bcd"]) {
|
|
63
|
-
set(v);
|
|
64
|
-
await Promise.resolve();
|
|
65
|
-
await settle(30);
|
|
66
|
-
}
|
|
67
|
-
expect(code.querySelector(".line")).toBeNull();
|
|
68
|
-
expect(code.textContent).toBe("bcd");
|
|
69
|
-
await settle(200);
|
|
70
|
-
expect(calls).toEqual(["a", "bcd"]);
|
|
71
|
-
expect(code.textContent).toBe("bcd");
|
|
72
|
-
expect(code.firstChild.nodeType).toBe(8);
|
|
73
|
-
expect(code.lastChild.nodeType).toBe(8);
|
|
74
|
-
});
|
|
75
|
-
it("drops the previous highlighted markup when the slot writes new text", async () => {
|
|
76
|
-
const { code, set } = mount("one\ntwo");
|
|
77
|
-
krateHighlightInit();
|
|
78
|
-
await settle(1);
|
|
79
|
-
expect(code.querySelectorAll(".line")).toHaveLength(2);
|
|
80
|
-
set("three");
|
|
81
|
-
await settle(0);
|
|
82
|
-
expect(code.textContent).toBe("three");
|
|
83
|
-
await settle(200);
|
|
84
|
-
expect(code.querySelectorAll(".line")).toHaveLength(1);
|
|
85
|
-
expect(code.textContent).toBe("three");
|
|
86
|
-
});
|
|
87
|
-
it("does not highlight again when the code has not changed", async () => {
|
|
88
|
-
document.body.innerHTML =
|
|
89
|
-
'<pre class="chroma"><code data-krate-hl="ts"><!--k:b--><span class="line"><span class="cl">x</span></span><!--/k:b--></code></pre>';
|
|
90
|
-
const code = document.querySelector("code");
|
|
91
|
-
krateHighlightInit();
|
|
92
|
-
await settle(500);
|
|
93
|
-
expect(calls).toEqual([]);
|
|
94
|
-
// a second init is a no-op too
|
|
95
|
-
krateHighlightInit();
|
|
96
|
-
await settle(500);
|
|
97
|
-
expect(calls).toEqual([]);
|
|
98
|
-
expect(code.innerHTML).toContain("line");
|
|
99
|
-
});
|
|
100
|
-
it("leaves plain text when the text is too large or the language is unavailable", async () => {
|
|
101
|
-
const big = mount("x".repeat(200));
|
|
102
|
-
krateHighlightInit();
|
|
103
|
-
await settle(1);
|
|
104
|
-
expect(big.code.querySelector(".line")).toBeNull();
|
|
105
|
-
expect(big.code.textContent).toBe("x".repeat(200));
|
|
106
|
-
const none = mount("let a", "zz");
|
|
107
|
-
krateHighlightInit();
|
|
108
|
-
await settle(1);
|
|
109
|
-
expect(none.code.querySelector(".line")).toBeNull();
|
|
110
|
-
});
|
|
111
|
-
it("binds code that is added to the page later", async () => {
|
|
112
|
-
document.body.innerHTML = "<main></main>";
|
|
113
|
-
krateHighlightInit();
|
|
114
|
-
const main = document.querySelector("main");
|
|
115
|
-
main.innerHTML = '<pre class="chroma"><code data-krate-hl="ts"><!--k:z-->late<!--/k:z--></code></pre>';
|
|
116
|
-
await settle(5);
|
|
117
|
-
expect(main.querySelector(".line")).not.toBeNull();
|
|
118
|
-
expect(calls).toEqual(["late"]);
|
|
119
|
-
});
|
|
120
|
-
it("highlights on demand through krateHighlight", async () => {
|
|
121
|
-
expect(await krateHighlight(" a\n", "ts")).toContain('<span class="k">a</span>');
|
|
122
|
-
expect(await krateHighlight("a", "unknown")).toBeNull();
|
|
123
|
-
});
|
|
124
|
-
});
|
package/dist/highlight.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/highlight.test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { beforeAll, describe, expect, it } from "vitest";
|
|
2
|
-
import { HIGHLIGHT_MAX_LENGTH, HIGHLIGHT_MAX_LINE, escapeHTML, hasLanguage, highlight, parseLineRanges, plainLines, registerLanguage, trimSpace, } from "./highlight";
|
|
3
|
-
// A tiny lexer in the exported table format: words are names, digits numbers,
|
|
4
|
-
// and an unmatched character is an error token.
|
|
5
|
-
const table = {
|
|
6
|
-
n: "Toy",
|
|
7
|
-
t: ["nx", "mi", "", "c"],
|
|
8
|
-
s: [
|
|
9
|
-
[
|
|
10
|
-
["[a-z]+", 0],
|
|
11
|
-
["[0-9]+", 1],
|
|
12
|
-
["#[^\\n]*", 3],
|
|
13
|
-
["[ \\n]+", 2],
|
|
14
|
-
],
|
|
15
|
-
],
|
|
16
|
-
e: 1,
|
|
17
|
-
};
|
|
18
|
-
beforeAll(() => registerLanguage(table, ["toy", "t"]));
|
|
19
|
-
describe("highlight", () => {
|
|
20
|
-
it("writes chroma's markup: one line wrapper per line, one span per token", () => {
|
|
21
|
-
expect(highlight("ab 12\nc", "toy")).toBe('<span class="line"><span class="cl"><span class="nx">ab</span> <span class="mi">12</span>\n</span></span>' +
|
|
22
|
-
'<span class="line"><span class="cl"><span class="nx">c</span></span></span>');
|
|
23
|
-
});
|
|
24
|
-
it("marks lines and ignores malformed ranges", () => {
|
|
25
|
-
const html = highlight("a\nb\nc", "toy", "2,x,5-3");
|
|
26
|
-
expect(html.match(/class="line hl"/g)).toHaveLength(1);
|
|
27
|
-
expect(html).toContain('<span class="line hl"><span class="cl"><span class="nx">b</span>');
|
|
28
|
-
expect(parseLineRanges("1,3-5, 7 ,0,abc,4-2")).toEqual([[1, 1], [3, 5], [7, 7]]);
|
|
29
|
-
});
|
|
30
|
-
it("escapes text the way the compiler does", () => {
|
|
31
|
-
expect(escapeHTML(`<a href="x">'&'</a>`)).toBe("<a href="x">'&'</a>");
|
|
32
|
-
expect(highlight("#<b>", "toy")).toContain('<span class="c">#<b></span>');
|
|
33
|
-
});
|
|
34
|
-
it("reports an unknown character as an error token and resumes", () => {
|
|
35
|
-
expect(highlight("a!b", "toy")).toContain('<span class="err">!</span>');
|
|
36
|
-
});
|
|
37
|
-
it("returns null when it cannot highlight exactly", () => {
|
|
38
|
-
expect(highlight("a", "nope")).toBeNull();
|
|
39
|
-
expect(highlight("a".repeat(HIGHLIGHT_MAX_LENGTH + 1), "toy")).toBeNull();
|
|
40
|
-
expect(highlight("a".repeat(HIGHLIGHT_MAX_LINE + 1), "toy")).toBeNull();
|
|
41
|
-
expect(highlight("a\n".repeat(HIGHLIGHT_MAX_LENGTH / 2), "toy", undefined, { maxLength: 10 })).toBeNull();
|
|
42
|
-
expect(hasLanguage(" TOY ")).toBe(true);
|
|
43
|
-
expect(hasLanguage("nope")).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
it("gives up when it runs out of time", () => {
|
|
46
|
-
const text = "a 1 b 2\n".repeat(3000);
|
|
47
|
-
expect(highlight(text, "toy", undefined, { budgetMs: -1 })).toBeNull();
|
|
48
|
-
expect(highlight(text, "toy", undefined, { budgetMs: 10000 })).not.toBeNull();
|
|
49
|
-
});
|
|
50
|
-
it("falls back to plain lines for languages chroma does not know", () => {
|
|
51
|
-
expect(plainLines("a<b\r\nc")).toBe('<span class="line"><span class="cl">a<b\n</span></span><span class="line"><span class="cl">c</span></span>');
|
|
52
|
-
});
|
|
53
|
-
it("trims whitespace like Go's strings.TrimSpace", () => {
|
|
54
|
-
expect(trimSpace("\u00a0 \n x \u2028")).toBe("x");
|
|
55
|
-
});
|
|
56
|
-
});
|
package/dist/lanes.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/lanes.test.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { createSignal, createEffect, disposeAll, krateHookState } from './signal';
|
|
3
|
-
import { createEffectDeps } from './effects';
|
|
4
|
-
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
5
|
-
async function settle() {
|
|
6
|
-
for (let i = 0; i < 4; i++)
|
|
7
|
-
await tick();
|
|
8
|
-
}
|
|
9
|
-
describe('mixed update lanes', () => {
|
|
10
|
-
beforeEach(() => disposeAll());
|
|
11
|
-
it('keeps a promise-driven React state write when a plain signal is written in a later microtask', async () => {
|
|
12
|
-
const [user, setUser] = createSignal('nobody', krateHookState);
|
|
13
|
-
const [flag, setFlag] = createSignal(false);
|
|
14
|
-
const text = [];
|
|
15
|
-
const effects = [];
|
|
16
|
-
createEffect(() => void text.push(user() + '/' + flag()));
|
|
17
|
-
createEffectDeps(() => void effects.push('user ' + user()), () => [user()]);
|
|
18
|
-
await settle();
|
|
19
|
-
text.length = 0;
|
|
20
|
-
effects.length = 0;
|
|
21
|
-
await Promise.resolve().then(() => {
|
|
22
|
-
setUser('grace');
|
|
23
|
-
queueMicrotask(() => setFlag(true));
|
|
24
|
-
});
|
|
25
|
-
await settle();
|
|
26
|
-
expect(user()).toBe('grace');
|
|
27
|
-
expect(text[text.length - 1]).toBe('grace/true');
|
|
28
|
-
expect(effects).toEqual(['user grace']);
|
|
29
|
-
});
|
|
30
|
-
it('keeps the React state write when the plain write comes first', async () => {
|
|
31
|
-
const [user, setUser] = createSignal('nobody', krateHookState);
|
|
32
|
-
const [flag, setFlag] = createSignal(false);
|
|
33
|
-
const seen = [];
|
|
34
|
-
createEffect(() => void seen.push(user() + '/' + flag()));
|
|
35
|
-
await settle();
|
|
36
|
-
await Promise.resolve().then(() => {
|
|
37
|
-
setFlag(true);
|
|
38
|
-
setUser('grace');
|
|
39
|
-
});
|
|
40
|
-
await settle();
|
|
41
|
-
expect(seen[seen.length - 1]).toBe('grace/true');
|
|
42
|
-
expect(user()).toBe('grace');
|
|
43
|
-
});
|
|
44
|
-
it('commits a React write made while a microtask flush is already queued', async () => {
|
|
45
|
-
const [user, setUser] = createSignal('nobody', krateHookState);
|
|
46
|
-
const [flag, setFlag] = createSignal(0);
|
|
47
|
-
const seen = [];
|
|
48
|
-
createEffect(() => void seen.push(user() + '/' + flag()));
|
|
49
|
-
createEffectDeps(() => void seen.push('effect ' + user()), () => [user()]);
|
|
50
|
-
await settle();
|
|
51
|
-
seen.length = 0;
|
|
52
|
-
setFlag(1);
|
|
53
|
-
await Promise.resolve();
|
|
54
|
-
setUser('grace');
|
|
55
|
-
await settle();
|
|
56
|
-
expect(seen).toContain('effect grace');
|
|
57
|
-
expect(user()).toBe('grace');
|
|
58
|
-
});
|
|
59
|
-
});
|
package/dist/list.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|