@nyby/detox-component-testing 1.4.2 → 1.5.1
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 +92 -47
- package/dist/ComponentHarness.d.ts.map +1 -1
- package/dist/ComponentHarness.js +11 -3
- package/dist/ComponentHarness.js.map +1 -1
- package/dist/configureHarness.d.ts +1 -1
- package/dist/configureHarness.d.ts.map +1 -1
- package/dist/configureHarness.js +3 -1
- package/dist/configureHarness.js.map +1 -1
- package/dist/debug.d.ts +8 -0
- package/dist/debug.d.ts.map +1 -1
- package/dist/debug.js +25 -31
- package/dist/debug.js.map +1 -1
- package/dist/environment.js +4 -32
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/mount.d.ts.map +1 -1
- package/dist/mount.js +13 -27
- package/dist/mount.js.map +1 -1
- package/package.json +1 -1
- package/src/ComponentHarness.tsx +15 -3
- package/src/configureHarness.ts +4 -2
- package/src/debug.ts +29 -32
- package/src/environment.js +4 -32
- package/src/index.ts +1 -2
- package/src/mount.ts +13 -27
- package/dist/DebugTree.d.ts +0 -20
- package/dist/DebugTree.d.ts.map +0 -1
- package/dist/DebugTree.js +0 -239
- package/dist/DebugTree.js.map +0 -1
- package/src/DebugTree.tsx +0 -280
package/src/configureHarness.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface WrapperProps {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface HarnessConfig {
|
|
9
|
-
wrapper
|
|
9
|
+
wrapper?: ComponentType<WrapperProps>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const DefaultWrapper = ({children}: WrapperProps) => children;
|
|
@@ -14,7 +14,9 @@ const DefaultWrapper = ({children}: WrapperProps) => children;
|
|
|
14
14
|
let globalWrapper: ComponentType<WrapperProps> | null = null;
|
|
15
15
|
|
|
16
16
|
export function configureHarness(config: HarnessConfig): void {
|
|
17
|
-
|
|
17
|
+
if (config.wrapper) {
|
|
18
|
+
globalWrapper = config.wrapper;
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export function getWrapper(): ComponentType<WrapperProps> {
|
package/src/debug.ts
CHANGED
|
@@ -2,47 +2,44 @@ import {mkdirSync, renameSync, writeFileSync} from 'fs';
|
|
|
2
2
|
import {join} from 'path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Capture a screenshot
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* import { debug } from '@nyby/detox-component-testing/test';
|
|
10
|
-
* await debug(); // artifacts/debug-1.png, debug-1-tree.json, debug-1-view.xml
|
|
11
|
-
* await debug('after-tap'); // artifacts/debug-after-tap.png, etc.
|
|
5
|
+
* Capture a screenshot and native view hierarchy to the given directory.
|
|
6
|
+
* Used by both the `debug()` helper and the custom test environment.
|
|
12
7
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
mkdirSync(
|
|
19
|
-
|
|
20
|
-
const screenshotPath = join(dir, `debug-${name}.png`);
|
|
21
|
-
const treePath = join(dir, `debug-${name}-tree.json`);
|
|
22
|
-
const viewPath = join(dir, `debug-${name}-view.xml`);
|
|
8
|
+
export async function captureArtifacts(
|
|
9
|
+
name: string,
|
|
10
|
+
outputDir: string,
|
|
11
|
+
deviceRef: {takeScreenshot: (n: string) => Promise<string>; generateViewHierarchyXml: () => Promise<string>},
|
|
12
|
+
) {
|
|
13
|
+
mkdirSync(outputDir, {recursive: true});
|
|
23
14
|
|
|
24
15
|
// Screenshot via Detox, then move to our artifacts dir
|
|
25
16
|
try {
|
|
26
|
-
const tempPath = await
|
|
17
|
+
const tempPath = await deviceRef.takeScreenshot(`debug-${name}`);
|
|
27
18
|
if (tempPath) {
|
|
28
|
-
renameSync(tempPath,
|
|
19
|
+
renameSync(tempPath, join(outputDir, `debug-${name}.png`));
|
|
29
20
|
}
|
|
30
21
|
} catch {}
|
|
31
22
|
|
|
32
|
-
// React component tree via DebugTree harness
|
|
33
|
-
try {
|
|
34
|
-
await element(by.id('debug-tree-control')).replaceText('dump');
|
|
35
|
-
await waitFor(element(by.id('debug-tree-output')))
|
|
36
|
-
.toExist()
|
|
37
|
-
.withTimeout(3000);
|
|
38
|
-
const attrs = await element(by.id('debug-tree-output')).getAttributes();
|
|
39
|
-
const tree = (attrs as any).text || (attrs as any).label || '[]';
|
|
40
|
-
writeFileSync(treePath, tree, 'utf8');
|
|
41
|
-
} catch {}
|
|
42
|
-
|
|
43
23
|
// Native view hierarchy
|
|
44
24
|
try {
|
|
45
|
-
const xml = await
|
|
46
|
-
writeFileSync(
|
|
25
|
+
const xml = await deviceRef.generateViewHierarchyXml();
|
|
26
|
+
writeFileSync(join(outputDir, `debug-${name}-view.xml`), xml, 'utf8');
|
|
47
27
|
} catch {}
|
|
48
28
|
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Capture a screenshot and native view hierarchy.
|
|
32
|
+
* Drop this anywhere in a test to inspect the current screen state.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* import { debug } from '@nyby/detox-component-testing/test';
|
|
36
|
+
* await debug(); // artifacts/debug-1.png, debug-1-view.xml
|
|
37
|
+
* await debug('after-tap'); // artifacts/debug-after-tap.png, etc.
|
|
38
|
+
*/
|
|
39
|
+
let counter = 0;
|
|
40
|
+
|
|
41
|
+
export async function debug(label?: string, outputDir?: string) {
|
|
42
|
+
const name = label || String(++counter);
|
|
43
|
+
const dir = outputDir || join(process.cwd(), 'artifacts');
|
|
44
|
+
await captureArtifacts(name, dir, device);
|
|
45
|
+
}
|
package/src/environment.js
CHANGED
|
@@ -1,45 +1,17 @@
|
|
|
1
1
|
const DetoxCircusEnvironment = require('detox/runners/jest/testEnvironment');
|
|
2
|
-
const {mkdirSync, writeFileSync} = require('fs');
|
|
3
2
|
const {join} = require('path');
|
|
3
|
+
const {captureArtifacts} = require('./debug');
|
|
4
4
|
|
|
5
5
|
class CustomDetoxEnvironment extends DetoxCircusEnvironment {
|
|
6
6
|
async handleTestEvent(event, state) {
|
|
7
7
|
await super.handleTestEvent(event, state);
|
|
8
8
|
|
|
9
9
|
if (event.name === 'test_done' && event.test.errors.length > 0) {
|
|
10
|
-
|
|
10
|
+
const safeName = event.test.name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
11
|
+
const outputDir = join(process.cwd(), 'artifacts');
|
|
12
|
+
await captureArtifacts(safeName, outputDir, this.global.device);
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
async _dumpDebugInfo(test) {
|
|
15
|
-
const outputDir = join(process.cwd(), 'artifacts');
|
|
16
|
-
const safeName = test.name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
17
|
-
|
|
18
|
-
mkdirSync(outputDir, {recursive: true});
|
|
19
|
-
|
|
20
|
-
// Screenshot (saved by Detox into its own artifacts folder)
|
|
21
|
-
try {
|
|
22
|
-
await this.global.device.takeScreenshot(`debug-${safeName}`);
|
|
23
|
-
} catch (_e) {}
|
|
24
|
-
|
|
25
|
-
// Component tree via DebugTree
|
|
26
|
-
try {
|
|
27
|
-
const {element, by, waitFor} = this.global;
|
|
28
|
-
|
|
29
|
-
await element(by.id('debug-tree-control')).replaceText('dump');
|
|
30
|
-
await waitFor(element(by.id('debug-tree-output'))).toExist().withTimeout(3000);
|
|
31
|
-
|
|
32
|
-
const attrs = await element(by.id('debug-tree-output')).getAttributes();
|
|
33
|
-
const tree = attrs.text || attrs.label || '[]';
|
|
34
|
-
writeFileSync(join(outputDir, `componenttree-${safeName}.json`), tree, 'utf8');
|
|
35
|
-
} catch (_e) {}
|
|
36
|
-
|
|
37
|
-
// Native view hierarchy
|
|
38
|
-
try {
|
|
39
|
-
const xml = await this.global.device.generateViewHierarchyXml();
|
|
40
|
-
writeFileSync(join(outputDir, `viewhierarchy-${safeName}.xml`), xml, 'utf8');
|
|
41
|
-
} catch (_e) {}
|
|
42
|
-
}
|
|
43
15
|
}
|
|
44
16
|
|
|
45
17
|
module.exports = CustomDetoxEnvironment;
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export {registerComponent} from './ComponentRegistry';
|
|
2
2
|
export {ComponentHarness} from './ComponentHarness';
|
|
3
|
-
export {configureHarness, WrapperProps} from './configureHarness';
|
|
4
|
-
export {DebugTree} from './DebugTree';
|
|
3
|
+
export {configureHarness, WrapperProps, HarnessConfig} from './configureHarness';
|
package/src/mount.ts
CHANGED
|
@@ -52,37 +52,23 @@ export async function mount(componentName: string, props?: MountProps): Promise<
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
74
|
-
await assertNoRenderError();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
await element(by.id('detox-harness-control')).replaceText(JSON.stringify(payload));
|
|
55
|
+
const launchArgs: Record<string, any> = {detoxComponentName: componentName};
|
|
56
|
+
Object.entries(payload.props).forEach(([key, value]) => {
|
|
57
|
+
launchArgs[`detoxProp_${key}`] = value;
|
|
58
|
+
});
|
|
59
|
+
payload.spies.forEach((name) => {
|
|
60
|
+
launchArgs[`detoxSpy_${name}`] = true;
|
|
61
|
+
});
|
|
62
|
+
await device.launchApp({newInstance: true, launchArgs});
|
|
63
|
+
appLaunched = true;
|
|
64
|
+
// Harness sets id '0' for the initial launch-args mount
|
|
79
65
|
try {
|
|
80
66
|
await waitFor(element(by.id('detox-mount-id')))
|
|
81
|
-
.toHaveText(
|
|
67
|
+
.toHaveText('0')
|
|
82
68
|
.withTimeout(5000);
|
|
83
69
|
} catch (e) {
|
|
84
|
-
await assertNoRenderError();
|
|
85
|
-
throw e;
|
|
70
|
+
await assertNoRenderError(); // Throws with the actual error if one exists
|
|
71
|
+
throw e; // Re-throw original timeout if no render error found
|
|
86
72
|
}
|
|
87
73
|
await assertNoRenderError();
|
|
88
74
|
}
|
package/dist/DebugTree.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export declare function captureTree(ref: any, usefulProps?: Set<string>, skipNames?: Set<string>, nativeDuplicates?: Set<string>): string;
|
|
3
|
-
export interface DebugTreeProps {
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
/** Props to include in tree output. Defaults to testID, accessibilityLabel, etc. */
|
|
6
|
-
usefulProps?: string[];
|
|
7
|
-
/** Component names to skip (internal wrappers that add noise). */
|
|
8
|
-
skipNames?: string[];
|
|
9
|
-
/** Native component names that duplicate their parent (e.g. RCTText inside Text). */
|
|
10
|
-
nativeDuplicates?: string[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Debug component that captures the React component tree on demand.
|
|
14
|
-
* Wrap your test content with this. Trigger via Detox:
|
|
15
|
-
*
|
|
16
|
-
* await element(by.id('debug-tree-control')).replaceText('dump');
|
|
17
|
-
* const attrs = await element(by.id('debug-tree-output')).getAttributes();
|
|
18
|
-
*/
|
|
19
|
-
export declare function DebugTree({ children, usefulProps, skipNames, nativeDuplicates }: DebugTreeProps): React.JSX.Element;
|
|
20
|
-
//# sourceMappingURL=DebugTree.d.ts.map
|
package/dist/DebugTree.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DebugTree.d.ts","sourceRoot":"","sources":["../src/DebugTree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAiN3D,wBAAgB,WAAW,CACzB,GAAG,EAAE,GAAG,EACR,WAAW,GAAE,GAAG,CAAC,MAAM,CAAwB,EAC/C,SAAS,GAAE,GAAG,CAAC,MAAM,CAAsB,EAC3C,gBAAgB,GAAE,GAAG,CAAC,MAAM,CAA6B,GACxD,MAAM,CAQR;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,EAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAC,EAAE,cAAc,qBAsC7F"}
|
package/dist/DebugTree.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.captureTree = captureTree;
|
|
37
|
-
exports.DebugTree = DebugTree;
|
|
38
|
-
const react_1 = __importStar(require("react"));
|
|
39
|
-
const react_native_1 = require("react-native");
|
|
40
|
-
// React fiber tags
|
|
41
|
-
const FunctionComponent = 0;
|
|
42
|
-
const ClassComponent = 1;
|
|
43
|
-
const HostComponent = 5;
|
|
44
|
-
const HostText = 6;
|
|
45
|
-
const ForwardRef = 11;
|
|
46
|
-
const MemoComponent = 14;
|
|
47
|
-
const SimpleMemoComponent = 15;
|
|
48
|
-
const DEFAULT_USEFUL_PROPS = new Set([
|
|
49
|
-
'testID',
|
|
50
|
-
'accessibilityLabel',
|
|
51
|
-
'accessibilityRole',
|
|
52
|
-
'title',
|
|
53
|
-
'name',
|
|
54
|
-
'variant',
|
|
55
|
-
'size',
|
|
56
|
-
'value',
|
|
57
|
-
'placeholder',
|
|
58
|
-
'disabled',
|
|
59
|
-
'selected',
|
|
60
|
-
'checked',
|
|
61
|
-
'visible',
|
|
62
|
-
]);
|
|
63
|
-
const DEFAULT_SKIP_NAMES = new Set([
|
|
64
|
-
'StaticContainer',
|
|
65
|
-
'EnsureSingleNavigator',
|
|
66
|
-
'PreventRemoveProvider',
|
|
67
|
-
'NavigationContent',
|
|
68
|
-
'NavigationStateContext',
|
|
69
|
-
'ScreenStackHeaderConfig',
|
|
70
|
-
'RenderErrorBoundary',
|
|
71
|
-
'DebugTree',
|
|
72
|
-
'PressabilityDebugView',
|
|
73
|
-
]);
|
|
74
|
-
const DEFAULT_NATIVE_DUPLICATES = new Set([
|
|
75
|
-
'RCTText',
|
|
76
|
-
'RCTView',
|
|
77
|
-
'RCTScrollView',
|
|
78
|
-
'RCTCustomScrollView',
|
|
79
|
-
'RCTScrollContentView',
|
|
80
|
-
'RCTSinglelineTextInputView',
|
|
81
|
-
'RCTUITextField',
|
|
82
|
-
]);
|
|
83
|
-
function findFiberFromRef(ref) {
|
|
84
|
-
if (!ref)
|
|
85
|
-
return null;
|
|
86
|
-
// React Native: __internalInstanceHandle is the fiber node
|
|
87
|
-
if (ref.__internalInstanceHandle) {
|
|
88
|
-
return ref.__internalInstanceHandle;
|
|
89
|
-
}
|
|
90
|
-
// React DEV builds
|
|
91
|
-
if (ref._internalFiberInstanceHandleDEV) {
|
|
92
|
-
return ref._internalFiberInstanceHandleDEV;
|
|
93
|
-
}
|
|
94
|
-
// React DOM style: __reactFiber$ key on the node
|
|
95
|
-
for (const key of Object.getOwnPropertyNames(ref)) {
|
|
96
|
-
if (key.startsWith('__reactFiber$')) {
|
|
97
|
-
return ref[key];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
function getComponentName(fiber) {
|
|
103
|
-
var _a, _b, _c, _d;
|
|
104
|
-
const { type, tag } = fiber;
|
|
105
|
-
if (tag === HostText)
|
|
106
|
-
return null;
|
|
107
|
-
if (tag === HostComponent) {
|
|
108
|
-
return typeof type === 'string' ? type : null;
|
|
109
|
-
}
|
|
110
|
-
if (tag === FunctionComponent || tag === ClassComponent || tag === SimpleMemoComponent) {
|
|
111
|
-
return (type === null || type === void 0 ? void 0 : type.displayName) || (type === null || type === void 0 ? void 0 : type.name) || null;
|
|
112
|
-
}
|
|
113
|
-
if (tag === ForwardRef) {
|
|
114
|
-
return (type === null || type === void 0 ? void 0 : type.displayName) || ((_a = type === null || type === void 0 ? void 0 : type.render) === null || _a === void 0 ? void 0 : _a.displayName) || ((_b = type === null || type === void 0 ? void 0 : type.render) === null || _b === void 0 ? void 0 : _b.name) || null;
|
|
115
|
-
}
|
|
116
|
-
if (tag === MemoComponent) {
|
|
117
|
-
return (type === null || type === void 0 ? void 0 : type.displayName) || ((_c = type === null || type === void 0 ? void 0 : type.type) === null || _c === void 0 ? void 0 : _c.displayName) || ((_d = type === null || type === void 0 ? void 0 : type.type) === null || _d === void 0 ? void 0 : _d.name) || null;
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
function isUserComponent(fiber) {
|
|
122
|
-
const { tag } = fiber;
|
|
123
|
-
return (tag === FunctionComponent ||
|
|
124
|
-
tag === ClassComponent ||
|
|
125
|
-
tag === ForwardRef ||
|
|
126
|
-
tag === MemoComponent ||
|
|
127
|
-
tag === SimpleMemoComponent);
|
|
128
|
-
}
|
|
129
|
-
function extractProps(fiber, usefulProps) {
|
|
130
|
-
const { memoizedProps } = fiber;
|
|
131
|
-
if (!memoizedProps)
|
|
132
|
-
return undefined;
|
|
133
|
-
const result = {};
|
|
134
|
-
let hasProps = false;
|
|
135
|
-
for (const key of Object.keys(memoizedProps)) {
|
|
136
|
-
if (key === 'children' || key === 'style')
|
|
137
|
-
continue;
|
|
138
|
-
if (usefulProps.has(key)) {
|
|
139
|
-
const val = memoizedProps[key];
|
|
140
|
-
if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {
|
|
141
|
-
result[key] = val;
|
|
142
|
-
hasProps = true;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (memoizedProps.onPress) {
|
|
147
|
-
result.onPress = true;
|
|
148
|
-
hasProps = true;
|
|
149
|
-
}
|
|
150
|
-
return hasProps ? result : undefined;
|
|
151
|
-
}
|
|
152
|
-
function getTextContent(fiber) {
|
|
153
|
-
var _a;
|
|
154
|
-
if (fiber.tag === HostText) {
|
|
155
|
-
return typeof fiber.memoizedProps === 'string' ? fiber.memoizedProps : undefined;
|
|
156
|
-
}
|
|
157
|
-
if (typeof ((_a = fiber.memoizedProps) === null || _a === void 0 ? void 0 : _a.children) === 'string') {
|
|
158
|
-
return fiber.memoizedProps.children;
|
|
159
|
-
}
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
function shouldShow(fiber, skipNames, nativeDuplicates) {
|
|
163
|
-
const name = getComponentName(fiber);
|
|
164
|
-
if (!name)
|
|
165
|
-
return false;
|
|
166
|
-
if (skipNames.has(name))
|
|
167
|
-
return false;
|
|
168
|
-
if (nativeDuplicates.has(name))
|
|
169
|
-
return false;
|
|
170
|
-
if (isUserComponent(fiber))
|
|
171
|
-
return true;
|
|
172
|
-
if (fiber.tag === HostComponent) {
|
|
173
|
-
const props = fiber.memoizedProps;
|
|
174
|
-
if ((props === null || props === void 0 ? void 0 : props.testID) || (props === null || props === void 0 ? void 0 : props.accessibilityLabel))
|
|
175
|
-
return true;
|
|
176
|
-
if (typeof (props === null || props === void 0 ? void 0 : props.children) === 'string')
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
function walkFiber(fiber, collect, usefulProps, skipNames, nativeDuplicates) {
|
|
182
|
-
if (!fiber)
|
|
183
|
-
return;
|
|
184
|
-
const name = getComponentName(fiber);
|
|
185
|
-
const show = fiber.tag !== HostText && shouldShow(fiber, skipNames, nativeDuplicates);
|
|
186
|
-
if (show && name) {
|
|
187
|
-
const node = { name };
|
|
188
|
-
const props = extractProps(fiber, usefulProps);
|
|
189
|
-
if (props)
|
|
190
|
-
node.props = props;
|
|
191
|
-
const text = getTextContent(fiber);
|
|
192
|
-
if (text)
|
|
193
|
-
node.text = text;
|
|
194
|
-
const childNodes = [];
|
|
195
|
-
walkFiber(fiber.child, childNodes, usefulProps, skipNames, nativeDuplicates);
|
|
196
|
-
if (childNodes.length > 0)
|
|
197
|
-
node.children = childNodes;
|
|
198
|
-
collect.push(node);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
walkFiber(fiber.child, collect, usefulProps, skipNames, nativeDuplicates);
|
|
202
|
-
}
|
|
203
|
-
walkFiber(fiber.sibling, collect, usefulProps, skipNames, nativeDuplicates);
|
|
204
|
-
}
|
|
205
|
-
function captureTree(ref, usefulProps = DEFAULT_USEFUL_PROPS, skipNames = DEFAULT_SKIP_NAMES, nativeDuplicates = DEFAULT_NATIVE_DUPLICATES) {
|
|
206
|
-
const fiber = findFiberFromRef(ref);
|
|
207
|
-
if (!fiber)
|
|
208
|
-
return '[]';
|
|
209
|
-
const tree = [];
|
|
210
|
-
walkFiber(fiber.child, tree, usefulProps, skipNames, nativeDuplicates);
|
|
211
|
-
return JSON.stringify(tree);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Debug component that captures the React component tree on demand.
|
|
215
|
-
* Wrap your test content with this. Trigger via Detox:
|
|
216
|
-
*
|
|
217
|
-
* await element(by.id('debug-tree-control')).replaceText('dump');
|
|
218
|
-
* const attrs = await element(by.id('debug-tree-output')).getAttributes();
|
|
219
|
-
*/
|
|
220
|
-
function DebugTree({ children, usefulProps, skipNames, nativeDuplicates }) {
|
|
221
|
-
const rootRef = (0, react_1.useRef)(null);
|
|
222
|
-
const [tree, setTree] = (0, react_1.useState)('');
|
|
223
|
-
const usefulPropsSet = usefulProps ? new Set(usefulProps) : DEFAULT_USEFUL_PROPS;
|
|
224
|
-
const skipNamesSet = skipNames ? new Set(skipNames) : DEFAULT_SKIP_NAMES;
|
|
225
|
-
const nativeDuplicatesSet = nativeDuplicates
|
|
226
|
-
? new Set(nativeDuplicates)
|
|
227
|
-
: DEFAULT_NATIVE_DUPLICATES;
|
|
228
|
-
const handleCommand = (0, react_1.useCallback)((text) => {
|
|
229
|
-
if (text === 'dump' && rootRef.current) {
|
|
230
|
-
const result = captureTree(rootRef.current, usefulPropsSet, skipNamesSet, nativeDuplicatesSet);
|
|
231
|
-
setTree(result);
|
|
232
|
-
}
|
|
233
|
-
}, [usefulPropsSet, skipNamesSet, nativeDuplicatesSet]);
|
|
234
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
235
|
-
react_1.default.createElement(react_native_1.TextInput, { testID: "debug-tree-control", onChangeText: handleCommand, style: { height: 1 } }),
|
|
236
|
-
react_1.default.createElement(react_native_1.View, { ref: rootRef, style: { flex: 1 }, collapsable: false }, children),
|
|
237
|
-
tree ? (react_1.default.createElement(react_native_1.Text, { testID: "debug-tree-output", style: { height: 1 } }, tree)) : null));
|
|
238
|
-
}
|
|
239
|
-
//# sourceMappingURL=DebugTree.js.map
|
package/dist/DebugTree.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DebugTree.js","sourceRoot":"","sources":["../src/DebugTree.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNA,kCAaC;AAmBD,8BAsCC;AAvRD,+CAA2D;AAC3D,+CAAmD;AAmBnD,mBAAmB;AACnB,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,QAAQ;IACR,oBAAoB;IACpB,mBAAmB;IACnB,OAAO;IACP,MAAM;IACN,S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