@omriashke/dynamico-validator 0.1.3 → 0.1.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.
- package/LICENSE +184 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interactSmoke.d.ts +7 -0
- package/dist/interactSmoke.d.ts.map +1 -0
- package/dist/interactSmoke.js +50 -0
- package/dist/interactSmoke.js.map +1 -0
- package/dist/render.d.ts +10 -24
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +67 -17
- package/dist/render.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +1 -0
- package/src/interactSmoke.ts +51 -0
- package/src/render.ts +85 -29
package/LICENSE
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of developing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or
|
|
82
|
+
contributory patent infringement, then any patent licenses granted
|
|
83
|
+
to You under this License for that Work shall terminate as of the
|
|
84
|
+
date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, reproduce, modify,
|
|
120
|
+
prepare Derivative Works of, convert to Object form, display,
|
|
121
|
+
perform, sublicense, and distribute the Work and such Derivative
|
|
122
|
+
Works in Source or Object form.
|
|
123
|
+
|
|
124
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
125
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
126
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
127
|
+
this License, without any additional terms or conditions.
|
|
128
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
129
|
+
the terms of any separate license agreement you may have executed
|
|
130
|
+
with Licensor regarding such Contributions.
|
|
131
|
+
|
|
132
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
133
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
134
|
+
except as required for reasonable and customary use in describing the
|
|
135
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
136
|
+
|
|
137
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
138
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
139
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
140
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
141
|
+
implied, including, without limitation, any warranties or conditions
|
|
142
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
143
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
144
|
+
appropriateness of using or redistributing the Work and assume any
|
|
145
|
+
risks associated with Your exercise of permissions under this License.
|
|
146
|
+
|
|
147
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
148
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
149
|
+
unless required by applicable law (such as deliberate and grossly
|
|
150
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
151
|
+
liable to You for damages, including any direct, indirect, special,
|
|
152
|
+
incidental, or exemplary damages of any character arising as a
|
|
153
|
+
result of this License or out of the use or inability to use the
|
|
154
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
155
|
+
work stoppage, computer failure or malfunction, or all other
|
|
156
|
+
commercial damages or losses), even if such Contributor has been
|
|
157
|
+
advised of the possibility of such damages.
|
|
158
|
+
|
|
159
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
160
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
161
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
162
|
+
or other liability obligations and/or rights consistent with this
|
|
163
|
+
License. However, in accepting such obligations, You may offer such
|
|
164
|
+
obligations only on Your own behalf and on Your sole responsibility,
|
|
165
|
+
not on behalf of any other Contributor, and only if You agree to
|
|
166
|
+
indemnify, defend, and hold each Contributor harmless for any
|
|
167
|
+
liability incurred by, or claims asserted against, such Contributor
|
|
168
|
+
by reason of your accepting any such warranty or additional liability.
|
|
169
|
+
|
|
170
|
+
END OF TERMS AND CONDITIONS
|
|
171
|
+
|
|
172
|
+
Copyright 2024 Omri Askenazi
|
|
173
|
+
|
|
174
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
175
|
+
you may not use this file except in compliance with the License.
|
|
176
|
+
You may obtain a copy of the License at
|
|
177
|
+
|
|
178
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
179
|
+
|
|
180
|
+
Unless required by applicable law or agreed to in writing, software
|
|
181
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
182
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
183
|
+
See the License for the specific language governing permissions and
|
|
184
|
+
limitations under the License.
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
export { render, type RenderResult, type RenderOptions } from "./render.js";
|
|
19
19
|
export { press, longPress, changeText } from "./events.js";
|
|
20
20
|
export { findByText, findAllByType, queryByText } from "./queries.js";
|
|
21
|
+
export { interactSmoke } from "./interactSmoke.js";
|
|
21
22
|
export { sleep, flush } from "./timing.js";
|
|
22
23
|
export { expect, type Expectation } from "./expect.js";
|
|
23
24
|
export { runTest, type RunTestInput, type RunTestResult, setHostScope, getHostScope } from "./runTest.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
export { render } from "./render.js";
|
|
19
19
|
export { press, longPress, changeText } from "./events.js";
|
|
20
20
|
export { findByText, findAllByType, queryByText } from "./queries.js";
|
|
21
|
+
export { interactSmoke } from "./interactSmoke.js";
|
|
21
22
|
export { sleep, flush } from "./timing.js";
|
|
22
23
|
export { expect } from "./expect.js";
|
|
23
24
|
export { runTest, setHostScope, getHostScope } from "./runTest.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAyC,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAyC,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAyC,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAyC,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactTestInstance } from "react-test-renderer";
|
|
2
|
+
/**
|
|
3
|
+
* Press every interactive node in the tree. Catches runtime errors that only
|
|
4
|
+
* appear after user interaction (undefined refs in handlers, bad hook data, etc.).
|
|
5
|
+
*/
|
|
6
|
+
export declare function interactSmoke(root: ReactTestInstance): void;
|
|
7
|
+
//# sourceMappingURL=interactSmoke.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactSmoke.d.ts","sourceRoot":"","sources":["../src/interactSmoke.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CA6B3D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import TestRenderer from "react-test-renderer";
|
|
2
|
+
const MAX_INTERACTIONS = 64;
|
|
3
|
+
function nodeType(node) {
|
|
4
|
+
if (typeof node.type === "string")
|
|
5
|
+
return node.type;
|
|
6
|
+
return node.type.displayName ?? "";
|
|
7
|
+
}
|
|
8
|
+
function walk(node, visit) {
|
|
9
|
+
visit(node);
|
|
10
|
+
for (const child of node.children ?? []) {
|
|
11
|
+
if (typeof child !== "string")
|
|
12
|
+
walk(child, visit);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Press every interactive node in the tree. Catches runtime errors that only
|
|
17
|
+
* appear after user interaction (undefined refs in handlers, bad hook data, etc.).
|
|
18
|
+
*/
|
|
19
|
+
export function interactSmoke(root) {
|
|
20
|
+
const targets = [];
|
|
21
|
+
walk(root, (node) => {
|
|
22
|
+
const props = node.props ?? {};
|
|
23
|
+
if (typeof props.onPress === "function" || typeof props.onValueChange === "function") {
|
|
24
|
+
targets.push(node);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
let count = 0;
|
|
28
|
+
for (const node of targets) {
|
|
29
|
+
if (count >= MAX_INTERACTIONS)
|
|
30
|
+
break;
|
|
31
|
+
const props = node.props ?? {};
|
|
32
|
+
try {
|
|
33
|
+
TestRenderer.act(() => {
|
|
34
|
+
if (typeof props.onPress === "function") {
|
|
35
|
+
props.onPress({});
|
|
36
|
+
count++;
|
|
37
|
+
}
|
|
38
|
+
if (typeof props.onValueChange === "function") {
|
|
39
|
+
props.onValueChange(!props.value);
|
|
40
|
+
count++;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
46
|
+
throw new Error(message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=interactSmoke.js.map
|
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YACH,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE;gBACpB,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;oBACxC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;oBAClB,KAAK,EAAE,CAAC;gBACV,CAAC;gBACD,IAAI,OAAO,KAAK,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;oBAC9C,KAAK,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAClC,KAAK,EAAE,CAAC;gBACV,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/render.d.ts
CHANGED
|
@@ -5,41 +5,27 @@ export interface RenderOptions {
|
|
|
5
5
|
* Override or extend the auto-stubbed scope for this render. Keys are bare
|
|
6
6
|
* specifiers that the component imports (e.g. '@newscast/app-hooks'); values
|
|
7
7
|
* are the modules the component will receive when it require()s that key.
|
|
8
|
-
*
|
|
9
|
-
* The runner already auto-stubs everything the component imports with empty
|
|
10
|
-
* objects; use this to set specific return values (e.g. simulate
|
|
11
|
-
* `useAuth() === { isAuthenticated: true }`).
|
|
12
8
|
*/
|
|
13
9
|
scope?: Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* After mount, walk the tree and fire onPress / onValueChange on interactive
|
|
12
|
+
* nodes to surface handler-time runtime errors. Default true.
|
|
13
|
+
*/
|
|
14
|
+
interact?: boolean;
|
|
14
15
|
}
|
|
15
16
|
export interface RenderResult {
|
|
16
17
|
root: ReactTestInstance;
|
|
17
18
|
renderer: ReactTestRenderer;
|
|
18
|
-
|
|
19
|
-
update: (next: React.ReactElement) => void;
|
|
20
|
-
/** Tear down. Tests don't usually need to call this; the runner does it. */
|
|
19
|
+
update: (next: React.ReactElement) => Promise<void>;
|
|
21
20
|
unmount: () => void;
|
|
22
|
-
/**
|
|
23
|
-
* Convenience: get the rendered tree as a serializable JSON snapshot. Useful
|
|
24
|
-
* when a test wants to assert on overall shape rather than poking specific
|
|
25
|
-
* nodes.
|
|
26
|
-
*/
|
|
27
21
|
toJSON: () => unknown;
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Mount a component using react-test-renderer.
|
|
31
25
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* test renderer". Deferring the access to call-time (when the test actually
|
|
36
|
-
* needs it) avoids the race.
|
|
37
|
-
*
|
|
38
|
-
* `RenderOptions.scope` is currently a hint surface only — the actual scope
|
|
39
|
-
* is wired up by the runner before render() is called (see runTest.ts), so
|
|
40
|
-
* passing scope here when calling render() directly in a test file is a no-op
|
|
41
|
-
* unless the runner is honoring it. The runner DOES merge scope from the
|
|
42
|
-
* second arg, so use it to control what hooks / modules the component sees.
|
|
26
|
+
* React 19 logs render errors instead of throwing from TestRenderer.create.
|
|
27
|
+
* We capture those console errors and fail the push gate. After mount, optional
|
|
28
|
+
* interact smoke presses handlers to catch tap-time crashes.
|
|
43
29
|
*/
|
|
44
|
-
export declare function render(element: React.ReactElement,
|
|
30
|
+
export declare function render(element: React.ReactElement, opts?: RenderOptions): Promise<RenderResult>;
|
|
45
31
|
//# sourceMappingURL=render.d.ts.map
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIhF,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,iBAAiB,CAAC;IACxB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,OAAO,CAAC;CACvB;AAuCD;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,KAAK,CAAC,YAAY,EAC3B,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,YAAY,CAAC,CA2CvB"}
|
package/dist/render.js
CHANGED
|
@@ -1,26 +1,68 @@
|
|
|
1
1
|
import TestRenderer from "react-test-renderer";
|
|
2
|
+
import { interactSmoke } from "./interactSmoke.js";
|
|
3
|
+
import { flush } from "./timing.js";
|
|
4
|
+
let lastRenderError = null;
|
|
5
|
+
function assertNoRenderError(phase) {
|
|
6
|
+
if (lastRenderError) {
|
|
7
|
+
const err = lastRenderError;
|
|
8
|
+
lastRenderError = null;
|
|
9
|
+
const wrapped = new Error(`${phase}: ${err.message}`);
|
|
10
|
+
wrapped.stack = err.stack;
|
|
11
|
+
throw wrapped;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function captureReactRenderErrors(fn) {
|
|
15
|
+
const errors = [];
|
|
16
|
+
const origError = console.error;
|
|
17
|
+
console.error = (...args) => {
|
|
18
|
+
const msg = args.map((a) => (a instanceof Error ? a.message : String(a))).join(" ");
|
|
19
|
+
if (msg.includes("An error occurred in the") ||
|
|
20
|
+
msg.includes("ReferenceError") ||
|
|
21
|
+
msg.includes("TypeError") ||
|
|
22
|
+
msg.includes("is not defined")) {
|
|
23
|
+
errors.push(msg);
|
|
24
|
+
}
|
|
25
|
+
origError.apply(console, args);
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
return fn();
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
console.error = origError;
|
|
32
|
+
if (errors.length > 0 && !lastRenderError) {
|
|
33
|
+
lastRenderError = new Error(errors[0]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
2
37
|
/**
|
|
3
38
|
* Mount a component using react-test-renderer.
|
|
4
39
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* test renderer". Deferring the access to call-time (when the test actually
|
|
9
|
-
* needs it) avoids the race.
|
|
10
|
-
*
|
|
11
|
-
* `RenderOptions.scope` is currently a hint surface only — the actual scope
|
|
12
|
-
* is wired up by the runner before render() is called (see runTest.ts), so
|
|
13
|
-
* passing scope here when calling render() directly in a test file is a no-op
|
|
14
|
-
* unless the runner is honoring it. The runner DOES merge scope from the
|
|
15
|
-
* second arg, so use it to control what hooks / modules the component sees.
|
|
40
|
+
* React 19 logs render errors instead of throwing from TestRenderer.create.
|
|
41
|
+
* We capture those console errors and fail the push gate. After mount, optional
|
|
42
|
+
* interact smoke presses handlers to catch tap-time crashes.
|
|
16
43
|
*/
|
|
17
|
-
export function render(element,
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
export async function render(element, opts = {}) {
|
|
45
|
+
const shouldInteract = opts.interact !== false;
|
|
46
|
+
let renderer;
|
|
47
|
+
captureReactRenderErrors(() => {
|
|
48
|
+
TestRenderer.act(() => {
|
|
49
|
+
renderer = TestRenderer.create(element);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
await flush();
|
|
53
|
+
assertNoRenderError("render");
|
|
54
|
+
const root = renderer.root;
|
|
55
|
+
const result = {
|
|
56
|
+
root,
|
|
21
57
|
renderer,
|
|
22
|
-
update(next) {
|
|
23
|
-
|
|
58
|
+
async update(next) {
|
|
59
|
+
captureReactRenderErrors(() => {
|
|
60
|
+
TestRenderer.act(() => {
|
|
61
|
+
renderer.update(next);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
await flush();
|
|
65
|
+
assertNoRenderError("render update");
|
|
24
66
|
},
|
|
25
67
|
unmount() {
|
|
26
68
|
renderer.unmount();
|
|
@@ -29,5 +71,13 @@ export function render(element, _opts = {}) {
|
|
|
29
71
|
return renderer.toJSON();
|
|
30
72
|
},
|
|
31
73
|
};
|
|
74
|
+
if (shouldInteract) {
|
|
75
|
+
captureReactRenderErrors(() => {
|
|
76
|
+
interactSmoke(root);
|
|
77
|
+
});
|
|
78
|
+
await flush();
|
|
79
|
+
assertNoRenderError("interact");
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
32
82
|
}
|
|
33
83
|
//# sourceMappingURL=render.js.map
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAwBpC,IAAI,eAAe,GAAiB,IAAI,CAAC;AAEzC,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,eAAe,CAAC;QAC5B,eAA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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omriashke/dynamico-validator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Server-side validator for dynamico components. Provides render(), press(), findByText() with auto-stubbed react-native + host scope so the registry can execute each component's co-located *.test.tsx in a worker thread and reject pushes that throw, miss a scope binding, or render incorrectly.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsc -p tsconfig.json",
|
|
41
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
42
|
-
},
|
|
43
39
|
"dependencies": {
|
|
44
|
-
"@omriashke/dynamico-core": "workspace:*",
|
|
45
40
|
"react": "^19.0.0",
|
|
46
|
-
"react-test-renderer": "^19.0.0"
|
|
41
|
+
"react-test-renderer": "^19.0.0",
|
|
42
|
+
"@omriashke/dynamico-core": "0.1.5"
|
|
47
43
|
},
|
|
48
44
|
"devDependencies": {
|
|
49
45
|
"@types/react": "^18.3.0",
|
|
50
46
|
"@types/react-test-renderer": "^18.3.0",
|
|
51
47
|
"typescript": "^5.6.3"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.json",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
export { render, type RenderResult, type RenderOptions } from "./render.js";
|
|
19
19
|
export { press, longPress, changeText } from "./events.js";
|
|
20
20
|
export { findByText, findAllByType, queryByText } from "./queries.js";
|
|
21
|
+
export { interactSmoke } from "./interactSmoke.js";
|
|
21
22
|
export { sleep, flush } from "./timing.js";
|
|
22
23
|
export { expect, type Expectation } from "./expect.js";
|
|
23
24
|
export { runTest, type RunTestInput, type RunTestResult, setHostScope, getHostScope } from "./runTest.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import TestRenderer from "react-test-renderer";
|
|
2
|
+
import type { ReactTestInstance } from "react-test-renderer";
|
|
3
|
+
|
|
4
|
+
const MAX_INTERACTIONS = 64;
|
|
5
|
+
|
|
6
|
+
function nodeType(node: ReactTestInstance): string {
|
|
7
|
+
if (typeof node.type === "string") return node.type;
|
|
8
|
+
return (node.type as { displayName?: string }).displayName ?? "";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function walk(node: ReactTestInstance, visit: (n: ReactTestInstance) => void): void {
|
|
12
|
+
visit(node);
|
|
13
|
+
for (const child of node.children ?? []) {
|
|
14
|
+
if (typeof child !== "string") walk(child, visit);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Press every interactive node in the tree. Catches runtime errors that only
|
|
20
|
+
* appear after user interaction (undefined refs in handlers, bad hook data, etc.).
|
|
21
|
+
*/
|
|
22
|
+
export function interactSmoke(root: ReactTestInstance): void {
|
|
23
|
+
const targets: ReactTestInstance[] = [];
|
|
24
|
+
walk(root, (node) => {
|
|
25
|
+
const props = node.props ?? {};
|
|
26
|
+
if (typeof props.onPress === "function" || typeof props.onValueChange === "function") {
|
|
27
|
+
targets.push(node);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let count = 0;
|
|
32
|
+
for (const node of targets) {
|
|
33
|
+
if (count >= MAX_INTERACTIONS) break;
|
|
34
|
+
const props = node.props ?? {};
|
|
35
|
+
try {
|
|
36
|
+
TestRenderer.act(() => {
|
|
37
|
+
if (typeof props.onPress === "function") {
|
|
38
|
+
props.onPress({});
|
|
39
|
+
count++;
|
|
40
|
+
}
|
|
41
|
+
if (typeof props.onValueChange === "function") {
|
|
42
|
+
props.onValueChange(!props.value);
|
|
43
|
+
count++;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
} catch (err) {
|
|
47
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
48
|
+
throw new Error(message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/render.ts
CHANGED
|
@@ -1,57 +1,103 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import TestRenderer from "react-test-renderer";
|
|
3
3
|
import type { ReactTestInstance, ReactTestRenderer } from "react-test-renderer";
|
|
4
|
+
import { interactSmoke } from "./interactSmoke.js";
|
|
5
|
+
import { flush } from "./timing.js";
|
|
4
6
|
|
|
5
7
|
export interface RenderOptions {
|
|
6
8
|
/**
|
|
7
9
|
* Override or extend the auto-stubbed scope for this render. Keys are bare
|
|
8
10
|
* specifiers that the component imports (e.g. '@newscast/app-hooks'); values
|
|
9
11
|
* are the modules the component will receive when it require()s that key.
|
|
10
|
-
*
|
|
11
|
-
* The runner already auto-stubs everything the component imports with empty
|
|
12
|
-
* objects; use this to set specific return values (e.g. simulate
|
|
13
|
-
* `useAuth() === { isAuthenticated: true }`).
|
|
14
12
|
*/
|
|
15
13
|
scope?: Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* After mount, walk the tree and fire onPress / onValueChange on interactive
|
|
16
|
+
* nodes to surface handler-time runtime errors. Default true.
|
|
17
|
+
*/
|
|
18
|
+
interact?: boolean;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
export interface RenderResult {
|
|
19
22
|
root: ReactTestInstance;
|
|
20
23
|
renderer: ReactTestRenderer;
|
|
21
|
-
|
|
22
|
-
update: (next: React.ReactElement) => void;
|
|
23
|
-
/** Tear down. Tests don't usually need to call this; the runner does it. */
|
|
24
|
+
update: (next: React.ReactElement) => Promise<void>;
|
|
24
25
|
unmount: () => void;
|
|
25
|
-
/**
|
|
26
|
-
* Convenience: get the rendered tree as a serializable JSON snapshot. Useful
|
|
27
|
-
* when a test wants to assert on overall shape rather than poking specific
|
|
28
|
-
* nodes.
|
|
29
|
-
*/
|
|
30
26
|
toJSON: () => unknown;
|
|
31
27
|
}
|
|
32
28
|
|
|
29
|
+
let lastRenderError: Error | null = null;
|
|
30
|
+
|
|
31
|
+
function assertNoRenderError(phase: string): void {
|
|
32
|
+
if (lastRenderError) {
|
|
33
|
+
const err = lastRenderError;
|
|
34
|
+
lastRenderError = null;
|
|
35
|
+
const wrapped = new Error(`${phase}: ${err.message}`);
|
|
36
|
+
wrapped.stack = err.stack;
|
|
37
|
+
throw wrapped;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function captureReactRenderErrors<T>(fn: () => T): T {
|
|
42
|
+
const errors: string[] = [];
|
|
43
|
+
const origError = console.error;
|
|
44
|
+
console.error = (...args: unknown[]) => {
|
|
45
|
+
const msg = args.map((a) => (a instanceof Error ? a.message : String(a))).join(" ");
|
|
46
|
+
if (
|
|
47
|
+
msg.includes("An error occurred in the") ||
|
|
48
|
+
msg.includes("ReferenceError") ||
|
|
49
|
+
msg.includes("TypeError") ||
|
|
50
|
+
msg.includes("is not defined")
|
|
51
|
+
) {
|
|
52
|
+
errors.push(msg);
|
|
53
|
+
}
|
|
54
|
+
origError.apply(console, args as []);
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
return fn();
|
|
58
|
+
} finally {
|
|
59
|
+
console.error = origError;
|
|
60
|
+
if (errors.length > 0 && !lastRenderError) {
|
|
61
|
+
lastRenderError = new Error(errors[0]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
33
66
|
/**
|
|
34
67
|
* Mount a component using react-test-renderer.
|
|
35
68
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* test renderer". Deferring the access to call-time (when the test actually
|
|
40
|
-
* needs it) avoids the race.
|
|
41
|
-
*
|
|
42
|
-
* `RenderOptions.scope` is currently a hint surface only — the actual scope
|
|
43
|
-
* is wired up by the runner before render() is called (see runTest.ts), so
|
|
44
|
-
* passing scope here when calling render() directly in a test file is a no-op
|
|
45
|
-
* unless the runner is honoring it. The runner DOES merge scope from the
|
|
46
|
-
* second arg, so use it to control what hooks / modules the component sees.
|
|
69
|
+
* React 19 logs render errors instead of throwing from TestRenderer.create.
|
|
70
|
+
* We capture those console errors and fail the push gate. After mount, optional
|
|
71
|
+
* interact smoke presses handlers to catch tap-time crashes.
|
|
47
72
|
*/
|
|
48
|
-
export function render(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
export async function render(
|
|
74
|
+
element: React.ReactElement,
|
|
75
|
+
opts: RenderOptions = {},
|
|
76
|
+
): Promise<RenderResult> {
|
|
77
|
+
const shouldInteract = opts.interact !== false;
|
|
78
|
+
let renderer!: ReactTestRenderer;
|
|
79
|
+
|
|
80
|
+
captureReactRenderErrors(() => {
|
|
81
|
+
TestRenderer.act(() => {
|
|
82
|
+
renderer = TestRenderer.create(element);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
await flush();
|
|
86
|
+
assertNoRenderError("render");
|
|
87
|
+
|
|
88
|
+
const root = renderer.root;
|
|
89
|
+
|
|
90
|
+
const result: RenderResult = {
|
|
91
|
+
root,
|
|
52
92
|
renderer,
|
|
53
|
-
update(next: React.ReactElement) {
|
|
54
|
-
|
|
93
|
+
async update(next: React.ReactElement) {
|
|
94
|
+
captureReactRenderErrors(() => {
|
|
95
|
+
TestRenderer.act(() => {
|
|
96
|
+
renderer.update(next);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
await flush();
|
|
100
|
+
assertNoRenderError("render update");
|
|
55
101
|
},
|
|
56
102
|
unmount() {
|
|
57
103
|
renderer.unmount();
|
|
@@ -60,4 +106,14 @@ export function render(element: React.ReactElement, _opts: RenderOptions = {}):
|
|
|
60
106
|
return renderer.toJSON();
|
|
61
107
|
},
|
|
62
108
|
};
|
|
109
|
+
|
|
110
|
+
if (shouldInteract) {
|
|
111
|
+
captureReactRenderErrors(() => {
|
|
112
|
+
interactSmoke(root);
|
|
113
|
+
});
|
|
114
|
+
await flush();
|
|
115
|
+
assertNoRenderError("interact");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return result;
|
|
63
119
|
}
|