@ryupold/vode 1.8.8 → 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 +5 -6
- package/dist/vode.es5.min.js +1 -1
- package/dist/vode.js +54 -44
- package/dist/vode.min.js +1 -1
- package/dist/vode.min.mjs +1 -1
- package/dist/vode.mjs +54 -44
- package/dist/vode.tests.mjs +5475 -0
- package/log.txt +1 -0
- package/package.json +5 -5
- package/src/vode.ts +63 -52
- package/test/helper.ts +299 -146
- package/test/index.ts +2 -64
- package/test/mocks.ts +83 -9
- package/test/run-tests.ts +61 -0
- package/test/tests-app.ts +48 -48
- package/test/tests-catch.ts +15 -15
- package/test/tests-children.ts +31 -31
- package/test/tests-createPatch.ts +12 -12
- package/test/tests-createState.ts +11 -11
- package/test/tests-defuse.ts +18 -18
- package/test/tests-examples.ts +87 -88
- package/test/tests-hydrate.ts +28 -28
- package/test/tests-memo.ts +29 -28
- package/test/tests-mergeClass.ts +31 -31
- package/test/tests-mergeProps.ts +19 -19
- package/test/tests-mergeStyle.ts +28 -14
- package/test/tests-mount-unmount.ts +368 -268
- package/test/tests-patch-advanced.ts +127 -19
- package/test/tests-patch-merge.ts +15 -15
- package/test/tests-props.ts +15 -15
- package/test/tests-state-context.ts +33 -33
- package/test/tests-tag.ts +14 -14
- package/test/tests-vode.ts +6 -6
package/test/tests-children.ts
CHANGED
|
@@ -2,68 +2,68 @@ import { children, child, childCount, childrenStart, DIV, SPAN, P, Vode } from "
|
|
|
2
2
|
import { expect } from "./helper";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
|
-
"children(): tag+props+children returns children array": () => {
|
|
5
|
+
"children(): tag+props+children returns children array": async () => {
|
|
6
6
|
const v: Vode = [DIV, { class: "x" }, [SPAN, "a"], [P, "b"]];
|
|
7
7
|
const c = children(v);
|
|
8
|
-
expect(Array.isArray(c)).toEqual(true);
|
|
9
|
-
expect(c!.length).toEqual(2);
|
|
8
|
+
await expect(Array.isArray(c)).toEqual(true);
|
|
9
|
+
await expect(c!.length).toEqual(2);
|
|
10
10
|
},
|
|
11
11
|
|
|
12
|
-
"children(): tag+children (no props) returns children array": () => {
|
|
12
|
+
"children(): tag+children (no props) returns children array": async () => {
|
|
13
13
|
const v: Vode = [DIV, [SPAN, "a"], [P, "b"]];
|
|
14
14
|
const c = children(v);
|
|
15
|
-
expect(Array.isArray(c)).toEqual(true);
|
|
16
|
-
expect(c!.length).toEqual(2);
|
|
15
|
+
await expect(Array.isArray(c)).toEqual(true);
|
|
16
|
+
await expect(c!.length).toEqual(2);
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
-
"children(): just-tag vode returns null": () => {
|
|
20
|
-
expect(children([DIV])).toEqual(null);
|
|
19
|
+
"children(): just-tag vode returns null": async () => {
|
|
20
|
+
await expect(children([DIV])).toEqual(null);
|
|
21
21
|
},
|
|
22
22
|
|
|
23
|
-
"children(): text vode returns null": () => {
|
|
24
|
-
expect(children("hello")).toEqual(null);
|
|
23
|
+
"children(): text vode returns null": async () => {
|
|
24
|
+
await expect(children("hello")).toEqual(null);
|
|
25
25
|
},
|
|
26
26
|
|
|
27
|
-
"childrenStart(): with props+children returns 2": () => {
|
|
28
|
-
expect(childrenStart([DIV, { class: "x" }, [SPAN]])).toEqual(2);
|
|
27
|
+
"childrenStart(): with props+children returns 2": async () => {
|
|
28
|
+
await expect(childrenStart([DIV, { class: "x" }, [SPAN]])).toEqual(2);
|
|
29
29
|
},
|
|
30
30
|
|
|
31
|
-
"childrenStart(): without props but with children returns 1": () => {
|
|
32
|
-
expect(childrenStart([DIV, [SPAN]])).toEqual(1);
|
|
31
|
+
"childrenStart(): without props but with children returns 1": async () => {
|
|
32
|
+
await expect(childrenStart([DIV, [SPAN]])).toEqual(1);
|
|
33
33
|
},
|
|
34
34
|
|
|
35
|
-
"childrenStart(): just-tag returns -1": () => {
|
|
36
|
-
expect(childrenStart([DIV])).toEqual(-1);
|
|
35
|
+
"childrenStart(): just-tag returns -1": async () => {
|
|
36
|
+
await expect(childrenStart([DIV])).toEqual(-1);
|
|
37
37
|
},
|
|
38
38
|
|
|
39
|
-
"childrenStart(): text vode returns -1": () => {
|
|
40
|
-
expect(childrenStart("hello")).toEqual(-1);
|
|
39
|
+
"childrenStart(): text vode returns -1": async () => {
|
|
40
|
+
await expect(childrenStart("hello")).toEqual(-1);
|
|
41
41
|
},
|
|
42
42
|
|
|
43
|
-
"childCount(): matches actual child count": () => {
|
|
44
|
-
expect(childCount([DIV, { class: "x" }, [SPAN, "a"], [P, "b"]])).toEqual(2);
|
|
45
|
-
expect(childCount([DIV, [SPAN]])).toEqual(1);
|
|
43
|
+
"childCount(): matches actual child count": async () => {
|
|
44
|
+
await expect(childCount([DIV, { class: "x" }, [SPAN, "a"], [P, "b"]])).toEqual(2);
|
|
45
|
+
await expect(childCount([DIV, [SPAN]])).toEqual(1);
|
|
46
46
|
},
|
|
47
47
|
|
|
48
|
-
"childCount(): returns 0 for no-children vode": () => {
|
|
49
|
-
expect(childCount([DIV])).toEqual(0);
|
|
50
|
-
expect(childCount("hello" as any)).toEqual(0);
|
|
48
|
+
"childCount(): returns 0 for no-children vode": async () => {
|
|
49
|
+
await expect(childCount([DIV])).toEqual(0);
|
|
50
|
+
await expect(childCount("hello" as any)).toEqual(0);
|
|
51
51
|
},
|
|
52
52
|
|
|
53
|
-
"child(): returns correct child at index": () => {
|
|
53
|
+
"child(): returns correct child at index": async () => {
|
|
54
54
|
const v: Vode = [DIV, { class: "x" }, [SPAN, "a"], [P, "b"]];
|
|
55
55
|
|
|
56
|
-
expect(child(v, 0)).toEqual([SPAN, "a"]);
|
|
57
|
-
expect(child(v, 1)).toEqual([P, "b"]);
|
|
56
|
+
await expect(child(v, 0)).toEqual([SPAN, "a"]);
|
|
57
|
+
await expect(child(v, 1)).toEqual([P, "b"]);
|
|
58
58
|
},
|
|
59
59
|
|
|
60
|
-
"child(): returns undefined for out-of-bounds": () => {
|
|
61
|
-
expect(child([DIV, { class: "x" }, [SPAN]], 5))
|
|
60
|
+
"child(): returns undefined for out-of-bounds": async () => {
|
|
61
|
+
await expect(child([DIV, { class: "x" }, [SPAN]], 5))
|
|
62
62
|
.toEqual(undefined);
|
|
63
63
|
},
|
|
64
64
|
|
|
65
|
-
"child(): returns undefined for text vode": () => {
|
|
66
|
-
expect(child("hello" as any, 0))
|
|
65
|
+
"child(): returns undefined for text vode": async () => {
|
|
66
|
+
await expect(child("hello" as any, 0))
|
|
67
67
|
.toEqual(undefined);
|
|
68
68
|
}
|
|
69
69
|
};
|
|
@@ -2,27 +2,27 @@ import { createPatch } from "../src/vode";
|
|
|
2
2
|
import { expect } from "./helper";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
|
-
"createPatch(): just returns the input": () => {
|
|
5
|
+
"createPatch(): just returns the input": async () => {
|
|
6
6
|
const p = { a: 123 };
|
|
7
|
-
expect(createPatch(p) === p).toEqual(true);
|
|
7
|
+
await expect(createPatch(p) === p).toEqual(true);
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
"createPatch(): returns undefined as-is": () => {
|
|
11
|
-
expect(createPatch(undefined)).toEqual(undefined);
|
|
10
|
+
"createPatch(): returns undefined as-is": async () => {
|
|
11
|
+
await expect(createPatch(undefined)).toEqual(undefined);
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
"createPatch(): returns null as-is": () => {
|
|
15
|
-
expect(createPatch(null)).toEqual(null);
|
|
14
|
+
"createPatch(): returns null as-is": async () => {
|
|
15
|
+
await expect(createPatch(null)).toEqual(null);
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
"createPatch(): returns function as-is": () => {
|
|
18
|
+
"createPatch(): returns function as-is": async () => {
|
|
19
19
|
const fn = () => ({});
|
|
20
|
-
expect(createPatch(fn) === fn).toEqual(true);
|
|
20
|
+
await expect(createPatch(fn) === fn).toEqual(true);
|
|
21
21
|
},
|
|
22
22
|
|
|
23
|
-
"createPatch(): returns primitive as-is": () => {
|
|
24
|
-
expect(createPatch(42)).toEqual(42);
|
|
25
|
-
expect(createPatch("ignored")).toEqual("ignored");
|
|
26
|
-
expect(createPatch(false)).toEqual(false);
|
|
23
|
+
"createPatch(): returns primitive as-is": async () => {
|
|
24
|
+
await expect(createPatch(42)).toEqual(42);
|
|
25
|
+
await expect(createPatch("ignored")).toEqual("ignored");
|
|
26
|
+
await expect(createPatch(false)).toEqual(false);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
@@ -2,24 +2,24 @@ import { expect } from "./helper";
|
|
|
2
2
|
import { createState, app, DIV } from "../index";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
|
-
"createState(): throws when state is not an object": () => {
|
|
5
|
+
"createState(): throws when state is not an object": async () => {
|
|
6
6
|
const err = expect(() => createState(null as any)).toFail();
|
|
7
|
-
expect(err.message)
|
|
7
|
+
await expect(err.message)
|
|
8
8
|
.toEqual("createState() must be called with a state object");
|
|
9
9
|
},
|
|
10
10
|
|
|
11
|
-
"createState(): adds patch function to state": () => {
|
|
11
|
+
"createState(): adds patch function to state": async () => {
|
|
12
12
|
const state = createState({ x: 1 });
|
|
13
|
-
expect(typeof (state as any).patch).toEqual("function");
|
|
14
|
-
expect((state)).toEqual({ x: 1, patch: (state as any).patch });
|
|
13
|
+
await expect(typeof (state as any).patch).toEqual("function");
|
|
14
|
+
await expect((state)).toEqual({ x: 1, patch: (state as any).patch });
|
|
15
15
|
},
|
|
16
16
|
|
|
17
|
-
"createState(): patch is non-enumerable": () => {
|
|
17
|
+
"createState(): patch is non-enumerable": async () => {
|
|
18
18
|
const state = createState({ x: 1 });
|
|
19
|
-
expect(Object.keys(state)).toEqual(["x"]);
|
|
19
|
+
await expect(Object.keys(state)).toEqual(["x"]);
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
-
"createState(): app picks up queued patches": () => {
|
|
22
|
+
"createState(): app picks up queued patches": async () => {
|
|
23
23
|
const state: any = createState({ count: 0 });
|
|
24
24
|
state.patch({ count: 1 });
|
|
25
25
|
state.patch({ count: 2 });
|
|
@@ -28,16 +28,16 @@ export default {
|
|
|
28
28
|
root.appendChild(container);
|
|
29
29
|
app(container, state, () => [DIV]);
|
|
30
30
|
|
|
31
|
-
expect(state.count)
|
|
31
|
+
await expect(state.count)
|
|
32
32
|
.toEqual(2);
|
|
33
33
|
},
|
|
34
34
|
|
|
35
|
-
"createState(): already-patchable state is kept as-is": () => {
|
|
35
|
+
"createState(): already-patchable state is kept as-is": async () => {
|
|
36
36
|
const existingPatch = (action: any) => { };
|
|
37
37
|
const state: any = { value: 5, patch: existingPatch };
|
|
38
38
|
const result = createState(state);
|
|
39
39
|
|
|
40
|
-
expect(result.patch === existingPatch)
|
|
40
|
+
await expect(result.patch === existingPatch)
|
|
41
41
|
.toEqual(true);
|
|
42
42
|
},
|
|
43
43
|
};
|
package/test/tests-defuse.ts
CHANGED
|
@@ -9,56 +9,56 @@ export default {
|
|
|
9
9
|
.toSucceed();
|
|
10
10
|
},
|
|
11
11
|
|
|
12
|
-
"defuse(): removes _vode from container": () => {
|
|
12
|
+
"defuse(): removes _vode from container": async () => {
|
|
13
13
|
const root = document.createElement("div");
|
|
14
14
|
const container = document.createElement("div");
|
|
15
15
|
root.appendChild(container);
|
|
16
16
|
app(container, {}, () => [DIV]);
|
|
17
|
-
expect(typeof (container as any)._vode).toEqual("object");
|
|
17
|
+
await expect(typeof (container as any)._vode).toEqual("object");
|
|
18
18
|
defuse(container as any);
|
|
19
19
|
|
|
20
|
-
expect((container as any)._vode)
|
|
20
|
+
await expect((container as any)._vode)
|
|
21
21
|
.toEqual(undefined);
|
|
22
22
|
},
|
|
23
23
|
|
|
24
|
-
"defuse(): removes patch function from state": () => {
|
|
24
|
+
"defuse(): removes patch function from state": async () => {
|
|
25
25
|
const root = document.createElement("div");
|
|
26
26
|
const container = document.createElement("div");
|
|
27
27
|
root.appendChild(container);
|
|
28
28
|
const state: any = {};
|
|
29
29
|
app(container, state, () => [DIV]);
|
|
30
|
-
expect(typeof state.patch).toEqual("function");
|
|
30
|
+
await expect(typeof state.patch).toEqual("function");
|
|
31
31
|
defuse(container as any);
|
|
32
32
|
|
|
33
|
-
expect(state.patch)
|
|
33
|
+
await expect(state.patch)
|
|
34
34
|
.toEqual(undefined);
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
"defuse(): disables renderSync and renderAsync": () => {
|
|
37
|
+
"defuse(): disables renderSync and renderAsync": async () => {
|
|
38
38
|
const root = document.createElement("div");
|
|
39
39
|
const container = document.createElement("div");
|
|
40
40
|
root.appendChild(container);
|
|
41
41
|
app(container, {}, () => [DIV]);
|
|
42
42
|
defuse(container as any);
|
|
43
43
|
|
|
44
|
-
expect((container as any)._vode)
|
|
44
|
+
await expect((container as any)._vode)
|
|
45
45
|
.toEqual(undefined);
|
|
46
46
|
},
|
|
47
47
|
|
|
48
|
-
"defuse(): clears event listeners from rendered elements": () => {
|
|
48
|
+
"defuse(): clears event listeners from rendered elements": async () => {
|
|
49
49
|
const root = document.createElement("div");
|
|
50
50
|
const container = document.createElement("div");
|
|
51
51
|
root.appendChild(container);
|
|
52
52
|
app(container, {}, () => [DIV, { onclick: () => ({}) }] as any);
|
|
53
53
|
const node = (container as any)._vode.vode.node;
|
|
54
|
-
expect(typeof node.onclick).toEqual("function");
|
|
54
|
+
await expect(typeof node.onclick).toEqual("function");
|
|
55
55
|
defuse(container as any);
|
|
56
56
|
|
|
57
|
-
expect(node.onclick)
|
|
57
|
+
await expect(node.onclick)
|
|
58
58
|
.toEqual(null);
|
|
59
59
|
},
|
|
60
60
|
|
|
61
|
-
"defuse(): recurses into child containers": () => {
|
|
61
|
+
"defuse(): recurses into child containers": async () => {
|
|
62
62
|
const root = document.createElement("div");
|
|
63
63
|
const outer = document.createElement("div");
|
|
64
64
|
const inner = document.createElement("div");
|
|
@@ -68,11 +68,11 @@ export default {
|
|
|
68
68
|
app(inner, state, () => [DIV]);
|
|
69
69
|
defuse(outer as any);
|
|
70
70
|
|
|
71
|
-
expect(state.patch)
|
|
71
|
+
await expect(state.patch)
|
|
72
72
|
.toEqual(undefined);
|
|
73
73
|
},
|
|
74
74
|
|
|
75
|
-
"defuse(): clears event listeners from child vodes without _vode": () => {
|
|
75
|
+
"defuse(): clears event listeners from child vodes without _vode": async () => {
|
|
76
76
|
const root = document.createElement("div");
|
|
77
77
|
const container = document.createElement("div");
|
|
78
78
|
root.appendChild(container);
|
|
@@ -83,13 +83,13 @@ export default {
|
|
|
83
83
|
const child1 = (v as any).node;
|
|
84
84
|
const child1onclick = child1.onclick;
|
|
85
85
|
const child2 = (v as any)[2].node;
|
|
86
|
-
expect(typeof child1onclick).toEqual("function");
|
|
87
|
-
expect(typeof child2.onclick).toEqual("function");
|
|
86
|
+
await expect(typeof child1onclick).toEqual("function");
|
|
87
|
+
await expect(typeof child2.onclick).toEqual("function");
|
|
88
88
|
defuse(container as any);
|
|
89
89
|
|
|
90
|
-
expect(child1.onclick)
|
|
90
|
+
await expect(child1.onclick)
|
|
91
91
|
.toEqual(null);
|
|
92
|
-
expect(child2.onclick)
|
|
92
|
+
await expect(child2.onclick)
|
|
93
93
|
.toEqual(null);
|
|
94
94
|
},
|
|
95
95
|
};
|