@nyby/detox-component-testing 1.3.0 → 1.4.2
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/README.md +19 -3
- package/dist/ComponentHarness.d.ts.map +1 -1
- package/dist/ComponentHarness.js +9 -8
- package/dist/ComponentHarness.js.map +1 -1
- package/dist/ComponentRegistry.d.ts.map +1 -1
- package/dist/ComponentRegistry.js.map +1 -1
- package/dist/DebugTree.d.ts +20 -0
- package/dist/DebugTree.d.ts.map +1 -0
- package/dist/DebugTree.js +239 -0
- package/dist/DebugTree.js.map +1 -0
- package/dist/configureHarness.d.ts.map +1 -1
- package/dist/configureHarness.js.map +1 -1
- package/dist/debug.d.ts +2 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +49 -0
- package/dist/debug.js.map +1 -0
- package/dist/environment.js +45 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/mount.d.ts.map +1 -1
- package/dist/mount.js +24 -5
- package/dist/mount.js.map +1 -1
- package/dist/test.d.ts +2 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +3 -2
- package/dist/test.js.map +1 -1
- package/package.json +13 -5
- package/src/ComponentHarness.tsx +35 -34
- package/src/ComponentRegistry.ts +2 -5
- package/src/DebugTree.tsx +280 -0
- package/src/configureHarness.ts +2 -2
- package/src/debug.ts +48 -0
- package/src/detox-env.d.ts +6 -2
- package/src/environment.js +45 -0
- package/src/index.ts +4 -3
- package/src/mount.ts +25 -9
- package/src/test.ts +2 -1
package/src/mount.ts
CHANGED
|
@@ -15,25 +15,26 @@ let mountCounter = 0;
|
|
|
15
15
|
let appLaunched = false;
|
|
16
16
|
|
|
17
17
|
export function spy(name: string): SpyMarker {
|
|
18
|
-
return {
|
|
18
|
+
return {[SPY_MARKER]: true, name};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
type MountProps = Record<string, string | number | boolean | SpyMarker>;
|
|
22
22
|
|
|
23
23
|
export async function assertNoRenderError(): Promise<void> {
|
|
24
24
|
try {
|
|
25
|
-
await waitFor(element(by.id('detox-render-error')))
|
|
25
|
+
await waitFor(element(by.id('detox-render-error')))
|
|
26
|
+
.toExist()
|
|
27
|
+
.withTimeout(500);
|
|
26
28
|
} catch {
|
|
27
29
|
return; // Element not found — no render error, all good
|
|
28
30
|
}
|
|
29
31
|
// Element exists — read the error message and throw
|
|
30
|
-
const attrs = await element(by.id('detox-render-error-message')).getAttributes() as any;
|
|
32
|
+
const attrs = (await element(by.id('detox-render-error-message')).getAttributes()) as any;
|
|
31
33
|
const message = attrs.text || attrs.label || 'Unknown render error';
|
|
32
34
|
throw new Error(`Component render error: ${message}`);
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export async function mount(componentName: string, props?: MountProps): Promise<void> {
|
|
36
|
-
|
|
37
38
|
const payload = {
|
|
38
39
|
id: String(++mountCounter),
|
|
39
40
|
name: componentName,
|
|
@@ -52,22 +53,37 @@ export async function mount(componentName: string, props?: MountProps): Promise<
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
if (!appLaunched) {
|
|
55
|
-
const launchArgs: Record<string, any> = {
|
|
56
|
+
const launchArgs: Record<string, any> = {detoxComponentName: componentName};
|
|
56
57
|
Object.entries(payload.props).forEach(([key, value]) => {
|
|
57
58
|
launchArgs[`detoxProp_${key}`] = value;
|
|
58
59
|
});
|
|
59
|
-
payload.spies.forEach(name => {
|
|
60
|
+
payload.spies.forEach((name) => {
|
|
60
61
|
launchArgs[`detoxSpy_${name}`] = true;
|
|
61
62
|
});
|
|
62
|
-
await device.launchApp({
|
|
63
|
+
await device.launchApp({newInstance: true, launchArgs});
|
|
63
64
|
appLaunched = true;
|
|
64
|
-
|
|
65
|
+
// Harness sets id '0' for the initial launch-args mount
|
|
66
|
+
try {
|
|
67
|
+
await waitFor(element(by.id('detox-mount-id')))
|
|
68
|
+
.toHaveText('0')
|
|
69
|
+
.withTimeout(5000);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
await assertNoRenderError(); // Throws with the actual error if one exists
|
|
72
|
+
throw e; // Re-throw original timeout if no render error found
|
|
73
|
+
}
|
|
65
74
|
await assertNoRenderError();
|
|
66
75
|
return;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
await element(by.id('detox-harness-control')).replaceText(JSON.stringify(payload));
|
|
70
|
-
|
|
79
|
+
try {
|
|
80
|
+
await waitFor(element(by.id('detox-mount-id')))
|
|
81
|
+
.toHaveText(payload.id)
|
|
82
|
+
.withTimeout(5000);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
await assertNoRenderError();
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
71
87
|
await assertNoRenderError();
|
|
72
88
|
}
|
|
73
89
|
|
package/src/test.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {mount, spy, expectSpy} from './mount';
|
|
2
|
+
export {debug} from './debug';
|