@alloy-js/core 0.24.0-dev.6 → 0.24.0-dev.7
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/dev/src/components/AccessExpression.test.js +30 -38
- package/dist/dev/src/components/AccessExpression.test.js.map +1 -1
- package/dist/dev/src/content-slot.test.js +16 -18
- package/dist/dev/src/content-slot.test.js.map +1 -1
- package/dist/dev/src/symbols/symbol-slot.test.js +4 -4
- package/dist/dev/src/symbols/symbol-slot.test.js.map +1 -1
- package/dist/dev/test/children.test.js +9 -11
- package/dist/dev/test/children.test.js.map +1 -1
- package/dist/dev/test/components/append-file.test.js +26 -27
- package/dist/dev/test/components/append-file.test.js.map +1 -1
- package/dist/dev/test/components/block.test.js +9 -11
- package/dist/dev/test/components/block.test.js.map +1 -1
- package/dist/dev/test/components/copy-file.test.js +6 -7
- package/dist/dev/test/components/copy-file.test.js.map +1 -1
- package/dist/dev/test/components/declaration.test.js +2 -2
- package/dist/dev/test/components/declaration.test.js.map +1 -1
- package/dist/dev/test/components/list.test.js +41 -43
- package/dist/dev/test/components/list.test.js.map +1 -1
- package/dist/dev/test/components/prose.test.js +4 -5
- package/dist/dev/test/components/prose.test.js.map +1 -1
- package/dist/dev/test/components/reference-or-content.test.js +32 -33
- package/dist/dev/test/components/reference-or-content.test.js.map +1 -1
- package/dist/dev/test/components/source-file.test.js +8 -7
- package/dist/dev/test/components/source-file.test.js.map +1 -1
- package/dist/dev/test/components/template-file.test.js +16 -17
- package/dist/dev/test/components/template-file.test.js.map +1 -1
- package/dist/dev/test/components/update-file.test.js +10 -11
- package/dist/dev/test/components/update-file.test.js.map +1 -1
- package/dist/dev/test/components/wrap.test.js +6 -8
- package/dist/dev/test/components/wrap.test.js.map +1 -1
- package/dist/dev/test/control-flow/for.test.js +58 -42
- package/dist/dev/test/control-flow/for.test.js.map +1 -1
- package/dist/dev/test/control-flow/match.test.js +15 -17
- package/dist/dev/test/control-flow/match.test.js.map +1 -1
- package/dist/dev/test/control-flow/show.test.js +5 -8
- package/dist/dev/test/control-flow/show.test.js.map +1 -1
- package/dist/dev/test/lazy-isempty.test.js +24 -26
- package/dist/dev/test/lazy-isempty.test.js.map +1 -1
- package/dist/dev/test/name-policy.test.js +2 -3
- package/dist/dev/test/name-policy.test.js.map +1 -1
- package/dist/dev/test/reactivity/circular-reactives.test.js +9 -9
- package/dist/dev/test/reactivity/circular-reactives.test.js.map +1 -1
- package/dist/dev/test/reactivity/cleanup.test.js +5 -6
- package/dist/dev/test/reactivity/cleanup.test.js.map +1 -1
- package/dist/dev/test/reactivity/ref-rendering.test.js +15 -15
- package/dist/dev/test/reactivity/ref-rendering.test.js.map +1 -1
- package/dist/dev/test/reactivity/test.test.js +18 -18
- package/dist/dev/test/reactivity/test.test.js.map +1 -1
- package/dist/dev/test/rendering/basic.test.js +18 -19
- package/dist/dev/test/rendering/basic.test.js.map +1 -1
- package/dist/dev/test/rendering/code.test.js +2 -3
- package/dist/dev/test/rendering/code.test.js.map +1 -1
- package/dist/dev/test/rendering/formatting.test.js +115 -121
- package/dist/dev/test/rendering/formatting.test.js.map +1 -1
- package/dist/dev/test/rendering/indent.test.js +23 -24
- package/dist/dev/test/rendering/indent.test.js.map +1 -1
- package/dist/dev/test/rendering/memoization.test.js +4 -5
- package/dist/dev/test/rendering/memoization.test.js.map +1 -1
- package/dist/dev/test/rendering/print-render-stack.test.js +20 -21
- package/dist/dev/test/rendering/print-render-stack.test.js.map +1 -1
- package/dist/dev/test/rendering/refkeys.test.js +1 -2
- package/dist/dev/test/rendering/refkeys.test.js.map +1 -1
- package/dist/dev/test/stc.test.js +0 -1
- package/dist/dev/test/stc.test.js.map +1 -1
- package/dist/dev/test/utils.test.js +34 -33
- package/dist/dev/test/utils.test.js.map +1 -1
- package/dist/dev/test/vitest.setup.js +2 -0
- package/dist/dev/test/vitest.setup.js.map +1 -0
- package/dist/dev/testing/extend-expect.js +23 -1
- package/dist/dev/testing/extend-expect.js.map +1 -1
- package/dist/src/components/AccessExpression.test.d.ts +1 -1
- package/dist/src/components/AccessExpression.test.d.ts.map +1 -1
- package/dist/src/components/AccessExpression.test.js +5 -13
- package/dist/src/components/AccessExpression.test.js.map +1 -1
- package/dist/src/content-slot.test.d.ts +1 -1
- package/dist/src/content-slot.test.d.ts.map +1 -1
- package/dist/src/content-slot.test.js +8 -10
- package/dist/src/content-slot.test.js.map +1 -1
- package/dist/src/symbols/symbol-slot.test.js +4 -4
- package/dist/src/symbols/symbol-slot.test.js.map +1 -1
- package/dist/test/children.test.js +5 -7
- package/dist/test/children.test.js.map +1 -1
- package/dist/test/components/append-file.test.d.ts +1 -1
- package/dist/test/components/append-file.test.d.ts.map +1 -1
- package/dist/test/components/append-file.test.js +0 -1
- package/dist/test/components/append-file.test.js.map +1 -1
- package/dist/test/components/block.test.d.ts +1 -1
- package/dist/test/components/block.test.d.ts.map +1 -1
- package/dist/test/components/block.test.js +4 -6
- package/dist/test/components/block.test.js.map +1 -1
- package/dist/test/components/copy-file.test.d.ts +1 -1
- package/dist/test/components/copy-file.test.d.ts.map +1 -1
- package/dist/test/components/copy-file.test.js +0 -1
- package/dist/test/components/copy-file.test.js.map +1 -1
- package/dist/test/components/declaration.test.js +2 -2
- package/dist/test/components/declaration.test.js.map +1 -1
- package/dist/test/components/list.test.d.ts +1 -1
- package/dist/test/components/list.test.d.ts.map +1 -1
- package/dist/test/components/list.test.js +20 -22
- package/dist/test/components/list.test.js.map +1 -1
- package/dist/test/components/prose.test.d.ts +1 -1
- package/dist/test/components/prose.test.d.ts.map +1 -1
- package/dist/test/components/prose.test.js +0 -1
- package/dist/test/components/prose.test.js.map +1 -1
- package/dist/test/components/reference-or-content.test.js +8 -9
- package/dist/test/components/reference-or-content.test.js.map +1 -1
- package/dist/test/components/source-file.test.d.ts +1 -1
- package/dist/test/components/source-file.test.d.ts.map +1 -1
- package/dist/test/components/source-file.test.js +5 -4
- package/dist/test/components/source-file.test.js.map +1 -1
- package/dist/test/components/template-file.test.d.ts +1 -1
- package/dist/test/components/template-file.test.d.ts.map +1 -1
- package/dist/test/components/template-file.test.js +0 -1
- package/dist/test/components/template-file.test.js.map +1 -1
- package/dist/test/components/update-file.test.d.ts +1 -1
- package/dist/test/components/update-file.test.d.ts.map +1 -1
- package/dist/test/components/update-file.test.js +0 -1
- package/dist/test/components/update-file.test.js.map +1 -1
- package/dist/test/components/wrap.test.d.ts +1 -1
- package/dist/test/components/wrap.test.d.ts.map +1 -1
- package/dist/test/components/wrap.test.js +3 -5
- package/dist/test/components/wrap.test.js.map +1 -1
- package/dist/test/control-flow/for.test.d.ts +1 -1
- package/dist/test/control-flow/for.test.d.ts.map +1 -1
- package/dist/test/control-flow/for.test.js +40 -24
- package/dist/test/control-flow/for.test.js.map +1 -1
- package/dist/test/control-flow/match.test.d.ts +1 -1
- package/dist/test/control-flow/match.test.d.ts.map +1 -1
- package/dist/test/control-flow/match.test.js +4 -6
- package/dist/test/control-flow/match.test.js.map +1 -1
- package/dist/test/control-flow/show.test.d.ts +1 -1
- package/dist/test/control-flow/show.test.d.ts.map +1 -1
- package/dist/test/control-flow/show.test.js +3 -6
- package/dist/test/control-flow/show.test.js.map +1 -1
- package/dist/test/lazy-isempty.test.d.ts +1 -1
- package/dist/test/lazy-isempty.test.d.ts.map +1 -1
- package/dist/test/lazy-isempty.test.js +11 -13
- package/dist/test/lazy-isempty.test.js.map +1 -1
- package/dist/test/name-policy.test.d.ts +1 -1
- package/dist/test/name-policy.test.d.ts.map +1 -1
- package/dist/test/name-policy.test.js +0 -1
- package/dist/test/name-policy.test.js.map +1 -1
- package/dist/test/reactivity/circular-reactives.test.js +6 -6
- package/dist/test/reactivity/circular-reactives.test.js.map +1 -1
- package/dist/test/reactivity/cleanup.test.js +2 -3
- package/dist/test/reactivity/cleanup.test.js.map +1 -1
- package/dist/test/reactivity/ref-rendering.test.js +15 -15
- package/dist/test/reactivity/ref-rendering.test.js.map +1 -1
- package/dist/test/reactivity/test.test.js +15 -15
- package/dist/test/reactivity/test.test.js.map +1 -1
- package/dist/test/rendering/basic.test.d.ts +1 -1
- package/dist/test/rendering/basic.test.d.ts.map +1 -1
- package/dist/test/rendering/basic.test.js +0 -1
- package/dist/test/rendering/basic.test.js.map +1 -1
- package/dist/test/rendering/code.test.d.ts +1 -1
- package/dist/test/rendering/code.test.d.ts.map +1 -1
- package/dist/test/rendering/code.test.js +0 -1
- package/dist/test/rendering/code.test.js.map +1 -1
- package/dist/test/rendering/formatting.test.d.ts +1 -1
- package/dist/test/rendering/formatting.test.d.ts.map +1 -1
- package/dist/test/rendering/formatting.test.js +17 -23
- package/dist/test/rendering/formatting.test.js.map +1 -1
- package/dist/test/rendering/indent.test.d.ts +1 -1
- package/dist/test/rendering/indent.test.d.ts.map +1 -1
- package/dist/test/rendering/indent.test.js +0 -1
- package/dist/test/rendering/indent.test.js.map +1 -1
- package/dist/test/rendering/memoization.test.js +2 -3
- package/dist/test/rendering/memoization.test.js.map +1 -1
- package/dist/test/rendering/print-render-stack.test.d.ts +1 -1
- package/dist/test/rendering/print-render-stack.test.d.ts.map +1 -1
- package/dist/test/rendering/print-render-stack.test.js +0 -1
- package/dist/test/rendering/print-render-stack.test.js.map +1 -1
- package/dist/test/rendering/refkeys.test.d.ts +1 -1
- package/dist/test/rendering/refkeys.test.d.ts.map +1 -1
- package/dist/test/rendering/refkeys.test.js +0 -1
- package/dist/test/rendering/refkeys.test.js.map +1 -1
- package/dist/test/stc.test.d.ts +1 -1
- package/dist/test/stc.test.d.ts.map +1 -1
- package/dist/test/stc.test.js +0 -1
- package/dist/test/stc.test.js.map +1 -1
- package/dist/test/utils.test.d.ts +1 -1
- package/dist/test/utils.test.d.ts.map +1 -1
- package/dist/test/utils.test.js +12 -11
- package/dist/test/utils.test.js.map +1 -1
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +2 -0
- package/dist/test/vitest.setup.js.map +1 -0
- package/dist/testing/extend-expect.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +23 -1
- package/dist/testing/extend-expect.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/AccessExpression.test.tsx +5 -13
- package/src/content-slot.test.tsx +8 -10
- package/src/symbols/symbol-slot.test.tsx +4 -4
- package/test/children.test.tsx +4 -7
- package/test/components/append-file.test.tsx +0 -1
- package/test/components/block.test.tsx +4 -6
- package/test/components/copy-file.test.tsx +0 -1
- package/test/components/declaration.test.tsx +2 -2
- package/test/components/list.test.tsx +20 -29
- package/test/components/prose.test.tsx +0 -1
- package/test/components/reference-or-content.test.tsx +8 -9
- package/test/components/source-file.test.tsx +4 -4
- package/test/components/template-file.test.tsx +0 -1
- package/test/components/update-file.test.tsx +0 -1
- package/test/components/wrap.test.tsx +3 -5
- package/test/control-flow/for.test.tsx +39 -31
- package/test/control-flow/match.test.tsx +4 -6
- package/test/control-flow/show.test.tsx +3 -6
- package/test/lazy-isempty.test.tsx +12 -14
- package/test/name-policy.test.tsx +0 -1
- package/test/reactivity/circular-reactives.test.tsx +6 -6
- package/test/reactivity/cleanup.test.tsx +2 -3
- package/test/reactivity/ref-rendering.test.tsx +15 -15
- package/test/reactivity/test.test.tsx +14 -14
- package/test/rendering/basic.test.tsx +0 -1
- package/test/rendering/code.test.tsx +0 -1
- package/test/rendering/formatting.test.tsx +21 -29
- package/test/rendering/indent.test.tsx +0 -1
- package/test/rendering/memoization.test.tsx +2 -3
- package/test/rendering/print-render-stack.test.tsx +0 -1
- package/test/rendering/refkeys.test.tsx +0 -1
- package/test/stc.test.tsx +0 -1
- package/test/utils.test.tsx +10 -9
- package/test/vitest.setup.ts +1 -0
- package/testing/extend-expect.ts +24 -1
- package/vitest.config.ts +3 -0
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import "@alloy-js/core/testing";
|
|
2
1
|
import { ref } from "@vue/reactivity";
|
|
3
2
|
import { expect, it } from "vitest";
|
|
4
3
|
import { Match, Switch } from "../../src/components/Switch.jsx";
|
|
5
|
-
import { printTree, renderTree } from "../../src/test-render.js";
|
|
6
4
|
|
|
7
5
|
it("selects the true branch", () => {
|
|
8
6
|
const template = (
|
|
@@ -40,10 +38,10 @@ it("works with reactivity", () => {
|
|
|
40
38
|
<Match else>odd</Match>
|
|
41
39
|
</Switch>
|
|
42
40
|
);
|
|
43
|
-
const tree =
|
|
44
|
-
expect(
|
|
41
|
+
const tree = template;
|
|
42
|
+
expect(tree).toRenderTo("even");
|
|
45
43
|
count.value++;
|
|
46
|
-
expect(
|
|
44
|
+
expect(tree).toRenderTo("odd");
|
|
47
45
|
count.value++;
|
|
48
|
-
expect(
|
|
46
|
+
expect(tree).toRenderTo("even");
|
|
49
47
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import "@alloy-js/core/testing";
|
|
2
1
|
import { ref } from "@vue/reactivity";
|
|
3
2
|
import { expect, it } from "vitest";
|
|
4
3
|
import { Show } from "../../src/components/Show.jsx";
|
|
5
|
-
import { printTree, renderTree } from "../../src/test-render.js";
|
|
6
4
|
|
|
7
5
|
it("selects the true branch", () => {
|
|
8
6
|
const template = <Show when={true}>true</Show>;
|
|
@@ -16,10 +14,9 @@ it("works with reactivity", () => {
|
|
|
16
14
|
even
|
|
17
15
|
</Show>
|
|
18
16
|
);
|
|
19
|
-
|
|
20
|
-
expect(printTree(tree)).toBe(`even`);
|
|
17
|
+
expect(template).toRenderTo("even");
|
|
21
18
|
count.value++;
|
|
22
|
-
expect(
|
|
19
|
+
expect(template).toRenderTo("odd");
|
|
23
20
|
count.value++;
|
|
24
|
-
expect(
|
|
21
|
+
expect(template).toRenderTo("even");
|
|
25
22
|
});
|
|
@@ -3,8 +3,6 @@ import { describe, expect, it } from "vitest";
|
|
|
3
3
|
import { Show } from "../src/components/Show.jsx";
|
|
4
4
|
import { createContentSlot } from "../src/content-slot.jsx";
|
|
5
5
|
import { Context, ensureIsEmpty, getContext } from "../src/reactivity.js";
|
|
6
|
-
import { printTree, renderTree } from "../src/test-render.js";
|
|
7
|
-
import "../testing/extend-expect.js";
|
|
8
6
|
|
|
9
7
|
describe("lazy isEmpty", () => {
|
|
10
8
|
it("context starts without isEmpty ref allocated", () => {
|
|
@@ -15,7 +13,7 @@ describe("lazy isEmpty", () => {
|
|
|
15
13
|
return "content";
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
expect(<Capture />).toRenderTo("content");
|
|
19
17
|
|
|
20
18
|
// The isEmpty ref should NOT be allocated unless someone observes it.
|
|
21
19
|
expect(ctx).not.toBeNull();
|
|
@@ -31,7 +29,7 @@ describe("lazy isEmpty", () => {
|
|
|
31
29
|
return "content";
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
expect(<Capture />).toRenderTo("content");
|
|
35
33
|
|
|
36
34
|
expect(ctx!.isEmpty).toBeUndefined();
|
|
37
35
|
const isEmptyRef = ensureIsEmpty(ctx!);
|
|
@@ -53,12 +51,12 @@ describe("lazy isEmpty", () => {
|
|
|
53
51
|
return "has content";
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
expect(
|
|
57
55
|
<>
|
|
58
56
|
<EmptyCapture />
|
|
59
57
|
<FullCapture />
|
|
60
58
|
</>,
|
|
61
|
-
);
|
|
59
|
+
).toRenderTo("has content");
|
|
62
60
|
|
|
63
61
|
expect(emptyCtx!.childrenWithContent).toBe(0);
|
|
64
62
|
expect(fullCtx!.childrenWithContent).toBe(1);
|
|
@@ -68,39 +66,39 @@ describe("lazy isEmpty", () => {
|
|
|
68
66
|
const ContentSlot = createContentSlot();
|
|
69
67
|
const showContent = ref(false);
|
|
70
68
|
|
|
71
|
-
const tree =
|
|
69
|
+
const tree = (
|
|
72
70
|
<>
|
|
73
71
|
{ContentSlot.isEmpty && "empty"}
|
|
74
72
|
<ContentSlot>
|
|
75
73
|
<Show when={showContent.value}>content</Show>
|
|
76
74
|
</ContentSlot>
|
|
77
|
-
|
|
75
|
+
</>
|
|
78
76
|
);
|
|
79
77
|
|
|
80
|
-
expect(
|
|
78
|
+
expect(tree).toRenderTo("empty");
|
|
81
79
|
|
|
82
80
|
showContent.value = true;
|
|
83
|
-
expect(
|
|
81
|
+
expect(tree).toRenderTo("content");
|
|
84
82
|
});
|
|
85
83
|
|
|
86
84
|
it("propagates empty state up through parent contexts", () => {
|
|
87
85
|
const OuterSlot = createContentSlot();
|
|
88
86
|
const showContent = ref(false);
|
|
89
87
|
|
|
90
|
-
const tree =
|
|
88
|
+
const tree = (
|
|
91
89
|
<>
|
|
92
90
|
{OuterSlot.isEmpty && "outer-empty"}
|
|
93
91
|
<OuterSlot>
|
|
94
92
|
<Show when={showContent.value}>content</Show>
|
|
95
93
|
</OuterSlot>
|
|
96
|
-
|
|
94
|
+
</>
|
|
97
95
|
);
|
|
98
96
|
|
|
99
97
|
// Outer should be empty initially.
|
|
100
|
-
expect(
|
|
98
|
+
expect(tree).toRenderTo("outer-empty");
|
|
101
99
|
|
|
102
100
|
// Show content — outer should become non-empty.
|
|
103
101
|
showContent.value = true;
|
|
104
|
-
expect(
|
|
102
|
+
expect(tree).toRenderTo("content");
|
|
105
103
|
});
|
|
106
104
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { shallowReactive } from "@vue/reactivity";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { For } from "../../src/index.js";
|
|
4
|
-
import { printTree, renderTree } from "../../src/test-render.js";
|
|
5
|
-
import { d } from "../../testing/render.js";
|
|
6
4
|
|
|
7
5
|
it("it should work with circular reactives", () => {
|
|
8
6
|
const items: string[] = shallowReactive([]);
|
|
@@ -23,9 +21,10 @@ it("it should work with circular reactives", () => {
|
|
|
23
21
|
</For>
|
|
24
22
|
</>
|
|
25
23
|
);
|
|
26
|
-
const tree =
|
|
24
|
+
const tree = template;
|
|
25
|
+
expect(tree).toRenderTo("");
|
|
27
26
|
items.push("item start");
|
|
28
|
-
expect(
|
|
27
|
+
expect(tree).toRenderTo(`
|
|
29
28
|
item start
|
|
30
29
|
item 1
|
|
31
30
|
`);
|
|
@@ -43,9 +42,10 @@ it("should work with immediately recursive reactives", () => {
|
|
|
43
42
|
</For>
|
|
44
43
|
</>
|
|
45
44
|
);
|
|
46
|
-
const tree =
|
|
45
|
+
const tree = template;
|
|
46
|
+
expect(tree).toRenderTo("");
|
|
47
47
|
items.add("item start");
|
|
48
|
-
expect(
|
|
48
|
+
expect(tree).toRenderTo(`
|
|
49
49
|
item start
|
|
50
50
|
item 1
|
|
51
51
|
`);
|
|
@@ -3,7 +3,6 @@ import { describe, expect, it } from "vitest";
|
|
|
3
3
|
import { effect, memo, onCleanup } from "../../src/reactivity.js";
|
|
4
4
|
import type { Children } from "../../src/runtime/component.js";
|
|
5
5
|
import { flushJobs } from "../../src/scheduler.js";
|
|
6
|
-
import { renderTree } from "../../src/test-render.js";
|
|
7
6
|
|
|
8
7
|
describe("memo cleanup", () => {
|
|
9
8
|
it("cleans up when memo value is recomputed", () => {
|
|
@@ -60,7 +59,7 @@ describe("element cleanup", () => {
|
|
|
60
59
|
}
|
|
61
60
|
const el = ref<unknown>(<Component />);
|
|
62
61
|
const template = <>{el}</>;
|
|
63
|
-
|
|
62
|
+
expect(template).toRenderTo("hi!");
|
|
64
63
|
el.value = "";
|
|
65
64
|
flushJobs();
|
|
66
65
|
expect(cleanedUp).toBe(true);
|
|
@@ -88,7 +87,7 @@ describe("element cleanup", () => {
|
|
|
88
87
|
</C1>,
|
|
89
88
|
);
|
|
90
89
|
const template = <>{el}</>;
|
|
91
|
-
|
|
90
|
+
expect(template).toRenderTo("");
|
|
92
91
|
el.value = "";
|
|
93
92
|
flushJobs();
|
|
94
93
|
expect(cleanedUpC1).toBe(true);
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { code, memo
|
|
1
|
+
import { code, memo } from "@alloy-js/core";
|
|
2
2
|
import { ref } from "@vue/reactivity";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
4
|
|
|
5
5
|
it("handles refs in the tree", () => {
|
|
6
6
|
const r = ref(42);
|
|
7
|
-
const tree =
|
|
7
|
+
const tree = <>The number is {r}</>;
|
|
8
8
|
|
|
9
|
-
expect(
|
|
9
|
+
expect(tree).toRenderTo("The number is 42");
|
|
10
10
|
r.value = 12;
|
|
11
|
-
expect(
|
|
11
|
+
expect(tree).toRenderTo("The number is 12");
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it("handles refs in the tree with code", () => {
|
|
15
15
|
const r = ref(42);
|
|
16
|
-
const tree =
|
|
16
|
+
const tree = code`
|
|
17
17
|
The number is ${r}
|
|
18
|
-
|
|
18
|
+
`;
|
|
19
19
|
|
|
20
|
-
expect(
|
|
20
|
+
expect(tree).toRenderTo("The number is 42");
|
|
21
21
|
r.value = 12;
|
|
22
|
-
expect(
|
|
22
|
+
expect(tree).toRenderTo("The number is 12");
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it("handles memos in the tree", () => {
|
|
26
26
|
const r = ref(42);
|
|
27
27
|
const m = memo(() => r.value + 10);
|
|
28
|
-
const tree =
|
|
28
|
+
const tree = <>The number is {m}</>;
|
|
29
29
|
|
|
30
|
-
expect(
|
|
30
|
+
expect(tree).toRenderTo("The number is 52");
|
|
31
31
|
r.value = 12;
|
|
32
|
-
expect(
|
|
32
|
+
expect(tree).toRenderTo("The number is 22");
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it("handles memos in the tree with code", () => {
|
|
36
36
|
const r = ref(42);
|
|
37
37
|
const m = memo(() => r.value + 10);
|
|
38
|
-
const tree =
|
|
38
|
+
const tree = code`
|
|
39
39
|
The number is ${m}
|
|
40
|
-
|
|
40
|
+
`;
|
|
41
41
|
|
|
42
|
-
expect(
|
|
42
|
+
expect(tree).toRenderTo("The number is 52");
|
|
43
43
|
r.value = 12;
|
|
44
|
-
expect(
|
|
44
|
+
expect(tree).toRenderTo("The number is 22");
|
|
45
45
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { memo
|
|
1
|
+
import { memo } from "@alloy-js/core";
|
|
2
2
|
import { computed, reactive, ref } from "@vue/reactivity";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
|
+
import { flushJobs } from "../../src/scheduler.js";
|
|
4
5
|
import { mapJoin } from "../../src/utils.js";
|
|
5
|
-
import { d } from "../../testing/render.js";
|
|
6
6
|
|
|
7
7
|
it("splices in new nodes", () => {
|
|
8
8
|
const r = ref(["one"]);
|
|
@@ -14,11 +14,11 @@ it("splices in new nodes", () => {
|
|
|
14
14
|
return <>{mapped.value} done</>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const tree =
|
|
18
|
-
expect(
|
|
17
|
+
const tree = <Foo />;
|
|
18
|
+
expect(tree).toRenderTo("mapped one done");
|
|
19
19
|
r.value = [...r.value, "two"];
|
|
20
20
|
|
|
21
|
-
expect(
|
|
21
|
+
expect(tree).toRenderTo("mapped one mapped two done");
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it("works with a complex case", () => {
|
|
@@ -56,20 +56,20 @@ it("works with a complex case", () => {
|
|
|
56
56
|
`import { ${[...props.types.values()].join(", ")} } from "${props.path}";`;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const tree =
|
|
59
|
+
const tree = <ImportStatements records={importRecords} />;
|
|
60
60
|
// the tree is empty.
|
|
61
61
|
|
|
62
|
-
expect(
|
|
62
|
+
expect(tree).toRenderTo("");
|
|
63
63
|
|
|
64
64
|
addImport("./foo.js", "hi");
|
|
65
|
-
|
|
66
|
-
expect(
|
|
65
|
+
flushJobs();
|
|
66
|
+
expect(tree).toRenderTo('import { hi } from "./foo.js";');
|
|
67
67
|
|
|
68
68
|
addImport("./foo.js", "bye");
|
|
69
|
-
expect(
|
|
69
|
+
expect(tree).toRenderTo('import { hi, bye } from "./foo.js";');
|
|
70
70
|
|
|
71
71
|
addImport("node:assert", "strictEqual");
|
|
72
|
-
expect(
|
|
72
|
+
expect(tree).toRenderTo(`
|
|
73
73
|
import { hi, bye } from "./foo.js";
|
|
74
74
|
import { strictEqual } from "node:assert";
|
|
75
75
|
`);
|
|
@@ -77,8 +77,8 @@ it("works with a complex case", () => {
|
|
|
77
77
|
|
|
78
78
|
it("works with memos of memos", () => {
|
|
79
79
|
const test = ref(1);
|
|
80
|
-
const tree =
|
|
81
|
-
expect(
|
|
80
|
+
const tree = memo(() => memo(() => test.value));
|
|
81
|
+
expect(tree).toRenderTo("1");
|
|
82
82
|
test.value = 2;
|
|
83
|
-
expect(
|
|
83
|
+
expect(tree).toRenderTo("2");
|
|
84
84
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { Children, RENDERABLE } from "../../src/runtime/component.js";
|
|
3
|
-
import "../../testing/extend-expect.js";
|
|
4
3
|
describe("string nodes", () => {
|
|
5
4
|
it("renders string nodes with substitutions", () => {
|
|
6
5
|
const str = "hi";
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
ContentOutputFile,
|
|
4
|
-
For,
|
|
5
|
-
Output,
|
|
6
|
-
render,
|
|
7
|
-
SourceFile,
|
|
8
|
-
} from "../../src/index.js";
|
|
9
|
-
import "../../testing/extend-expect.js";
|
|
10
|
-
import { d } from "../../testing/render.js";
|
|
2
|
+
import { For, Output, SourceFile } from "../../src/index.js";
|
|
11
3
|
|
|
12
4
|
describe("group", () => {
|
|
13
5
|
it("breaks when shouldBreak is passed", () => {
|
|
@@ -459,16 +451,16 @@ it("formats based on the output component props", () => {
|
|
|
459
451
|
</Output>
|
|
460
452
|
);
|
|
461
453
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
454
|
+
expect(template).toRenderTo(
|
|
455
|
+
`
|
|
456
|
+
1
|
|
457
|
+
2
|
|
458
|
+
3
|
|
459
|
+
4
|
|
460
|
+
5
|
|
461
|
+
6
|
|
462
|
+
`,
|
|
463
|
+
);
|
|
472
464
|
});
|
|
473
465
|
|
|
474
466
|
it("formats based on the source file component props", () => {
|
|
@@ -482,14 +474,14 @@ it("formats based on the source file component props", () => {
|
|
|
482
474
|
</Output>
|
|
483
475
|
);
|
|
484
476
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
477
|
+
expect(template).toRenderTo(
|
|
478
|
+
`
|
|
479
|
+
1
|
|
480
|
+
2
|
|
481
|
+
3
|
|
482
|
+
4
|
|
483
|
+
5
|
|
484
|
+
6
|
|
485
|
+
`,
|
|
486
|
+
);
|
|
495
487
|
});
|
|
@@ -2,13 +2,12 @@ import { ref } from "@vue/reactivity";
|
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { memo } from "../../src/reactivity.js";
|
|
4
4
|
import { flushJobs } from "../../src/scheduler.js";
|
|
5
|
-
import { renderTree } from "../../src/test-render.js";
|
|
6
5
|
|
|
7
6
|
it("memoizes child components", () => {
|
|
8
7
|
let renderCount = 0;
|
|
9
8
|
function Child() {
|
|
10
9
|
renderCount++;
|
|
11
|
-
return "hi
|
|
10
|
+
return "hi";
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
const doThing = ref();
|
|
@@ -25,7 +24,7 @@ it("memoizes child components", () => {
|
|
|
25
24
|
|
|
26
25
|
const template = <>{items}</>;
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
expect(template).toRenderTo("hi");
|
|
29
28
|
doThing.value = true;
|
|
30
29
|
flushJobs();
|
|
31
30
|
// Without element-cache (legacy), each component creator is invoked on
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
resetDevtoolsServerForTests,
|
|
13
13
|
} from "../../src/devtools/devtools-server.js";
|
|
14
14
|
import { clearRenderStack } from "../../src/render-stack.js";
|
|
15
|
-
import "../../testing/extend-expect.js";
|
|
16
15
|
|
|
17
16
|
// Strip ANSI escape codes from a string for consistent testing across environments
|
|
18
17
|
function stripAnsi(str: string): string {
|
package/test/stc.test.tsx
CHANGED
package/test/utils.test.tsx
CHANGED
|
@@ -2,9 +2,7 @@ import { computed, ref, triggerRef } from "@vue/reactivity";
|
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { Children } from "../src/index.js";
|
|
4
4
|
import { flushJobs } from "../src/scheduler.js";
|
|
5
|
-
import { renderTree } from "../src/test-render.js";
|
|
6
5
|
import { children, join, mapJoin } from "../src/utils.js";
|
|
7
|
-
import "../testing/extend-expect.js";
|
|
8
6
|
|
|
9
7
|
describe("mapJoin", () => {
|
|
10
8
|
it("can map a map", () => {
|
|
@@ -107,7 +105,10 @@ describe("mapJoin", () => {
|
|
|
107
105
|
},
|
|
108
106
|
);
|
|
109
107
|
|
|
110
|
-
|
|
108
|
+
expect(joined).toRenderTo(`
|
|
109
|
+
Value: 1
|
|
110
|
+
Value: 2
|
|
111
|
+
`);
|
|
111
112
|
|
|
112
113
|
expect(callCount).toBe(2);
|
|
113
114
|
arr.value.push(3);
|
|
@@ -246,34 +247,34 @@ describe("children", () => {
|
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
it("resolves a single child", () => {
|
|
249
|
-
|
|
250
|
+
expect(<ResolveChildren>1</ResolveChildren>).toRenderTo("");
|
|
250
251
|
expect(resolvedChildren).toEqual("1");
|
|
251
252
|
});
|
|
252
253
|
|
|
253
254
|
it("resolves multiple children", () => {
|
|
254
|
-
|
|
255
|
+
expect(<ResolveChildren>1{"2"}3</ResolveChildren>).toRenderTo("");
|
|
255
256
|
expect(resolvedChildren).toEqual(["1", "2", "3"]);
|
|
256
257
|
});
|
|
257
258
|
|
|
258
259
|
it("resolves fragments by default", () => {
|
|
259
|
-
|
|
260
|
+
expect(
|
|
260
261
|
<ResolveChildren>
|
|
261
262
|
<>1</>
|
|
262
263
|
<>2</>
|
|
263
264
|
<>3</>
|
|
264
265
|
</ResolveChildren>,
|
|
265
|
-
);
|
|
266
|
+
).toRenderTo("");
|
|
266
267
|
expect(resolvedChildren).toEqual(["1", "2", "3"]);
|
|
267
268
|
});
|
|
268
269
|
|
|
269
270
|
it("preserves fragments if asked", () => {
|
|
270
|
-
|
|
271
|
+
expect(
|
|
271
272
|
<ResolveChildren preserveFragments>
|
|
272
273
|
<>1</>
|
|
273
274
|
<>2</>
|
|
274
275
|
<>3</>
|
|
275
276
|
</ResolveChildren>,
|
|
276
|
-
);
|
|
277
|
+
).toRenderTo("");
|
|
277
278
|
expect(resolvedChildren).toEqual([["1"], ["2"], ["3"]]);
|
|
278
279
|
});
|
|
279
280
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
package/testing/extend-expect.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Children, Diagnostic } from "@alloy-js/core";
|
|
2
2
|
import "vitest";
|
|
3
3
|
import { expect } from "vitest";
|
|
4
|
+
import { ElementNode } from "../src/render/node.js";
|
|
4
5
|
import { flushJobs, flushJobsAsync } from "../src/scheduler.js";
|
|
5
6
|
import {
|
|
6
7
|
getDiagnosticsForTree,
|
|
@@ -9,6 +10,28 @@ import {
|
|
|
9
10
|
} from "../src/test-render.js";
|
|
10
11
|
import { dedent } from "./render.js";
|
|
11
12
|
|
|
13
|
+
// Cache rendered trees so the same Children reference reuses its tree across
|
|
14
|
+
// multiple toRenderTo assertions (enables reactive test patterns without
|
|
15
|
+
// explicit renderTree calls).
|
|
16
|
+
const renderedTrees = new WeakMap<object, ElementNode>();
|
|
17
|
+
|
|
18
|
+
function getOrRenderTree(received: Children): ElementNode {
|
|
19
|
+
if (received instanceof ElementNode) {
|
|
20
|
+
return received;
|
|
21
|
+
}
|
|
22
|
+
// If received is an object (array/JSX node), check cache
|
|
23
|
+
if (typeof received === "object" && received !== null) {
|
|
24
|
+
const cached = renderedTrees.get(received as object);
|
|
25
|
+
if (cached) {
|
|
26
|
+
return cached;
|
|
27
|
+
}
|
|
28
|
+
const tree = renderTree(received);
|
|
29
|
+
renderedTrees.set(received as object, tree);
|
|
30
|
+
return tree;
|
|
31
|
+
}
|
|
32
|
+
return renderTree(received);
|
|
33
|
+
}
|
|
34
|
+
|
|
12
35
|
/**
|
|
13
36
|
* Print options passed to `toRenderTo` / `toRenderToAsync`. These override
|
|
14
37
|
* the per-`SourceFile` print settings for the duration of the assertion,
|
|
@@ -47,7 +70,7 @@ expect.extend({
|
|
|
47
70
|
expectedRaw: string | Record<string, string>,
|
|
48
71
|
renderOptions?: ToRenderToOptions,
|
|
49
72
|
) {
|
|
50
|
-
const tree =
|
|
73
|
+
const tree = getOrRenderTree(received);
|
|
51
74
|
flushJobs();
|
|
52
75
|
const actual = getFilesFromTree(tree, renderOptions);
|
|
53
76
|
|