@nyby/detox-component-testing 1.6.1 → 1.7.0

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 CHANGED
@@ -121,7 +121,7 @@ module.exports = {
121
121
  maxWorkers: 1,
122
122
  globalSetup: 'detox/runners/jest/globalSetup',
123
123
  globalTeardown: 'detox/runners/jest/globalTeardown',
124
- testEnvironment: '@nyby/detox-component-testing/environment',
124
+ testEnvironment: 'detox/runners/jest/testEnvironment',
125
125
  setupFilesAfterEnv: ['./setup.ts'],
126
126
  testRunner: 'jest-circus/runner',
127
127
  testTimeout: 120000,
@@ -237,47 +237,6 @@ Returns an assertion object for a spy:
237
237
  - `.toHaveBeenCalledTimes(n)` — spy was called exactly `n` times
238
238
  - `.lastCalledWith(...args)` — the last call's arguments match
239
239
 
240
- #### `debug(label?, outputDir?)`
241
-
242
- Capture a screenshot and native view hierarchy for the current screen state. Useful for debugging test failures or inspecting what's on screen at any point in a test.
243
-
244
- ```ts
245
- import {mount, debug} from '@nyby/detox-component-testing/test';
246
-
247
- it('renders the event screen', async () => {
248
- await mount('EventScreen', {eventId: 'event_1'});
249
- await debug('after-mount'); // writes to artifacts/debug-after-mount.{png,xml}
250
- });
251
- ```
252
-
253
- Each call writes up to two files to the output directory (defaults to `<cwd>/artifacts`):
254
-
255
- - `debug-<label>.png` — screenshot
256
- - `debug-<label>-view.xml` — native view hierarchy
257
-
258
- If no label is provided, calls are numbered automatically (`1`, `2`, `3`, ...).
259
-
260
- ### Debugging
261
-
262
- #### Custom test environment
263
-
264
- A Detox Jest environment that automatically captures debug artifacts when a test fails. Use it instead of the default Detox environment:
265
-
266
- ```js
267
- // jest.config.js
268
- module.exports = {
269
- testEnvironment: '@nyby/detox-component-testing/environment',
270
- // ...
271
- };
272
- ```
273
-
274
- On test failure, it captures:
275
-
276
- - A screenshot
277
- - The native view hierarchy
278
-
279
- All artifacts are written to `<cwd>/artifacts/`.
280
-
281
240
  ## Limitations
282
241
 
283
242
  - **No JSX in tests** — Tests run in Node.js, not the React Native runtime. You cannot import components or use JSX in test files. Reference components by their registered name string.
package/dist/test.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { mount, spy, expectSpy } from './mount';
2
- export { debug } from './debug';
3
2
  //# sourceMappingURL=test.d.ts.map
@@ -1 +1 @@
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"}
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"}
package/dist/test.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debug = exports.expectSpy = exports.spy = exports.mount = void 0;
3
+ exports.expectSpy = exports.spy = exports.mount = void 0;
4
4
  var mount_1 = require("./mount");
5
5
  Object.defineProperty(exports, "mount", { enumerable: true, get: function () { return mount_1.mount; } });
6
6
  Object.defineProperty(exports, "spy", { enumerable: true, get: function () { return mount_1.spy; } });
7
7
  Object.defineProperty(exports, "expectSpy", { enumerable: true, get: function () { return mount_1.expectSpy; } });
8
- var debug_1 = require("./debug");
9
- Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
10
8
  //# sourceMappingURL=test.js.map
package/dist/test.js.map CHANGED
@@ -1 +1 @@
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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyby/detox-component-testing",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Component testing support for Detox and React Native",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,9 +12,6 @@
12
12
  "./test": {
13
13
  "types": "./dist/test.d.ts",
14
14
  "default": "./dist/test.js"
15
- },
16
- "./environment": {
17
- "default": "./dist/environment.js"
18
15
  }
19
16
  },
20
17
  "typesVersions": {
@@ -29,7 +26,7 @@
29
26
  "src"
30
27
  ],
31
28
  "scripts": {
32
- "build": "tsc && cp src/environment.js dist/environment.js",
29
+ "build": "tsc",
33
30
  "clean": "rm -rf dist",
34
31
  "prepublishOnly": "npm run clean && npm run build",
35
32
  "publish:public": "npm publish --access public",
@@ -46,4 +46,4 @@ export function getComponent(name: string): ComponentEntry {
46
46
  );
47
47
  }
48
48
  return entry;
49
- }
49
+ }
@@ -0,0 +1,5 @@
1
+ declare module 'react-native-launch-arguments' {
2
+ export const LaunchArguments: {
3
+ value(): Record<string, any>;
4
+ };
5
+ }
package/src/test.ts CHANGED
@@ -1,2 +1 @@
1
1
  export {mount, spy, expectSpy} from './mount';
2
- export {debug} from './debug';
package/dist/debug.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Capture a screenshot and native view hierarchy to the given directory.
3
- * Used by both the `debug()` helper and the custom test environment.
4
- */
5
- export declare function captureArtifacts(name: string, outputDir: string, deviceRef: {
6
- takeScreenshot: (n: string) => Promise<string>;
7
- generateViewHierarchyXml: () => Promise<string>;
8
- }): Promise<void>;
9
- export declare function debug(label?: string, outputDir?: string): Promise<void>;
10
- //# sourceMappingURL=debug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE;IACT,cAAc,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,wBAAwB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACjD,iBAiBF;AAaD,wBAAsB,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,iBAI7D"}
package/dist/debug.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.captureArtifacts = captureArtifacts;
4
- exports.debug = debug;
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- /**
8
- * Capture a screenshot and native view hierarchy to the given directory.
9
- * Used by both the `debug()` helper and the custom test environment.
10
- */
11
- async function captureArtifacts(name, outputDir, deviceRef) {
12
- (0, fs_1.mkdirSync)(outputDir, { recursive: true });
13
- // Screenshot via Detox, then move to our artifacts dir
14
- try {
15
- const tempPath = await deviceRef.takeScreenshot(`debug-${name}`);
16
- if (tempPath) {
17
- (0, fs_1.renameSync)(tempPath, (0, path_1.join)(outputDir, `debug-${name}.png`));
18
- }
19
- }
20
- catch { }
21
- // Native view hierarchy
22
- try {
23
- const xml = await deviceRef.generateViewHierarchyXml();
24
- (0, fs_1.writeFileSync)((0, path_1.join)(outputDir, `debug-${name}-view.xml`), xml, 'utf8');
25
- }
26
- catch { }
27
- }
28
- /**
29
- * Capture a screenshot and native view hierarchy.
30
- * Drop this anywhere in a test to inspect the current screen state.
31
- *
32
- * Usage:
33
- * import { debug } from '@nyby/detox-component-testing/test';
34
- * await debug(); // artifacts/debug-1.png, debug-1-view.xml
35
- * await debug('after-tap'); // artifacts/debug-after-tap.png, etc.
36
- */
37
- let counter = 0;
38
- async function debug(label, outputDir) {
39
- const name = label || String(++counter);
40
- const dir = outputDir || (0, path_1.join)(process.cwd(), 'artifacts');
41
- await captureArtifacts(name, dir, device);
42
- }
43
- //# sourceMappingURL=debug.js.map
package/dist/debug.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":";;AAOA,4CAuBC;AAaD,sBAIC;AA/CD,2BAAwD;AACxD,+BAA0B;AAE1B;;;GAGG;AACI,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,SAAiB,EACjB,SAGC;IAED,IAAA,cAAS,EAAC,SAAS,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;IAExC,uDAAuD;IACvD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;QACjE,IAAI,QAAQ,EAAE,CAAC;YACb,IAAA,eAAU,EAAC,QAAQ,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,SAAS,IAAI,MAAM,CAAC,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,wBAAwB;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,wBAAwB,EAAE,CAAC;QACvD,IAAA,kBAAa,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,SAAS,IAAI,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACZ,CAAC;AAED;;;;;;;;GAQG;AACH,IAAI,OAAO,GAAG,CAAC,CAAC;AAET,KAAK,UAAU,KAAK,CAAC,KAAc,EAAE,SAAkB;IAC5D,MAAM,IAAI,GAAG,KAAK,IAAI,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IACxC,MAAM,GAAG,GAAG,SAAS,IAAI,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAC;IAC1D,MAAM,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC"}
@@ -1,17 +0,0 @@
1
- const DetoxCircusEnvironment = require('detox/runners/jest/testEnvironment');
2
- const {join} = require('path');
3
- const {captureArtifacts} = require('./debug');
4
-
5
- class CustomDetoxEnvironment extends DetoxCircusEnvironment {
6
- async handleTestEvent(event, state) {
7
- await super.handleTestEvent(event, state);
8
-
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
- await captureArtifacts(safeName, outputDir, this.global.device);
13
- }
14
- }
15
- }
16
-
17
- module.exports = CustomDetoxEnvironment;
package/src/debug.ts DELETED
@@ -1,48 +0,0 @@
1
- import {mkdirSync, renameSync, writeFileSync} from 'fs';
2
- import {join} from 'path';
3
-
4
- /**
5
- * Capture a screenshot and native view hierarchy to the given directory.
6
- * Used by both the `debug()` helper and the custom test environment.
7
- */
8
- export async function captureArtifacts(
9
- name: string,
10
- outputDir: string,
11
- deviceRef: {
12
- takeScreenshot: (n: string) => Promise<string>;
13
- generateViewHierarchyXml: () => Promise<string>;
14
- },
15
- ) {
16
- mkdirSync(outputDir, {recursive: true});
17
-
18
- // Screenshot via Detox, then move to our artifacts dir
19
- try {
20
- const tempPath = await deviceRef.takeScreenshot(`debug-${name}`);
21
- if (tempPath) {
22
- renameSync(tempPath, join(outputDir, `debug-${name}.png`));
23
- }
24
- } catch {}
25
-
26
- // Native view hierarchy
27
- try {
28
- const xml = await deviceRef.generateViewHierarchyXml();
29
- writeFileSync(join(outputDir, `debug-${name}-view.xml`), xml, 'utf8');
30
- } catch {}
31
- }
32
-
33
- /**
34
- * Capture a screenshot and native view hierarchy.
35
- * Drop this anywhere in a test to inspect the current screen state.
36
- *
37
- * Usage:
38
- * import { debug } from '@nyby/detox-component-testing/test';
39
- * await debug(); // artifacts/debug-1.png, debug-1-view.xml
40
- * await debug('after-tap'); // artifacts/debug-after-tap.png, etc.
41
- */
42
- let counter = 0;
43
-
44
- export async function debug(label?: string, outputDir?: string) {
45
- const name = label || String(++counter);
46
- const dir = outputDir || join(process.cwd(), 'artifacts');
47
- await captureArtifacts(name, dir, device);
48
- }
@@ -1,17 +0,0 @@
1
- const DetoxCircusEnvironment = require('detox/runners/jest/testEnvironment');
2
- const {join} = require('path');
3
- const {captureArtifacts} = require('./debug');
4
-
5
- class CustomDetoxEnvironment extends DetoxCircusEnvironment {
6
- async handleTestEvent(event, state) {
7
- await super.handleTestEvent(event, state);
8
-
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
- await captureArtifacts(safeName, outputDir, this.global.device);
13
- }
14
- }
15
- }
16
-
17
- module.exports = CustomDetoxEnvironment;