@ryupold/vode 1.8.10 → 1.8.11
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/.github/workflows/publish.yml +5 -0
- package/.github/workflows/tests.yml +1 -0
- package/README.md +36 -2
- package/dist/vode.cjs.min.js +1 -1
- package/dist/vode.d.ts +1 -1
- package/dist/vode.es5.min.js +1 -1
- package/dist/vode.js +5 -5
- package/dist/vode.min.js +1 -1
- package/dist/vode.min.mjs +1 -1
- package/dist/vode.mjs +5 -5
- package/dist/vode.tests.mjs +331 -159
- package/log.txt +1 -0
- package/package.json +1 -1
- package/src/vode.ts +8 -8
- package/test/helper.ts +19 -11
- package/test/mocks.ts +26 -14
- package/test/tests-mount-unmount.ts +219 -142
- package/test/tests-patch-advanced.ts +108 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { delay, expect } from "./helper";
|
|
2
|
-
import { app, createState, DIV } from "../index";
|
|
2
|
+
import { app, ContainerNode, createState, DIV } from "../index";
|
|
3
3
|
|
|
4
4
|
function setup() {
|
|
5
5
|
const root = document.createElement("div");
|
|
6
6
|
const container = document.createElement("div");
|
|
7
7
|
root.appendChild(container);
|
|
8
|
-
return container;
|
|
8
|
+
return container as unknown as ContainerNode;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export default {
|
|
@@ -36,8 +36,11 @@ export default {
|
|
|
36
36
|
await expect(state.phase).toEqual("start");
|
|
37
37
|
|
|
38
38
|
state.patch(async function* () {
|
|
39
|
+
await expect(container._vode.stats.syncRenderPatchCount).toEqual(0);
|
|
39
40
|
yield { phase: "working", value: 10 };
|
|
41
|
+
await expect(container._vode.stats.syncRenderPatchCount).toEqual(1);
|
|
40
42
|
yield { phase: "almost", value: 20 };
|
|
43
|
+
await expect(container._vode.stats.syncRenderPatchCount).toEqual(2);
|
|
41
44
|
return { phase: "done", value: 30 };
|
|
42
45
|
}());
|
|
43
46
|
|
|
@@ -83,4 +86,107 @@ export default {
|
|
|
83
86
|
await expect(state.x).toEqual(10);
|
|
84
87
|
await expect(state.y).toEqual(20);
|
|
85
88
|
},
|
|
89
|
+
|
|
90
|
+
"patch(): returns Promise for generator functions, can be awaited": async () => {
|
|
91
|
+
const container = setup();
|
|
92
|
+
const state = createState({ count: 0 });
|
|
93
|
+
app<typeof state>(container, state, (s) => [DIV, String(s.count)]);
|
|
94
|
+
|
|
95
|
+
await expect(container._vode.stats.patchCount).toEqual(0);
|
|
96
|
+
const result = state.patch(function* () {
|
|
97
|
+
yield { count: 1 };
|
|
98
|
+
return { count: 2 };
|
|
99
|
+
});
|
|
100
|
+
await expect(container._vode.stats.patchCount).toEqual(1);
|
|
101
|
+
|
|
102
|
+
expect(result).toBeA("object");
|
|
103
|
+
await expect(result instanceof Promise).toEqual(true);
|
|
104
|
+
|
|
105
|
+
await result;
|
|
106
|
+
await expect(container._vode.stats.patchCount).toEqual(3);
|
|
107
|
+
|
|
108
|
+
await expect(state.count).toEqual(2);
|
|
109
|
+
await expect(container).toMatch([DIV, "2"]);
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
"patch(): returns Promise for Promise patches, can be awaited": async () => {
|
|
113
|
+
const container = setup();
|
|
114
|
+
const state = createState({ msg: "before" });
|
|
115
|
+
app<typeof state>(container, state, (s) => [DIV, s.msg]);
|
|
116
|
+
|
|
117
|
+
const result = state.patch(Promise.resolve({ msg: "after" }));
|
|
118
|
+
|
|
119
|
+
expect(result).toBeA("object");
|
|
120
|
+
await expect(result instanceof Promise).toEqual(true);
|
|
121
|
+
|
|
122
|
+
await result;
|
|
123
|
+
|
|
124
|
+
await expect(state.msg).toEqual("after");
|
|
125
|
+
await expect(container).toMatch([DIV, "after"]);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
"patch(): returns void for object patches": async () => {
|
|
129
|
+
const container = setup();
|
|
130
|
+
const state = createState({ x: 1 });
|
|
131
|
+
app<typeof state>(container, state, (s) => [DIV, String(s.x)]);
|
|
132
|
+
|
|
133
|
+
const result = state.patch({ x: 2 });
|
|
134
|
+
|
|
135
|
+
expect(result).toBeA("undefined");
|
|
136
|
+
|
|
137
|
+
await expect(state.x).toEqual(2);
|
|
138
|
+
await expect(container).toMatch([DIV, "2"]);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
"patch(): forward promise error when one happens during patch": async () => {
|
|
142
|
+
const container = setup();
|
|
143
|
+
const state = createState({ msg: "before" });
|
|
144
|
+
app<typeof state>(container, state, (s) => [DIV, s.msg]);
|
|
145
|
+
|
|
146
|
+
const mockPromise = Promise.withResolvers<void>();
|
|
147
|
+
const promisePatchResult = state.patch(mockPromise.promise);
|
|
148
|
+
mockPromise.reject(new Error("promise error"));
|
|
149
|
+
|
|
150
|
+
let err = await expect(() => promisePatchResult)
|
|
151
|
+
.toFailAsync("promise (1) error expected");
|
|
152
|
+
expect(err.message).toEqual("promise error");
|
|
153
|
+
|
|
154
|
+
err = await expect(() => state.patch(async () => {
|
|
155
|
+
await delay(1);
|
|
156
|
+
throw new Error("promise error")
|
|
157
|
+
})).toFailAsync("promise (2) error expected");
|
|
158
|
+
expect(err.message).toEqual("promise error");
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
"patch(): forward generator error when one happens during patch": async () => {
|
|
162
|
+
const container = setup();
|
|
163
|
+
const state = createState({ msg: "before" });
|
|
164
|
+
app<typeof state>(container, state, (s) => [DIV, s.msg]);
|
|
165
|
+
|
|
166
|
+
const err = await expect(
|
|
167
|
+
() => state.patch(
|
|
168
|
+
async function* () {
|
|
169
|
+
yield {};
|
|
170
|
+
await delay(1);
|
|
171
|
+
yield {};
|
|
172
|
+
throw new Error("generator error");
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
).toFailAsync("generator error expected");
|
|
176
|
+
expect(err.message).toEqual("generator error");
|
|
177
|
+
},
|
|
178
|
+
"patch(): forward error when one happens during patch": async () => {
|
|
179
|
+
const container = setup();
|
|
180
|
+
const state = createState({ msg: "before" });
|
|
181
|
+
app<typeof state>(container, state, (s) => [DIV, s.msg]);
|
|
182
|
+
|
|
183
|
+
const err = await expect(
|
|
184
|
+
() => state.patch(
|
|
185
|
+
() => {
|
|
186
|
+
throw new Error("void error");
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
).toFailAsync("void error expected");
|
|
190
|
+
expect(err.message).toEqual("void error");
|
|
191
|
+
},
|
|
86
192
|
};
|