@nyby/detox-component-testing 1.6.0 → 1.6.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/dist/ComponentHarness.d.ts +1 -1
- package/dist/ComponentHarness.d.ts.map +1 -1
- package/dist/ComponentHarness.js +4 -4
- package/dist/ComponentHarness.js.map +1 -1
- package/dist/ComponentRegistry.d.ts +1 -2
- package/dist/ComponentRegistry.d.ts.map +1 -1
- package/dist/ComponentRegistry.js +2 -6
- package/dist/ComponentRegistry.js.map +1 -1
- package/dist/configureHarness.d.ts +1 -1
- package/dist/configureHarness.d.ts.map +1 -1
- package/dist/configureHarness.js.map +1 -1
- package/dist/debug.js +2 -2
- package/dist/debug.js.map +1 -1
- package/dist/environment.js +6 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mount.d.ts.map +1 -1
- package/dist/mount.js +8 -10
- package/dist/mount.js.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js.map +1 -1
- package/package.json +3 -2
- package/src/ComponentHarness.tsx +25 -40
- package/src/ComponentRegistry.ts +5 -12
- package/src/configureHarness.ts +2 -2
- package/src/debug.ts +5 -5
- package/src/detox-env.d.ts +1 -1
- package/src/environment.js +6 -6
- package/src/index.ts +3 -7
- package/src/mount.ts +14 -27
- package/src/test.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentHarness.d.ts","sourceRoot":"","sources":["../src/ComponentHarness.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ComponentHarness.d.ts","sourceRoot":"","sources":["../src/ComponentHarness.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8E,MAAM,OAAO,CAAC;AAuDnG,wBAAgB,gBAAgB,sBAkD/B"}
|
package/dist/ComponentHarness.js
CHANGED
|
@@ -55,8 +55,8 @@ class RenderErrorBoundary extends react_1.Component {
|
|
|
55
55
|
return this.props.children;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
const PROP_PREFIX =
|
|
59
|
-
const SPY_PREFIX =
|
|
58
|
+
const PROP_PREFIX = 'detoxProp_';
|
|
59
|
+
const SPY_PREFIX = 'detoxSpy_';
|
|
60
60
|
function parseLaunchArgs(args) {
|
|
61
61
|
const props = {};
|
|
62
62
|
const spies = [];
|
|
@@ -86,7 +86,7 @@ function ComponentHarness() {
|
|
|
86
86
|
else if (launchArgs.detoxComponentName) {
|
|
87
87
|
const { props, spies } = parseLaunchArgs(launchArgs);
|
|
88
88
|
activeMount = {
|
|
89
|
-
id:
|
|
89
|
+
id: '0',
|
|
90
90
|
name: launchArgs.detoxComponentName,
|
|
91
91
|
props,
|
|
92
92
|
spies,
|
|
@@ -94,7 +94,7 @@ function ComponentHarness() {
|
|
|
94
94
|
}
|
|
95
95
|
return (react_1.default.createElement(react_native_1.View, { style: { flex: 1 } },
|
|
96
96
|
react_1.default.createElement(react_native_1.TextInput, { testID: "detox-harness-control", onEndEditing: handleControl, style: {
|
|
97
|
-
position:
|
|
97
|
+
position: 'absolute',
|
|
98
98
|
bottom: 0,
|
|
99
99
|
left: 0,
|
|
100
100
|
right: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentHarness.js","sourceRoot":"","sources":["../src/ComponentHarness.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ComponentHarness.js","sourceRoot":"","sources":["../src/ComponentHarness.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,4CAkDC;AAzGD,+CAAmG;AACnG,+CAA+D;AAC/D,iFAA8D;AAC9D,2DAAiD;AACjD,yDAA8C;AAM9C,MAAM,mBAAoB,SAAQ,iBAAyD;IAA3F;;QACE,UAAK,GAAuB,EAAC,KAAK,EAAE,IA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AAC;QACJ,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,EAAC,GAAG,YAAY,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,EAAC,CAAC;IACrE,MAAM,OAAO,GAAG,IAAA,6BAAU,GAAE,CAAC;IAE7B,OAAO,CACL,8BAAC,OAAO,IAAC,UAAU,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;QACpC,8BAAC,mBAAI,IAAC,MAAM,EAAC,wBAAwB,EAAC,KAAK,EAAE,EAAC,IAAI,EAAE,CAAC,EAAC;YACpD,8BAAC,SAAS,OAAK,KAAK,GAAI;YACvB,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACtB,8BAAC,mBAAI,IAAC,GAAG,EAAE,IAAI;gBACb,8BAAC,mBAAI,IAAC,MAAM,EAAE,OAAO,IAAI,QAAQ,IAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAQ;gBACvE,8BAAC,mBAAI,IAAC,MAAM,EAAE,OAAO,IAAI,WAAW,IAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAQ,CAChF,CACR,CAAC,CACG,CACC,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType } from
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
2
|
export interface ComponentEntry<P = any> {
|
|
3
3
|
Component: ComponentType<P>;
|
|
4
4
|
defaultProps: Partial<P>;
|
|
@@ -6,5 +6,4 @@ export interface ComponentEntry<P = any> {
|
|
|
6
6
|
export declare function registerComponent<P>(name: string, Component: ComponentType<P>, defaultProps?: Partial<P>): void;
|
|
7
7
|
export declare function registerComponent<P>(Component: ComponentType<P>, defaultProps?: Partial<P>): void;
|
|
8
8
|
export declare function getComponent(name: string): ComponentEntry;
|
|
9
|
-
export declare function getAll(): Record<string, ComponentEntry>;
|
|
10
9
|
//# sourceMappingURL=ComponentRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentRegistry.d.ts","sourceRoot":"","sources":["../src/ComponentRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ComponentRegistry.d.ts","sourceRoot":"","sources":["../src/ComponentRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEpC,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC5B,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAC1B;AAID,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAC3B,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GACxB,IAAI,CAAC;AACR,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AA0BnG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAQzD"}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerComponent = registerComponent;
|
|
4
4
|
exports.getComponent = getComponent;
|
|
5
|
-
exports.getAll = getAll;
|
|
6
5
|
const registry = new Map();
|
|
7
6
|
function registerComponent(nameOrComponent, componentOrProps, defaultProps) {
|
|
8
|
-
if (typeof nameOrComponent ===
|
|
7
|
+
if (typeof nameOrComponent === 'string') {
|
|
9
8
|
registry.set(nameOrComponent, {
|
|
10
9
|
Component: componentOrProps,
|
|
11
10
|
defaultProps: (defaultProps || {}),
|
|
@@ -15,7 +14,7 @@ function registerComponent(nameOrComponent, componentOrProps, defaultProps) {
|
|
|
15
14
|
const Component = nameOrComponent;
|
|
16
15
|
const name = Component.displayName || Component.name;
|
|
17
16
|
if (!name) {
|
|
18
|
-
throw new Error(
|
|
17
|
+
throw new Error('[detox-component-testing] Component must have a name or displayName to register without an explicit name.');
|
|
19
18
|
}
|
|
20
19
|
registry.set(name, {
|
|
21
20
|
Component,
|
|
@@ -30,7 +29,4 @@ function getComponent(name) {
|
|
|
30
29
|
}
|
|
31
30
|
return entry;
|
|
32
31
|
}
|
|
33
|
-
function getAll() {
|
|
34
|
-
return Object.fromEntries(registry);
|
|
35
|
-
}
|
|
36
32
|
//# sourceMappingURL=ComponentRegistry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentRegistry.js","sourceRoot":"","sources":["../src/ComponentRegistry.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"ComponentRegistry.js","sourceRoot":"","sources":["../src/ComponentRegistry.ts"],"names":[],"mappings":";;AAeA,8CAuBC;AAED,oCAQC;AAzCD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;AAQnD,SAAgB,iBAAiB,CAC/B,eAA0C,EAC1C,gBAAgD,EAChD,YAAyB;IAEzB,IAAI,OAAO,eAAe,KAAK,QAAQ,EAAE,CAAC;QACxC,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE;YAC5B,SAAS,EAAE,gBAAoC;YAC/C,YAAY,EAAE,CAAC,YAAY,IAAI,EAAE,CAAe;SACjD,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,GAAG,eAAe,CAAC;QAClC,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI,CAAC;QACrD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,2GAA2G,CAC5G,CAAC;QACJ,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE;YACjB,SAAS;YACT,YAAY,EAAE,CAAE,gBAA+B,IAAI,EAAE,CAAe;SACrE,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,wCAAwC,IAAI,4DAA4D,CACzG,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureHarness.d.ts","sourceRoot":"","sources":["../src/configureHarness.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"configureHarness.d.ts","sourceRoot":"","sources":["../src/configureHarness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAE/C,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CACvC;AAMD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAI5D;AAED,wBAAgB,UAAU,IAAI,aAAa,CAAC,YAAY,CAAC,CAExD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureHarness.js","sourceRoot":"","sources":["../src/configureHarness.ts"],"names":[],"mappings":";;AAeA,4CAIC;AAED,gCAEC;AAZD,MAAM,cAAc,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"configureHarness.js","sourceRoot":"","sources":["../src/configureHarness.ts"],"names":[],"mappings":";;AAeA,4CAIC;AAED,gCAEC;AAZD,MAAM,cAAc,GAAG,CAAC,EAAC,QAAQ,EAAe,EAAE,EAAE,CAAC,QAAQ,CAAC;AAE9D,IAAI,aAAa,GAAuC,IAAI,CAAC;AAE7D,SAAgB,gBAAgB,CAAC,MAAqB;IACpD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;IACjC,CAAC;AACH,CAAC;AAED,SAAgB,UAAU;IACxB,OAAO,aAAa,IAAI,cAAc,CAAC;AACzC,CAAC"}
|
package/dist/debug.js
CHANGED
|
@@ -21,7 +21,7 @@ async function captureArtifacts(name, outputDir, deviceRef) {
|
|
|
21
21
|
// Native view hierarchy
|
|
22
22
|
try {
|
|
23
23
|
const xml = await deviceRef.generateViewHierarchyXml();
|
|
24
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(outputDir, `debug-${name}-view.xml`), xml,
|
|
24
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(outputDir, `debug-${name}-view.xml`), xml, 'utf8');
|
|
25
25
|
}
|
|
26
26
|
catch { }
|
|
27
27
|
}
|
|
@@ -37,7 +37,7 @@ async function captureArtifacts(name, outputDir, deviceRef) {
|
|
|
37
37
|
let counter = 0;
|
|
38
38
|
async function debug(label, outputDir) {
|
|
39
39
|
const name = label || String(++counter);
|
|
40
|
-
const dir = outputDir || (0, path_1.join)(process.cwd(),
|
|
40
|
+
const dir = outputDir || (0, path_1.join)(process.cwd(), 'artifacts');
|
|
41
41
|
await captureArtifacts(name, dir, device);
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=debug.js.map
|
package/dist/debug.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":";;AAOA,4CAuBC;AAaD,sB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package/dist/environment.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const DetoxCircusEnvironment = require(
|
|
2
|
-
const {
|
|
3
|
-
const {
|
|
1
|
+
const DetoxCircusEnvironment = require('detox/runners/jest/testEnvironment');
|
|
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
|
-
if (event.name ===
|
|
10
|
-
const safeName = event.test.name.replace(/[^a-zA-Z0-9_-]/g,
|
|
11
|
-
const outputDir = join(process.cwd(),
|
|
9
|
+
if (event.name === 'test_done' && event.test.errors.length > 0) {
|
|
10
|
+
const safeName = event.test.name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
11
|
+
const outputDir = join(process.cwd(), 'artifacts');
|
|
12
12
|
await captureArtifacts(safeName, outputDir, this.global.device);
|
|
13
13
|
}
|
|
14
14
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { registerComponent } from
|
|
2
|
-
export { ComponentHarness } from
|
|
3
|
-
export { configureHarness, WrapperProps, HarnessConfig
|
|
1
|
+
export { registerComponent } from './ComponentRegistry';
|
|
2
|
+
export { ComponentHarness } from './ComponentHarness';
|
|
3
|
+
export { configureHarness, WrapperProps, HarnessConfig } from './configureHarness';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AAA9C,sHAAA,iBAAiB,OAAA;AACzB,uDAAoD;AAA5C,oHAAA,gBAAgB,OAAA;AACxB,uDAAiF;AAAzE,oHAAA,gBAAgB,OAAA"}
|
package/dist/mount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,cAAc,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,cAAc,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAMD,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAE3C;AAED,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;AAgBxE,wBAAsB,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAoCpF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAetD"}
|
package/dist/mount.js
CHANGED
|
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.spy = spy;
|
|
4
4
|
exports.mount = mount;
|
|
5
5
|
exports.expectSpy = expectSpy;
|
|
6
|
-
const SPY_MARKER =
|
|
6
|
+
const SPY_MARKER = '__detoxSpy__';
|
|
7
7
|
let mountCounter = 0;
|
|
8
|
-
let appLaunched = false;
|
|
9
8
|
function spy(name) {
|
|
10
9
|
return { [SPY_MARKER]: true, name };
|
|
11
10
|
}
|
|
12
11
|
async function assertNoRenderError() {
|
|
13
12
|
try {
|
|
14
|
-
await waitFor(element(by.id(
|
|
13
|
+
await waitFor(element(by.id('detox-render-error')))
|
|
15
14
|
.toExist()
|
|
16
15
|
.withTimeout(500);
|
|
17
16
|
}
|
|
@@ -19,8 +18,8 @@ async function assertNoRenderError() {
|
|
|
19
18
|
return; // Element not found — no render error, all good
|
|
20
19
|
}
|
|
21
20
|
// Element exists — read the error message and throw
|
|
22
|
-
const attrs = (await element(by.id(
|
|
23
|
-
const message = attrs.text || attrs.label ||
|
|
21
|
+
const attrs = (await element(by.id('detox-render-error-message')).getAttributes());
|
|
22
|
+
const message = attrs.text || attrs.label || 'Unknown render error';
|
|
24
23
|
throw new Error(`Component render error: ${message}`);
|
|
25
24
|
}
|
|
26
25
|
async function mount(componentName, props) {
|
|
@@ -32,7 +31,7 @@ async function mount(componentName, props) {
|
|
|
32
31
|
};
|
|
33
32
|
if (props) {
|
|
34
33
|
Object.entries(props).forEach(([key, value]) => {
|
|
35
|
-
if (value && typeof value ===
|
|
34
|
+
if (value && typeof value === 'object' && SPY_MARKER in value) {
|
|
36
35
|
payload.spies.push(key);
|
|
37
36
|
}
|
|
38
37
|
else {
|
|
@@ -48,11 +47,10 @@ async function mount(componentName, props) {
|
|
|
48
47
|
launchArgs[`detoxSpy_${name}`] = true;
|
|
49
48
|
});
|
|
50
49
|
await device.launchApp({ newInstance: true, launchArgs });
|
|
51
|
-
appLaunched = true;
|
|
52
50
|
// Harness sets id '0' for the initial launch-args mount
|
|
53
51
|
try {
|
|
54
|
-
await waitFor(element(by.id(
|
|
55
|
-
.toHaveText(
|
|
52
|
+
await waitFor(element(by.id('detox-mount-id')))
|
|
53
|
+
.toHaveText('0')
|
|
56
54
|
.withTimeout(5000);
|
|
57
55
|
}
|
|
58
56
|
catch (e) {
|
|
@@ -67,7 +65,7 @@ function expectSpy(name) {
|
|
|
67
65
|
const getExpect = () => expect;
|
|
68
66
|
return {
|
|
69
67
|
async toHaveBeenCalled() {
|
|
70
|
-
await getExpect()(element(by.id(`spy-${name}-count`))).not.toHaveText(
|
|
68
|
+
await getExpect()(element(by.id(`spy-${name}-count`))).not.toHaveText('0');
|
|
71
69
|
},
|
|
72
70
|
async toHaveBeenCalledTimes(n) {
|
|
73
71
|
await getExpect()(element(by.id(`spy-${name}-count`))).toHaveText(String(n));
|
package/dist/mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":";;AAeA,kBAEC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,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC7E,CAAC;QACD,KAAK,CAAC,qBAAqB,CAAC,CAAS;YACnC,MAAM,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,CAAC;QACD,KAAK,CAAC,cAAc,CAAC,GAAG,IAAW;YACjC,MAAM,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7F,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/test.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { mount, spy, expectSpy } from
|
|
2
|
-
export { debug } from
|
|
1
|
+
export { mount, spy, expectSpy } from './mount';
|
|
2
|
+
export { debug } from './debug';
|
|
3
3
|
//# sourceMappingURL=test.d.ts.map
|
package/dist/test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC"}
|
package/dist/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;AAAA,iCAA8C;AAAtC,8FAAA,KAAK,OAAA;AAAE,4FAAA,GAAG,OAAA;AAAE,kGAAA,SAAS,OAAA;AAC7B,iCAA8B;AAAtB,8FAAA,KAAK,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyby/detox-component-testing",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Component testing support for Detox and React Native",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,5 +47,6 @@
|
|
|
47
47
|
"@types/react-native": "^0.72.8",
|
|
48
48
|
"prettier": "^3.8.1",
|
|
49
49
|
"typescript": "^5.9.3"
|
|
50
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
51
52
|
}
|
package/src/ComponentHarness.tsx
CHANGED
|
@@ -1,36 +1,25 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ReactNode,
|
|
7
|
-
} from "react";
|
|
8
|
-
import { View, Text, TextInput, ScrollView } from "react-native";
|
|
9
|
-
import { LaunchArguments } from "react-native-launch-arguments";
|
|
10
|
-
import { getComponent } from "./ComponentRegistry";
|
|
11
|
-
import { getWrapper } from "./configureHarness";
|
|
1
|
+
import React, {Component as ReactComponent, useState, useRef, useCallback, ReactNode} from 'react';
|
|
2
|
+
import {View, Text, TextInput, ScrollView} from 'react-native';
|
|
3
|
+
import {LaunchArguments} from 'react-native-launch-arguments';
|
|
4
|
+
import {getComponent} from './ComponentRegistry';
|
|
5
|
+
import {getWrapper} from './configureHarness';
|
|
12
6
|
|
|
13
7
|
interface ErrorBoundaryState {
|
|
14
8
|
error: Error | null;
|
|
15
9
|
}
|
|
16
10
|
|
|
17
|
-
class RenderErrorBoundary extends ReactComponent<
|
|
18
|
-
{
|
|
19
|
-
ErrorBoundaryState
|
|
20
|
-
> {
|
|
21
|
-
state: ErrorBoundaryState = { error: null };
|
|
11
|
+
class RenderErrorBoundary extends ReactComponent<{children: ReactNode}, ErrorBoundaryState> {
|
|
12
|
+
state: ErrorBoundaryState = {error: null};
|
|
22
13
|
|
|
23
14
|
static getDerivedStateFromError(error: Error) {
|
|
24
|
-
return {
|
|
15
|
+
return {error};
|
|
25
16
|
}
|
|
26
17
|
|
|
27
18
|
render() {
|
|
28
19
|
if (this.state.error) {
|
|
29
20
|
return (
|
|
30
21
|
<ScrollView testID="detox-render-error">
|
|
31
|
-
<Text testID="detox-render-error-message">
|
|
32
|
-
{this.state.error.message}
|
|
33
|
-
</Text>
|
|
22
|
+
<Text testID="detox-render-error-message">{this.state.error.message}</Text>
|
|
34
23
|
</ScrollView>
|
|
35
24
|
);
|
|
36
25
|
}
|
|
@@ -38,8 +27,8 @@ class RenderErrorBoundary extends ReactComponent<
|
|
|
38
27
|
}
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
const PROP_PREFIX =
|
|
42
|
-
const SPY_PREFIX =
|
|
30
|
+
const PROP_PREFIX = 'detoxProp_';
|
|
31
|
+
const SPY_PREFIX = 'detoxSpy_';
|
|
43
32
|
|
|
44
33
|
interface MountPayload {
|
|
45
34
|
id: string;
|
|
@@ -61,14 +50,14 @@ function parseLaunchArgs(args: Record<string, any>): {
|
|
|
61
50
|
spies.push(key.slice(SPY_PREFIX.length));
|
|
62
51
|
}
|
|
63
52
|
});
|
|
64
|
-
return {
|
|
53
|
+
return {props, spies};
|
|
65
54
|
}
|
|
66
55
|
|
|
67
56
|
export function ComponentHarness() {
|
|
68
57
|
const launchArgs = LaunchArguments.value() as Record<string, any>;
|
|
69
58
|
const [mountPayload, setMountPayload] = useState<MountPayload | null>(null);
|
|
70
59
|
|
|
71
|
-
const handleControl = useCallback((e: {
|
|
60
|
+
const handleControl = useCallback((e: {nativeEvent: {text: string}}) => {
|
|
72
61
|
try {
|
|
73
62
|
setMountPayload(JSON.parse(e.nativeEvent.text));
|
|
74
63
|
} catch (_e) {}
|
|
@@ -78,9 +67,9 @@ export function ComponentHarness() {
|
|
|
78
67
|
if (mountPayload) {
|
|
79
68
|
activeMount = mountPayload;
|
|
80
69
|
} else if (launchArgs.detoxComponentName) {
|
|
81
|
-
const {
|
|
70
|
+
const {props, spies} = parseLaunchArgs(launchArgs);
|
|
82
71
|
activeMount = {
|
|
83
|
-
id:
|
|
72
|
+
id: '0',
|
|
84
73
|
name: launchArgs.detoxComponentName as string,
|
|
85
74
|
props,
|
|
86
75
|
spies,
|
|
@@ -88,12 +77,12 @@ export function ComponentHarness() {
|
|
|
88
77
|
}
|
|
89
78
|
|
|
90
79
|
return (
|
|
91
|
-
<View style={{
|
|
80
|
+
<View style={{flex: 1}}>
|
|
92
81
|
<TextInput
|
|
93
82
|
testID="detox-harness-control"
|
|
94
83
|
onEndEditing={handleControl}
|
|
95
84
|
style={{
|
|
96
|
-
position:
|
|
85
|
+
position: 'absolute',
|
|
97
86
|
bottom: 0,
|
|
98
87
|
left: 0,
|
|
99
88
|
right: 0,
|
|
@@ -104,7 +93,7 @@ export function ComponentHarness() {
|
|
|
104
93
|
/>
|
|
105
94
|
{activeMount && (
|
|
106
95
|
<>
|
|
107
|
-
<Text testID="detox-mount-id" style={{
|
|
96
|
+
<Text testID="detox-mount-id" style={{height: 1}}>
|
|
108
97
|
{activeMount.id}
|
|
109
98
|
</Text>
|
|
110
99
|
<RenderErrorBoundary>
|
|
@@ -121,13 +110,13 @@ interface SpyData {
|
|
|
121
110
|
lastArgs: any[];
|
|
122
111
|
}
|
|
123
112
|
|
|
124
|
-
function ComponentRenderer({
|
|
125
|
-
const {
|
|
113
|
+
function ComponentRenderer({mount}: {mount: MountPayload}) {
|
|
114
|
+
const {Component, defaultProps} = getComponent(mount.name);
|
|
126
115
|
const spyNames = mount.spies || [];
|
|
127
116
|
|
|
128
117
|
const initialData: Record<string, SpyData> = {};
|
|
129
118
|
spyNames.forEach((name) => {
|
|
130
|
-
initialData[name] = {
|
|
119
|
+
initialData[name] = {count: 0, lastArgs: []};
|
|
131
120
|
});
|
|
132
121
|
|
|
133
122
|
const [spyData, setSpyData] = useState(initialData);
|
|
@@ -149,21 +138,17 @@ function ComponentRenderer({ mount }: { mount: MountPayload }) {
|
|
|
149
138
|
spyProps[name] = spyFnsRef.current[name];
|
|
150
139
|
});
|
|
151
140
|
|
|
152
|
-
const props = {
|
|
141
|
+
const props = {...defaultProps, ...(mount.props || {}), ...spyProps};
|
|
153
142
|
const Wrapper = getWrapper();
|
|
154
143
|
|
|
155
144
|
return (
|
|
156
145
|
<Wrapper launchArgs={mount.props || {}}>
|
|
157
|
-
<View testID="component-harness-root" style={{
|
|
146
|
+
<View testID="component-harness-root" style={{flex: 1}}>
|
|
158
147
|
<Component {...props} />
|
|
159
148
|
{spyNames.map((name) => (
|
|
160
149
|
<View key={name}>
|
|
161
|
-
<Text testID={`spy-${name}-count`}>
|
|
162
|
-
|
|
163
|
-
</Text>
|
|
164
|
-
<Text testID={`spy-${name}-lastArgs`}>
|
|
165
|
-
{JSON.stringify(spyData[name].lastArgs)}
|
|
166
|
-
</Text>
|
|
150
|
+
<Text testID={`spy-${name}-count`}>{String(spyData[name].count)}</Text>
|
|
151
|
+
<Text testID={`spy-${name}-lastArgs`}>{JSON.stringify(spyData[name].lastArgs)}</Text>
|
|
167
152
|
</View>
|
|
168
153
|
))}
|
|
169
154
|
</View>
|
package/src/ComponentRegistry.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ComponentType} from 'react';
|
|
2
2
|
|
|
3
3
|
export interface ComponentEntry<P = any> {
|
|
4
4
|
Component: ComponentType<P>;
|
|
@@ -12,16 +12,13 @@ export function registerComponent<P>(
|
|
|
12
12
|
Component: ComponentType<P>,
|
|
13
13
|
defaultProps?: Partial<P>,
|
|
14
14
|
): void;
|
|
15
|
-
export function registerComponent<P>(
|
|
16
|
-
Component: ComponentType<P>,
|
|
17
|
-
defaultProps?: Partial<P>,
|
|
18
|
-
): void;
|
|
15
|
+
export function registerComponent<P>(Component: ComponentType<P>, defaultProps?: Partial<P>): void;
|
|
19
16
|
export function registerComponent<P>(
|
|
20
17
|
nameOrComponent: string | ComponentType<P>,
|
|
21
18
|
componentOrProps?: ComponentType<P> | Partial<P>,
|
|
22
19
|
defaultProps?: Partial<P>,
|
|
23
20
|
): void {
|
|
24
|
-
if (typeof nameOrComponent ===
|
|
21
|
+
if (typeof nameOrComponent === 'string') {
|
|
25
22
|
registry.set(nameOrComponent, {
|
|
26
23
|
Component: componentOrProps as ComponentType<P>,
|
|
27
24
|
defaultProps: (defaultProps || {}) as Partial<P>,
|
|
@@ -31,7 +28,7 @@ export function registerComponent<P>(
|
|
|
31
28
|
const name = Component.displayName || Component.name;
|
|
32
29
|
if (!name) {
|
|
33
30
|
throw new Error(
|
|
34
|
-
|
|
31
|
+
'[detox-component-testing] Component must have a name or displayName to register without an explicit name.',
|
|
35
32
|
);
|
|
36
33
|
}
|
|
37
34
|
registry.set(name, {
|
|
@@ -49,8 +46,4 @@ export function getComponent(name: string): ComponentEntry {
|
|
|
49
46
|
);
|
|
50
47
|
}
|
|
51
48
|
return entry;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function getAll(): Record<string, ComponentEntry> {
|
|
55
|
-
return Object.fromEntries(registry);
|
|
56
|
-
}
|
|
49
|
+
}
|
package/src/configureHarness.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ComponentType, ReactNode} from 'react';
|
|
2
2
|
|
|
3
3
|
export interface WrapperProps {
|
|
4
4
|
children: ReactNode;
|
|
@@ -9,7 +9,7 @@ export interface HarnessConfig {
|
|
|
9
9
|
wrapper?: ComponentType<WrapperProps>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const DefaultWrapper = ({
|
|
12
|
+
const DefaultWrapper = ({children}: WrapperProps) => children;
|
|
13
13
|
|
|
14
14
|
let globalWrapper: ComponentType<WrapperProps> | null = null;
|
|
15
15
|
|
package/src/debug.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {mkdirSync, renameSync, writeFileSync} from 'fs';
|
|
2
|
+
import {join} from 'path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Capture a screenshot and native view hierarchy to the given directory.
|
|
@@ -13,7 +13,7 @@ export async function captureArtifacts(
|
|
|
13
13
|
generateViewHierarchyXml: () => Promise<string>;
|
|
14
14
|
},
|
|
15
15
|
) {
|
|
16
|
-
mkdirSync(outputDir, {
|
|
16
|
+
mkdirSync(outputDir, {recursive: true});
|
|
17
17
|
|
|
18
18
|
// Screenshot via Detox, then move to our artifacts dir
|
|
19
19
|
try {
|
|
@@ -26,7 +26,7 @@ export async function captureArtifacts(
|
|
|
26
26
|
// Native view hierarchy
|
|
27
27
|
try {
|
|
28
28
|
const xml = await deviceRef.generateViewHierarchyXml();
|
|
29
|
-
writeFileSync(join(outputDir, `debug-${name}-view.xml`), xml,
|
|
29
|
+
writeFileSync(join(outputDir, `debug-${name}-view.xml`), xml, 'utf8');
|
|
30
30
|
} catch {}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -43,6 +43,6 @@ let counter = 0;
|
|
|
43
43
|
|
|
44
44
|
export async function debug(label?: string, outputDir?: string) {
|
|
45
45
|
const name = label || String(++counter);
|
|
46
|
-
const dir = outputDir || join(process.cwd(),
|
|
46
|
+
const dir = outputDir || join(process.cwd(), 'artifacts');
|
|
47
47
|
await captureArtifacts(name, dir, device);
|
|
48
48
|
}
|
package/src/detox-env.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ declare const device: {
|
|
|
5
5
|
generateViewHierarchyXml(): Promise<string>;
|
|
6
6
|
};
|
|
7
7
|
declare function element(matcher: any): any;
|
|
8
|
-
declare const by: {
|
|
8
|
+
declare const by: {id(id: string): any};
|
|
9
9
|
declare function waitFor(e: any): any;
|
|
10
10
|
declare function expect(e: any): any;
|
package/src/environment.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const DetoxCircusEnvironment = require(
|
|
2
|
-
const {
|
|
3
|
-
const {
|
|
1
|
+
const DetoxCircusEnvironment = require('detox/runners/jest/testEnvironment');
|
|
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
|
-
if (event.name ===
|
|
10
|
-
const safeName = event.test.name.replace(/[^a-zA-Z0-9_-]/g,
|
|
11
|
-
const outputDir = join(process.cwd(),
|
|
9
|
+
if (event.name === 'test_done' && event.test.errors.length > 0) {
|
|
10
|
+
const safeName = event.test.name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
11
|
+
const outputDir = join(process.cwd(), 'artifacts');
|
|
12
12
|
await captureArtifacts(safeName, outputDir, this.global.device);
|
|
13
13
|
}
|
|
14
14
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
configureHarness,
|
|
5
|
-
WrapperProps,
|
|
6
|
-
HarnessConfig,
|
|
7
|
-
} from "./configureHarness";
|
|
1
|
+
export {registerComponent} from './ComponentRegistry';
|
|
2
|
+
export {ComponentHarness} from './ComponentHarness';
|
|
3
|
+
export {configureHarness, WrapperProps, HarnessConfig} from './configureHarness';
|
package/src/mount.ts
CHANGED
|
@@ -9,37 +9,31 @@ export interface SpyExpectation {
|
|
|
9
9
|
lastCalledWith(...args: any[]): Promise<void>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const SPY_MARKER =
|
|
12
|
+
const SPY_MARKER = '__detoxSpy__' as const;
|
|
13
13
|
|
|
14
14
|
let mountCounter = 0;
|
|
15
|
-
let appLaunched = false;
|
|
16
15
|
|
|
17
16
|
export function spy(name: string): SpyMarker {
|
|
18
|
-
return {
|
|
17
|
+
return {[SPY_MARKER]: true, name};
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
type MountProps = Record<string, string | number | boolean | SpyMarker>;
|
|
22
21
|
|
|
23
22
|
async function assertNoRenderError(): Promise<void> {
|
|
24
23
|
try {
|
|
25
|
-
await waitFor(element(by.id(
|
|
24
|
+
await waitFor(element(by.id('detox-render-error')))
|
|
26
25
|
.toExist()
|
|
27
26
|
.withTimeout(500);
|
|
28
27
|
} catch {
|
|
29
28
|
return; // Element not found — no render error, all good
|
|
30
29
|
}
|
|
31
30
|
// Element exists — read the error message and throw
|
|
32
|
-
const attrs = (await element(
|
|
33
|
-
|
|
34
|
-
).getAttributes()) as any;
|
|
35
|
-
const message = attrs.text || attrs.label || "Unknown render error";
|
|
31
|
+
const attrs = (await element(by.id('detox-render-error-message')).getAttributes()) as any;
|
|
32
|
+
const message = attrs.text || attrs.label || 'Unknown render error';
|
|
36
33
|
throw new Error(`Component render error: ${message}`);
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
export async function mount(
|
|
40
|
-
componentName: string,
|
|
41
|
-
props?: MountProps,
|
|
42
|
-
): Promise<void> {
|
|
36
|
+
export async function mount(componentName: string, props?: MountProps): Promise<void> {
|
|
43
37
|
const payload = {
|
|
44
38
|
id: String(++mountCounter),
|
|
45
39
|
name: componentName,
|
|
@@ -49,7 +43,7 @@ export async function mount(
|
|
|
49
43
|
|
|
50
44
|
if (props) {
|
|
51
45
|
Object.entries(props).forEach(([key, value]) => {
|
|
52
|
-
if (value && typeof value ===
|
|
46
|
+
if (value && typeof value === 'object' && SPY_MARKER in value) {
|
|
53
47
|
payload.spies.push(key);
|
|
54
48
|
} else {
|
|
55
49
|
payload.props[key] = value;
|
|
@@ -57,19 +51,18 @@ export async function mount(
|
|
|
57
51
|
});
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
const launchArgs: Record<string, any> = {
|
|
54
|
+
const launchArgs: Record<string, any> = {detoxComponentName: componentName};
|
|
61
55
|
Object.entries(payload.props).forEach(([key, value]) => {
|
|
62
56
|
launchArgs[`detoxProp_${key}`] = value;
|
|
63
57
|
});
|
|
64
58
|
payload.spies.forEach((name) => {
|
|
65
59
|
launchArgs[`detoxSpy_${name}`] = true;
|
|
66
60
|
});
|
|
67
|
-
await device.launchApp({
|
|
68
|
-
appLaunched = true;
|
|
61
|
+
await device.launchApp({newInstance: true, launchArgs});
|
|
69
62
|
// Harness sets id '0' for the initial launch-args mount
|
|
70
63
|
try {
|
|
71
|
-
await waitFor(element(by.id(
|
|
72
|
-
.toHaveText(
|
|
64
|
+
await waitFor(element(by.id('detox-mount-id')))
|
|
65
|
+
.toHaveText('0')
|
|
73
66
|
.withTimeout(5000);
|
|
74
67
|
} catch (e) {
|
|
75
68
|
await assertNoRenderError(); // Throws with the actual error if one exists
|
|
@@ -84,19 +77,13 @@ export function expectSpy(name: string): SpyExpectation {
|
|
|
84
77
|
const getExpect = () => expect as unknown as (e: any) => any;
|
|
85
78
|
return {
|
|
86
79
|
async toHaveBeenCalled() {
|
|
87
|
-
await getExpect()(element(by.id(`spy-${name}-count`))).not.toHaveText(
|
|
88
|
-
"0",
|
|
89
|
-
);
|
|
80
|
+
await getExpect()(element(by.id(`spy-${name}-count`))).not.toHaveText('0');
|
|
90
81
|
},
|
|
91
82
|
async toHaveBeenCalledTimes(n: number) {
|
|
92
|
-
await getExpect()(element(by.id(`spy-${name}-count`))).toHaveText(
|
|
93
|
-
String(n),
|
|
94
|
-
);
|
|
83
|
+
await getExpect()(element(by.id(`spy-${name}-count`))).toHaveText(String(n));
|
|
95
84
|
},
|
|
96
85
|
async lastCalledWith(...args: any[]) {
|
|
97
|
-
await getExpect()(element(by.id(`spy-${name}-lastArgs`))).toHaveText(
|
|
98
|
-
JSON.stringify(args),
|
|
99
|
-
);
|
|
86
|
+
await getExpect()(element(by.id(`spy-${name}-lastArgs`))).toHaveText(JSON.stringify(args));
|
|
100
87
|
},
|
|
101
88
|
};
|
|
102
89
|
}
|
package/src/test.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export {mount, spy, expectSpy} from './mount';
|
|
2
|
+
export {debug} from './debug';
|