@react-native-harness/runtime 1.1.0 → 1.2.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/dist/NativeHarness.d.ts +41 -0
- package/dist/NativeHarness.d.ts.map +1 -0
- package/dist/NativeHarness.js +2 -0
- package/dist/client/factory.d.ts +2 -1
- package/dist/client/factory.d.ts.map +1 -1
- package/dist/client/factory.js +53 -59
- package/dist/client/store.d.ts +3 -3
- package/dist/client/store.d.ts.map +1 -1
- package/dist/client/store.js +7 -7
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +1 -0
- package/dist/expect/context.d.ts +20 -0
- package/dist/expect/context.d.ts.map +1 -0
- package/dist/expect/context.js +6 -0
- package/dist/expect/errors.d.ts +3 -0
- package/dist/expect/errors.d.ts.map +1 -0
- package/dist/expect/errors.js +45 -0
- package/dist/expect/expect.d.ts.map +1 -1
- package/dist/expect/expect.js +6 -1
- package/dist/expect/matchers/toMatchImageSnapshot.d.ts +1 -1
- package/dist/expect/matchers/toMatchImageSnapshot.d.ts.map +1 -1
- package/dist/expect/matchers/toMatchImageSnapshot.js +4 -12
- package/dist/initialize.js +14 -5
- package/dist/jsx/jsx-dev-runtime.d.ts +2 -1
- package/dist/jsx/jsx-dev-runtime.d.ts.map +1 -1
- package/dist/jsx/jsx-dev-runtime.js +16 -7
- package/dist/render/queries.d.ts +7 -0
- package/dist/render/queries.d.ts.map +1 -0
- package/dist/render/queries.js +99 -0
- package/dist/runHarnessTestsInModule.d.ts +9 -0
- package/dist/runHarnessTestsInModule.d.ts.map +1 -0
- package/dist/runHarnessTestsInModule.js +57 -0
- package/dist/runner/runSuite.d.ts.map +1 -1
- package/dist/runner/runSuite.js +16 -6
- package/dist/screen/index.d.ts +50 -0
- package/dist/screen/index.d.ts.map +1 -0
- package/dist/screen/index.js +46 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/userEvent/index.d.ts +16 -0
- package/dist/userEvent/index.d.ts.map +1 -0
- package/dist/userEvent/index.js +31 -0
- package/dist/utils/hmr.d.ts +2 -0
- package/dist/utils/hmr.d.ts.map +1 -0
- package/dist/utils/hmr.js +3 -0
- package/dist/utils/parse-error-stack.d.ts +9 -0
- package/dist/utils/parse-error-stack.d.ts.map +1 -0
- package/dist/utils/parse-error-stack.js +56 -0
- package/dist/waitFor.d.ts.map +1 -1
- package/dist/waitFor.js +5 -3
- package/out-tsc/vitest/src/__tests__/collector.test.d.ts +2 -0
- package/out-tsc/vitest/src/__tests__/collector.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/__tests__/error-handling.test.d.ts +2 -0
- package/out-tsc/vitest/src/__tests__/error-handling.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/__tests__/expect.test.d.ts +2 -0
- package/out-tsc/vitest/src/__tests__/expect.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/__tests__/initialize.test.d.ts +2 -0
- package/out-tsc/vitest/src/__tests__/initialize.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/__tests__/spy.test.d.ts +2 -0
- package/out-tsc/vitest/src/__tests__/spy.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/bundler/bundle.d.ts +2 -0
- package/out-tsc/vitest/src/bundler/bundle.d.ts.map +1 -0
- package/out-tsc/vitest/src/bundler/errors.d.ts +15 -0
- package/out-tsc/vitest/src/bundler/errors.d.ts.map +1 -0
- package/out-tsc/vitest/src/bundler/evaluate.d.ts +2 -0
- package/out-tsc/vitest/src/bundler/evaluate.d.ts.map +1 -0
- package/out-tsc/vitest/src/bundler/factory.d.ts +3 -0
- package/out-tsc/vitest/src/bundler/factory.d.ts.map +1 -0
- package/out-tsc/vitest/src/bundler/index.d.ts +4 -0
- package/out-tsc/vitest/src/bundler/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/bundler/types.d.ts +7 -0
- package/out-tsc/vitest/src/bundler/types.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/factory.d.ts +3 -0
- package/out-tsc/vitest/src/client/factory.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/getDeviceDescriptor.d.ts +8 -0
- package/out-tsc/vitest/src/client/getDeviceDescriptor.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/getWSServer.d.ts +2 -0
- package/out-tsc/vitest/src/client/getWSServer.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/getWSServer.test.d.ts +2 -0
- package/out-tsc/vitest/src/client/getWSServer.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/index.d.ts +2 -0
- package/out-tsc/vitest/src/client/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/setup-files.d.ts +12 -0
- package/out-tsc/vitest/src/client/setup-files.d.ts.map +1 -0
- package/out-tsc/vitest/src/client/store.d.ts +4 -0
- package/out-tsc/vitest/src/client/store.d.ts.map +1 -0
- package/out-tsc/vitest/src/collector/errors.d.ts +8 -0
- package/out-tsc/vitest/src/collector/errors.d.ts.map +1 -0
- package/out-tsc/vitest/src/collector/factory.d.ts +3 -0
- package/out-tsc/vitest/src/collector/factory.d.ts.map +1 -0
- package/out-tsc/vitest/src/collector/functions.d.ts +22 -0
- package/out-tsc/vitest/src/collector/functions.d.ts.map +1 -0
- package/out-tsc/vitest/src/collector/index.d.ts +5 -0
- package/out-tsc/vitest/src/collector/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/collector/types.d.ts +10 -0
- package/out-tsc/vitest/src/collector/types.d.ts.map +1 -0
- package/out-tsc/vitest/src/collector/validation.d.ts +4 -0
- package/out-tsc/vitest/src/collector/validation.d.ts.map +1 -0
- package/out-tsc/vitest/src/constants.d.ts +2 -0
- package/out-tsc/vitest/src/constants.d.ts.map +1 -0
- package/out-tsc/vitest/src/disableHMRWhenReady.d.ts +2 -0
- package/out-tsc/vitest/src/disableHMRWhenReady.d.ts.map +1 -0
- package/out-tsc/vitest/src/disableHMRWhenReady.test.d.ts +2 -0
- package/out-tsc/vitest/src/disableHMRWhenReady.test.d.ts.map +1 -0
- package/out-tsc/vitest/src/entry-point.d.ts +2 -0
- package/out-tsc/vitest/src/entry-point.d.ts.map +1 -0
- package/out-tsc/vitest/src/errors.d.ts +6 -0
- package/out-tsc/vitest/src/errors.d.ts.map +1 -0
- package/out-tsc/vitest/src/expect/context.d.ts +20 -0
- package/out-tsc/vitest/src/expect/context.d.ts.map +1 -0
- package/out-tsc/vitest/src/expect/errors.d.ts +3 -0
- package/out-tsc/vitest/src/expect/errors.d.ts.map +1 -0
- package/out-tsc/vitest/src/expect/expect.d.ts +9 -0
- package/out-tsc/vitest/src/expect/expect.d.ts.map +1 -0
- package/out-tsc/vitest/src/expect/index.d.ts +2 -0
- package/out-tsc/vitest/src/expect/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/expect/matchers/toMatchImageSnapshot.d.ts +13 -0
- package/out-tsc/vitest/src/expect/matchers/toMatchImageSnapshot.d.ts.map +1 -0
- package/out-tsc/vitest/src/expect/setup.d.ts +2 -0
- package/out-tsc/vitest/src/expect/setup.d.ts.map +1 -0
- package/out-tsc/vitest/src/filtering/index.d.ts +2 -0
- package/out-tsc/vitest/src/filtering/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/filtering/testNameFilter.d.ts +12 -0
- package/out-tsc/vitest/src/filtering/testNameFilter.d.ts.map +1 -0
- package/out-tsc/vitest/src/globals.d.ts +19 -0
- package/out-tsc/vitest/src/globals.d.ts.map +1 -0
- package/out-tsc/vitest/src/index.d.ts +12 -0
- package/out-tsc/vitest/src/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/initialize.d.ts +2 -0
- package/out-tsc/vitest/src/initialize.d.ts.map +1 -0
- package/out-tsc/vitest/src/jest-mock.d.ts +2 -0
- package/out-tsc/vitest/src/jest-mock.d.ts.map +1 -0
- package/out-tsc/vitest/src/jsx/jsx-dev-runtime.d.ts +4 -0
- package/out-tsc/vitest/src/jsx/jsx-dev-runtime.d.ts.map +1 -0
- package/out-tsc/vitest/src/jsx/jsx-runtime.d.ts +6 -0
- package/out-tsc/vitest/src/jsx/jsx-runtime.d.ts.map +1 -0
- package/out-tsc/vitest/src/mocker/index.d.ts +2 -0
- package/out-tsc/vitest/src/mocker/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/mocker/registry.d.ts +6 -0
- package/out-tsc/vitest/src/mocker/registry.d.ts.map +1 -0
- package/out-tsc/vitest/src/mocker/types.d.ts +6 -0
- package/out-tsc/vitest/src/mocker/types.d.ts.map +1 -0
- package/out-tsc/vitest/src/namespace.d.ts +18 -0
- package/out-tsc/vitest/src/namespace.d.ts.map +1 -0
- package/out-tsc/vitest/src/polyfills.d.ts +11 -0
- package/out-tsc/vitest/src/polyfills.d.ts.map +1 -0
- package/out-tsc/vitest/src/render/ErrorBoundary.d.ts +17 -0
- package/out-tsc/vitest/src/render/ErrorBoundary.d.ts.map +1 -0
- package/out-tsc/vitest/src/render/TestComponentOverlay.d.ts +3 -0
- package/out-tsc/vitest/src/render/TestComponentOverlay.d.ts.map +1 -0
- package/out-tsc/vitest/src/render/cleanup.d.ts +2 -0
- package/out-tsc/vitest/src/render/cleanup.d.ts.map +1 -0
- package/out-tsc/vitest/src/render/index.d.ts +6 -0
- package/out-tsc/vitest/src/render/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/render/setup.d.ts +2 -0
- package/out-tsc/vitest/src/render/setup.d.ts.map +1 -0
- package/out-tsc/vitest/src/render/types.d.ts +12 -0
- package/out-tsc/vitest/src/render/types.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/context.d.ts +10 -0
- package/out-tsc/vitest/src/runner/context.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/errors.d.ts +11 -0
- package/out-tsc/vitest/src/runner/errors.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/factory.d.ts +3 -0
- package/out-tsc/vitest/src/runner/factory.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/hooks.d.ts +4 -0
- package/out-tsc/vitest/src/runner/hooks.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/index.d.ts +5 -0
- package/out-tsc/vitest/src/runner/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/runSuite.d.ts +7 -0
- package/out-tsc/vitest/src/runner/runSuite.d.ts.map +1 -0
- package/out-tsc/vitest/src/runner/types.d.ts +18 -0
- package/out-tsc/vitest/src/runner/types.d.ts.map +1 -0
- package/out-tsc/vitest/src/screen/index.d.ts +8 -0
- package/out-tsc/vitest/src/screen/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/spy/index.d.ts +2 -0
- package/out-tsc/vitest/src/spy/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/symbolicate.d.ts +17 -0
- package/out-tsc/vitest/src/symbolicate.d.ts.map +1 -0
- package/out-tsc/vitest/src/ui/ReadyScreen.d.ts +2 -0
- package/out-tsc/vitest/src/ui/ReadyScreen.d.ts.map +1 -0
- package/out-tsc/vitest/src/ui/RunnerScreen.d.ts +8 -0
- package/out-tsc/vitest/src/ui/RunnerScreen.d.ts.map +1 -0
- package/out-tsc/vitest/src/ui/WrongEnvironmentScreen.d.ts +2 -0
- package/out-tsc/vitest/src/ui/WrongEnvironmentScreen.d.ts.map +1 -0
- package/out-tsc/vitest/src/ui/images.d.ts +3 -0
- package/out-tsc/vitest/src/ui/images.d.ts.map +1 -0
- package/out-tsc/vitest/src/ui/index.d.ts +2 -0
- package/out-tsc/vitest/src/ui/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/ui/state.d.ts +20 -0
- package/out-tsc/vitest/src/ui/state.d.ts.map +1 -0
- package/out-tsc/vitest/src/userEvent/index.d.ts +6 -0
- package/out-tsc/vitest/src/userEvent/index.d.ts.map +1 -0
- package/out-tsc/vitest/src/utils/dev-server.d.ts +2 -0
- package/out-tsc/vitest/src/utils/dev-server.d.ts.map +1 -0
- package/out-tsc/vitest/src/utils/emitter.d.ts +16 -0
- package/out-tsc/vitest/src/utils/emitter.d.ts.map +1 -0
- package/out-tsc/vitest/src/waitFor.d.ts +21 -0
- package/out-tsc/vitest/src/waitFor.d.ts.map +1 -0
- package/out-tsc/vitest/tsconfig.spec.tsbuildinfo +1 -0
- package/out-tsc/vitest/vite.config.d.ts +3 -0
- package/out-tsc/vitest/vite.config.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/client/factory.ts +63 -74
- package/src/client/store.ts +8 -8
- package/src/expect/context.ts +30 -0
- package/src/expect/errors.ts +76 -0
- package/src/expect/expect.ts +16 -5
- package/src/expect/matchers/toMatchImageSnapshot.ts +9 -23
- package/src/initialize.ts +14 -5
- package/src/jsx/jsx-dev-runtime.ts +34 -15
- package/src/runner/runSuite.ts +25 -11
- package/src/waitFor.ts +8 -6
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the position and dimensions of a view in screen coordinates (points/dp).
|
|
4
|
+
*/
|
|
5
|
+
export interface ViewInfo {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
interface Spec extends TurboModule {
|
|
12
|
+
/**
|
|
13
|
+
* Simulates a native tap at the specified screen coordinates.
|
|
14
|
+
* Returns a promise that resolves when the tap action is complete.
|
|
15
|
+
*/
|
|
16
|
+
simulateTap(x: number, y: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Finds a view by its testID (accessibilityIdentifier on iOS, tag on Android).
|
|
19
|
+
* Returns null if no view is found.
|
|
20
|
+
*/
|
|
21
|
+
queryByTestId(testId: string): ViewInfo | null;
|
|
22
|
+
/**
|
|
23
|
+
* Finds all views by testID (accessibilityIdentifier on iOS, tag on Android).
|
|
24
|
+
* Returns an empty array if no views are found.
|
|
25
|
+
*/
|
|
26
|
+
queryAllByTestId(testId: string): ViewInfo[];
|
|
27
|
+
/**
|
|
28
|
+
* Finds a view by its accessibility label.
|
|
29
|
+
* Returns null if no view is found.
|
|
30
|
+
*/
|
|
31
|
+
queryByAccessibilityLabel(label: string): ViewInfo | null;
|
|
32
|
+
/**
|
|
33
|
+
* Finds all views by accessibility label.
|
|
34
|
+
* Returns an empty array if no views are found.
|
|
35
|
+
*/
|
|
36
|
+
queryAllByAccessibilityLabel(label: string): ViewInfo[];
|
|
37
|
+
}
|
|
38
|
+
export type HarnessModule = Spec;
|
|
39
|
+
declare const _default: Spec;
|
|
40
|
+
export default _default;
|
|
41
|
+
//# sourceMappingURL=NativeHarness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeHarness.d.ts","sourceRoot":"","sources":["../src/NativeHarness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,IAAK,SAAQ,WAAW;IAChC;;;OAGG;IACH,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE/C;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;IAE7C;;;OAGG;IACH,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE1D;;;OAGG;IACH,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;CACzD;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC;;AAEjC,wBAAiE"}
|
package/dist/client/factory.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { type HarnessHandle } from '@react-native-harness/bridge/client';
|
|
2
|
+
export declare const getClient: () => Promise<HarnessHandle>;
|
|
2
3
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/client/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/client/factory.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAY3F,eAAO,MAAM,SAAS,QAAa,OAAO,CAAC,aAAa,CA2EvD,CAAC"}
|
package/dist/client/factory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { connectToHarness } from '@react-native-harness/bridge/client';
|
|
2
2
|
import { store } from '../ui/state.js';
|
|
3
3
|
import { getTestRunner } from '../runner/index.js';
|
|
4
4
|
import { getTestCollector } from '../collector/index.js';
|
|
@@ -8,68 +8,62 @@ import { getBundler, evaluateModule } from '../bundler/index.js';
|
|
|
8
8
|
import { markTestsAsSkippedByName } from '../filtering/index.js';
|
|
9
9
|
import { setup } from '../render/setup.js';
|
|
10
10
|
import { runSetupFiles } from './setup-files.js';
|
|
11
|
-
import {
|
|
11
|
+
import { setHandle } from './store.js';
|
|
12
12
|
export const getClient = async () => {
|
|
13
|
-
const
|
|
14
|
-
runTests: async () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bundler = getBundler();
|
|
32
|
-
events = combineEventEmitters(collector.events, runner.events, bundler.events);
|
|
33
|
-
events.addListener((event) => {
|
|
34
|
-
client.rpc.emitEvent(event.type, event);
|
|
35
|
-
});
|
|
36
|
-
await runSetupFiles({
|
|
37
|
-
setupFiles: options.setupFiles ?? [],
|
|
38
|
-
setupFilesAfterEnv: [],
|
|
39
|
-
events: events,
|
|
40
|
-
bundler: bundler,
|
|
41
|
-
evaluateModule,
|
|
42
|
-
});
|
|
43
|
-
const moduleJs = await bundler.getModule(path);
|
|
44
|
-
const collectionResult = await collector.collect(async () => {
|
|
13
|
+
const handle = await connectToHarness(getWSServer(), {
|
|
14
|
+
runTests: async (path, options) => {
|
|
15
|
+
if (store.getState().status === 'running') {
|
|
16
|
+
throw new Error('Already running tests');
|
|
17
|
+
}
|
|
18
|
+
store.getState().setStatus('running');
|
|
19
|
+
let collector = null;
|
|
20
|
+
let runner = null;
|
|
21
|
+
let events = null;
|
|
22
|
+
let bundler = null;
|
|
23
|
+
try {
|
|
24
|
+
collector = getTestCollector();
|
|
25
|
+
runner = getTestRunner();
|
|
26
|
+
bundler = getBundler();
|
|
27
|
+
events = combineEventEmitters(collector.events, runner.events, bundler.events);
|
|
28
|
+
events.addListener((event) => {
|
|
29
|
+
handle.emitEvent(event);
|
|
30
|
+
});
|
|
45
31
|
await runSetupFiles({
|
|
46
|
-
setupFiles: [],
|
|
47
|
-
setupFilesAfterEnv:
|
|
32
|
+
setupFiles: options.setupFiles ?? [],
|
|
33
|
+
setupFilesAfterEnv: [],
|
|
48
34
|
events: events,
|
|
49
35
|
bundler: bundler,
|
|
50
36
|
evaluateModule,
|
|
51
37
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
38
|
+
const moduleJs = await bundler.getModule(path);
|
|
39
|
+
const collectionResult = await collector.collect(async () => {
|
|
40
|
+
await runSetupFiles({
|
|
41
|
+
setupFiles: [],
|
|
42
|
+
setupFilesAfterEnv: options.setupFilesAfterEnv ?? [],
|
|
43
|
+
events: events,
|
|
44
|
+
bundler: bundler,
|
|
45
|
+
evaluateModule,
|
|
46
|
+
});
|
|
47
|
+
setup();
|
|
48
|
+
evaluateModule(moduleJs, path);
|
|
49
|
+
}, path);
|
|
50
|
+
const processedTestSuite = options.testNamePattern
|
|
51
|
+
? markTestsAsSkippedByName(collectionResult.testSuite, options.testNamePattern)
|
|
52
|
+
: collectionResult.testSuite;
|
|
53
|
+
return await runner.run({
|
|
54
|
+
testSuite: processedTestSuite,
|
|
55
|
+
testFilePath: path,
|
|
56
|
+
runner: options.runner,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
collector?.dispose();
|
|
61
|
+
runner?.dispose();
|
|
62
|
+
events?.clearAllListeners();
|
|
63
|
+
store.getState().setStatus('idle');
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
setHandle(handle);
|
|
68
|
+
return handle;
|
|
75
69
|
};
|
package/dist/client/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
import type { HarnessHandle } from '@react-native-harness/bridge/client';
|
|
2
|
+
export declare const setHandle: (h: HarnessHandle) => void;
|
|
3
|
+
export declare const getHandle: () => HarnessHandle;
|
|
4
4
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/client/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/client/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAIzE,eAAO,MAAM,SAAS,GAAI,GAAG,aAAa,KAAG,IAE5C,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,aAO5B,CAAC"}
|
package/dist/client/store.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
let
|
|
2
|
-
export const
|
|
3
|
-
|
|
1
|
+
let handle = null;
|
|
2
|
+
export const setHandle = (h) => {
|
|
3
|
+
handle = h;
|
|
4
4
|
};
|
|
5
|
-
export const
|
|
6
|
-
if (!
|
|
7
|
-
throw new Error('
|
|
5
|
+
export const getHandle = () => {
|
|
6
|
+
if (!handle) {
|
|
7
|
+
throw new Error('Harness not connected. This should not happen in normal operation.');
|
|
8
8
|
}
|
|
9
|
-
return
|
|
9
|
+
return handle;
|
|
10
10
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const WS_SERVER_PORT = 3001;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type HarnessExpectError = {
|
|
2
|
+
name?: string;
|
|
3
|
+
message?: string;
|
|
4
|
+
stack?: string;
|
|
5
|
+
};
|
|
6
|
+
export type HarnessExpectTestState = {
|
|
7
|
+
result?: {
|
|
8
|
+
state: 'pass' | 'fail';
|
|
9
|
+
errors?: HarnessExpectError[];
|
|
10
|
+
};
|
|
11
|
+
promises?: Promise<unknown>[];
|
|
12
|
+
onFinished?: Array<() => void | Promise<void>>;
|
|
13
|
+
};
|
|
14
|
+
declare global {
|
|
15
|
+
var HARNESS_EXPECT_TEST_STATE: HarnessExpectTestState | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare const getCurrentExpectTestState: () => HarnessExpectTestState | undefined;
|
|
18
|
+
export declare const setCurrentExpectTestState: (state: HarnessExpectTestState | undefined) => void;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/expect/context.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE;QACP,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,kBAAkB,EAAE,CAAC;KAC/B,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,yBAAyB,EAAE,sBAAsB,GAAG,SAAS,CAAC;CACnE;AAED,eAAO,MAAM,yBAAyB,QAClC,sBAAsB,GACtB,SAEH,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,OAAO,sBAAsB,GAAG,SAAS,KACxC,IAEF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/expect/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAgD3D,eAAO,MAAM,oBAAoB,GAC/B,OAAO,sBAAsB,KAC5B,OAAO,CAAC,IAAI,CAyBd,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const formatErrorMessage = (error) => {
|
|
2
|
+
if (error instanceof Error) {
|
|
3
|
+
return `${error.name}: ${error.message}`;
|
|
4
|
+
}
|
|
5
|
+
if (error && typeof error === 'object') {
|
|
6
|
+
const maybeError = error;
|
|
7
|
+
if (maybeError.name || maybeError.message) {
|
|
8
|
+
return [maybeError.name, maybeError.message].filter(Boolean).join(': ');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return String(error);
|
|
12
|
+
};
|
|
13
|
+
const createExpectError = (errors, title) => {
|
|
14
|
+
const message = [title, ...errors.map(formatErrorMessage)]
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.join('\n\n');
|
|
17
|
+
const error = new Error(message);
|
|
18
|
+
const firstError = errors.find((value) => !!value && typeof value === 'object');
|
|
19
|
+
if (firstError?.name) {
|
|
20
|
+
error.name = firstError.name;
|
|
21
|
+
}
|
|
22
|
+
if (firstError?.stack) {
|
|
23
|
+
error.stack = firstError.stack.replace(/^([^\n]+)(\n|$)/, `${error.name}: ${message}$2`);
|
|
24
|
+
}
|
|
25
|
+
return error;
|
|
26
|
+
};
|
|
27
|
+
export const flushExpectTestState = async (state) => {
|
|
28
|
+
if (state.promises?.length) {
|
|
29
|
+
const results = await Promise.allSettled(state.promises);
|
|
30
|
+
const rejected = results
|
|
31
|
+
.filter((result) => result.status === 'rejected')
|
|
32
|
+
.map((result) => result.reason);
|
|
33
|
+
if (rejected.length > 0) {
|
|
34
|
+
throw createExpectError(rejected);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const hook of state.onFinished ?? []) {
|
|
38
|
+
await hook();
|
|
39
|
+
}
|
|
40
|
+
const softErrors = state.result?.errors ?? [];
|
|
41
|
+
if (softErrors.length === 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw createExpectError(softErrors, 'Soft assertion failures:');
|
|
45
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect/expect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAS5E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect/expect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAS5E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B,OAAO,YAAY,CAAC;AAGpB,wBAAgB,YAAY,IAAI,YAAY,CAkG3C;AAED,QAAA,MAAM,YAAY,EAAE,YAA6B,CAAC;AAQlD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC;AAExC,YAAY,EACV,SAAS,EACT,4BAA4B,EAC5B,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,gBAAgB,CAAC"}
|
package/dist/expect/expect.js
CHANGED
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
import { addCustomEqualityTesters, ASYMMETRIC_MATCHERS_OBJECT, customMatchers, getState, GLOBAL_EXPECT, setState, } from '@vitest/expect';
|
|
4
4
|
import * as chai from 'chai';
|
|
5
5
|
// Setup additional matchers
|
|
6
|
+
import { getCurrentExpectTestState } from './context.js';
|
|
6
7
|
import './setup.js';
|
|
7
8
|
import { toMatchImageSnapshot } from './matchers/toMatchImageSnapshot.js';
|
|
8
9
|
export function createExpect() {
|
|
9
10
|
const expect = ((value, message) => {
|
|
10
11
|
const { assertionCalls } = getState(expect);
|
|
11
12
|
setState({ assertionCalls: assertionCalls + 1 }, expect);
|
|
12
|
-
|
|
13
|
+
const assertion = chai.expect(value, message);
|
|
14
|
+
const currentTest = getCurrentExpectTestState();
|
|
15
|
+
return currentTest && assertion.withTest
|
|
16
|
+
? assertion.withTest(currentTest)
|
|
17
|
+
: assertion;
|
|
13
18
|
});
|
|
14
19
|
Object.assign(expect, chai.expect);
|
|
15
20
|
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toMatchImageSnapshot.d.ts","sourceRoot":"","sources":["../../../src/expect/matchers/toMatchImageSnapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"toMatchImageSnapshot.d.ts","sourceRoot":"","sources":["../../../src/expect/matchers/toMatchImageSnapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC,CAoBnD"}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { generateTransferId, } from '@react-native-harness/bridge';
|
|
1
|
+
import { getHandle } from '../../client/store.js';
|
|
3
2
|
import { getHarnessContext } from '../../runner/index.js';
|
|
4
3
|
export async function toMatchImageSnapshot(received, options) {
|
|
5
|
-
const
|
|
4
|
+
const handle = getHandle();
|
|
6
5
|
const context = getHarnessContext();
|
|
7
|
-
const
|
|
8
|
-
client.sendBinary(transferId, received.data);
|
|
9
|
-
const screenshotFile = await client.rpc['device.screenshot.receive']({
|
|
10
|
-
type: 'binary',
|
|
11
|
-
transferId,
|
|
12
|
-
size: received.data.length,
|
|
13
|
-
mimeType: 'image/png',
|
|
14
|
-
}, {
|
|
6
|
+
const screenshotFile = await handle.transferScreenshot(received.data, {
|
|
15
7
|
width: received.width,
|
|
16
8
|
height: received.height,
|
|
17
9
|
});
|
|
18
|
-
const result = await
|
|
10
|
+
const result = await handle.matchImageSnapshot(screenshotFile, context.testFilePath, options, context.runner);
|
|
19
11
|
return {
|
|
20
12
|
pass: result.pass,
|
|
21
13
|
message: () => result.message,
|
package/dist/initialize.js
CHANGED
|
@@ -2,10 +2,19 @@ import { getDeviceDescriptor } from './client/getDeviceDescriptor.js';
|
|
|
2
2
|
import { getClient } from './client/index.js';
|
|
3
3
|
import { disableHMRWhenReady } from './disableHMRWhenReady.js';
|
|
4
4
|
import { setupJestMock } from './jest-mock.js';
|
|
5
|
-
// Polyfill for EventTarget
|
|
5
|
+
// Polyfill for EventTarget on runtimes that don't ship one (RN's JSC).
|
|
6
|
+
// Do NOT overwrite when a native ctor already exists (RN Web / browsers):
|
|
7
|
+
// Safari's EventTarget.dispatchEvent() does an internal brand check and
|
|
8
|
+
// rejects polyfill instances with a TypeError, which breaks any
|
|
9
|
+
// DOM-event-driven flow in the page — most visibly DRM (FairPlay) via
|
|
10
|
+
// libraries that re-dispatch synthetic `encrypted` events.
|
|
6
11
|
const Shim = require('event-target-shim');
|
|
7
|
-
globalThis.Event
|
|
8
|
-
globalThis.
|
|
12
|
+
if (typeof globalThis.Event !== 'function') {
|
|
13
|
+
globalThis.Event = Shim.Event;
|
|
14
|
+
}
|
|
15
|
+
if (typeof globalThis.EventTarget !== 'function') {
|
|
16
|
+
globalThis.EventTarget = Shim.EventTarget;
|
|
17
|
+
}
|
|
9
18
|
// Setup jest mock to warn users about using Jest APIs
|
|
10
19
|
setupJestMock();
|
|
11
20
|
// Turn off LogBox
|
|
@@ -19,9 +28,9 @@ setTimeout(() => {
|
|
|
19
28
|
void (async () => {
|
|
20
29
|
try {
|
|
21
30
|
await disableHMRWhenReady(() => HMRClient.disable(), 50);
|
|
22
|
-
const
|
|
31
|
+
const handle = await getClient();
|
|
23
32
|
const deviceDescriptor = getDeviceDescriptor();
|
|
24
|
-
|
|
33
|
+
handle.reportReady(deviceDescriptor);
|
|
25
34
|
}
|
|
26
35
|
catch (error) {
|
|
27
36
|
console.error('Failed to initialize React Native Harness', error);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as ReactJSXRuntimeDev from 'react/jsx-dev-runtime';
|
|
1
2
|
export declare const Fragment: import("react").ExoticComponent<import("react").FragmentProps>;
|
|
2
|
-
export declare function jsxDEV(
|
|
3
|
+
export declare function jsxDEV(...args: Parameters<typeof ReactJSXRuntimeDev.jsxDEV>): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
4
|
//# sourceMappingURL=jsx-dev-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;AAe5D,eAAO,MAAM,QAAQ,gEAA8B,CAAC;AAEpD,wBAAgB,MAAM,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,MAAM,CAAC,8FA8B3E"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import * as ReactJSXRuntimeDev from 'react/jsx-dev-runtime';
|
|
2
|
+
const isNamedElementType = (value) => (typeof value === 'function' ||
|
|
3
|
+
(typeof value === 'object' && value !== null)) &&
|
|
4
|
+
('displayName' in value || 'name' in value);
|
|
5
|
+
const isPropsObject = (value) => typeof value === 'object' && value !== null;
|
|
2
6
|
export const Fragment = ReactJSXRuntimeDev.Fragment;
|
|
3
|
-
export function jsxDEV(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
props
|
|
7
|
+
export function jsxDEV(...args) {
|
|
8
|
+
const [type, props, key, isStaticChildren, source, self] = args;
|
|
9
|
+
const isViewType = isNamedElementType(type) &&
|
|
10
|
+
(type.displayName === 'View' || type.name === 'View');
|
|
11
|
+
const nextProps = isViewType &&
|
|
12
|
+
isPropsObject(props) &&
|
|
13
|
+
props.collapsable === undefined
|
|
14
|
+
? { ...props, collapsable: true }
|
|
15
|
+
: props;
|
|
16
|
+
if (isViewType && isPropsObject(props) && props.collapsable === undefined) {
|
|
17
|
+
return ReactJSXRuntimeDev.jsxDEV(type, nextProps, key, isStaticChildren, source, self);
|
|
9
18
|
}
|
|
10
|
-
return ReactJSXRuntimeDev.jsxDEV(type,
|
|
19
|
+
return ReactJSXRuntimeDev.jsxDEV(type, nextProps, key, isStaticChildren, source, self);
|
|
11
20
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HostInstance } from 'react-native';
|
|
2
|
+
export declare const setRoot: (rootInstance: HostInstance) => void;
|
|
3
|
+
declare const queryByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, queryAllByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], getByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, getAllByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], findByTestId: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default>, findAllByTestId: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[]>;
|
|
4
|
+
declare const queryById: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, queryAllById: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], getId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, getAllById: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], findById: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default>, findAllById: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[]>;
|
|
5
|
+
export { queryByTestId, queryAllByTestId, getByTestId, getAllByTestId, findByTestId, findAllByTestId, };
|
|
6
|
+
export { queryById, queryAllById, getId, getAllById, findById, findAllById };
|
|
7
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/render/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM5C,eAAO,MAAM,OAAO,GAAI,cAAc,YAAY,SAEjD,CAAC;AA6IF,QAAA,MACW,aAAa,8HACV,gBAAgB,yHACrB,WAAW,8HACR,cAAc,yHAChB,YAAY,gIACT,eAAe,gIAG3B,CAAC;AACF,QAAA,MACW,SAAS,8HACN,YAAY,yHACjB,KAAK,8HACF,UAAU,yHACZ,QAAQ,gIACL,WAAW,gIAC+B,CAAC;AAExD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// import { store } from '../ui/state.js';
|
|
2
|
+
import { waitUntil } from '../waitFor.js';
|
|
3
|
+
let root = null;
|
|
4
|
+
export const setRoot = (rootInstance) => {
|
|
5
|
+
root = rootInstance;
|
|
6
|
+
};
|
|
7
|
+
const getRoot = () => {
|
|
8
|
+
const container = root;
|
|
9
|
+
if (!container) {
|
|
10
|
+
throw new Error('You need to render a component first!');
|
|
11
|
+
}
|
|
12
|
+
const ownerDocument = container.ownerDocument;
|
|
13
|
+
if (!ownerDocument) {
|
|
14
|
+
throw new Error('This feature is supported in React Native 0.82 and later!');
|
|
15
|
+
}
|
|
16
|
+
return ownerDocument.getRootNode();
|
|
17
|
+
};
|
|
18
|
+
const findNodeByPredicate = (predicate) => {
|
|
19
|
+
const queue = [getRoot()];
|
|
20
|
+
while (queue.length > 0) {
|
|
21
|
+
const node = queue.shift();
|
|
22
|
+
if (predicate(node)) {
|
|
23
|
+
return node;
|
|
24
|
+
}
|
|
25
|
+
for (const child of node.children) {
|
|
26
|
+
queue.push(child);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
const findNodesByPredicate = (predicate) => {
|
|
32
|
+
const nodes = [];
|
|
33
|
+
const queue = [getRoot()];
|
|
34
|
+
while (queue.length > 0) {
|
|
35
|
+
const node = queue.shift();
|
|
36
|
+
if (predicate(node)) {
|
|
37
|
+
nodes.push(node);
|
|
38
|
+
}
|
|
39
|
+
for (const child of node.children) {
|
|
40
|
+
queue.push(child);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return nodes;
|
|
44
|
+
};
|
|
45
|
+
const getFiberOfHostInstance = (hostInstance) => {
|
|
46
|
+
// This should be considered as 'reaching into the implementation details' of React Native.
|
|
47
|
+
// Not perfect, but it's the only way to get the props of the host instance.
|
|
48
|
+
return (hostInstance
|
|
49
|
+
.__internalInstanceHandle || null);
|
|
50
|
+
};
|
|
51
|
+
const getPropsOfHostInstance = (hostInstance) => {
|
|
52
|
+
return getFiberOfHostInstance(hostInstance)?.memoizedProps || {};
|
|
53
|
+
};
|
|
54
|
+
const findBy = (predicate, options) => {
|
|
55
|
+
return waitUntil(() => findNodeByPredicate(predicate), options);
|
|
56
|
+
};
|
|
57
|
+
const findAllBy = (predicate, options) => {
|
|
58
|
+
return waitUntil(() => {
|
|
59
|
+
const nodes = findNodesByPredicate(predicate);
|
|
60
|
+
if (nodes.length === 0) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return nodes;
|
|
64
|
+
}, options);
|
|
65
|
+
};
|
|
66
|
+
const queryBy = (predicate) => {
|
|
67
|
+
return findNodeByPredicate(predicate);
|
|
68
|
+
};
|
|
69
|
+
const queryAllBy = (predicate) => {
|
|
70
|
+
return findNodesByPredicate(predicate);
|
|
71
|
+
};
|
|
72
|
+
const getBy = (predicate) => {
|
|
73
|
+
const node = queryBy(predicate);
|
|
74
|
+
if (!node) {
|
|
75
|
+
throw new Error(`No node found with predicate ${predicate}`);
|
|
76
|
+
}
|
|
77
|
+
return node;
|
|
78
|
+
};
|
|
79
|
+
const getAllBy = (predicate) => {
|
|
80
|
+
const nodes = queryAllBy(predicate);
|
|
81
|
+
if (nodes.length === 0) {
|
|
82
|
+
throw new Error(`No nodes found with predicate ${predicate}`);
|
|
83
|
+
}
|
|
84
|
+
return nodes;
|
|
85
|
+
};
|
|
86
|
+
const createQueries = (predicate) => {
|
|
87
|
+
return {
|
|
88
|
+
findBy: (params) => findBy((node) => predicate(node, params)),
|
|
89
|
+
findAllBy: (params) => findAllBy((node) => predicate(node, params)),
|
|
90
|
+
queryBy: (params) => queryBy((node) => predicate(node, params)),
|
|
91
|
+
queryAllBy: (params) => queryAllBy((node) => predicate(node, params)),
|
|
92
|
+
getBy: (params) => getBy((node) => predicate(node, params)),
|
|
93
|
+
getAllBy: (params) => getAllBy((node) => predicate(node, params)),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const { queryBy: queryByTestId, queryAllBy: queryAllByTestId, getBy: getByTestId, getAllBy: getAllByTestId, findBy: findByTestId, findAllBy: findAllByTestId, } = createQueries((node, testId) => getPropsOfHostInstance(node).testID === testId);
|
|
97
|
+
const { queryBy: queryById, queryAllBy: queryAllById, getBy: getId, getAllBy: getAllById, findBy: findById, findAllBy: findAllById, } = createQueries((node, id) => node.id === id);
|
|
98
|
+
export { queryByTestId, queryAllByTestId, getByTestId, getAllByTestId, findByTestId, findAllByTestId, };
|
|
99
|
+
export { queryById, queryAllById, getId, getAllById, findById, findAllById };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TestSuiteResult } from '@react-native-harness/bridge';
|
|
2
|
+
/**
|
|
3
|
+
* Runs tests from a specific module programmatically and returns the results.
|
|
4
|
+
*
|
|
5
|
+
* @param moduleId The require.resolveWeak call to the module, returning the module ID
|
|
6
|
+
* @returns The result of the test suite execution
|
|
7
|
+
*/
|
|
8
|
+
export declare const runHarnessTestsInModule: (loader: () => unknown) => Promise<TestSuiteResult>;
|
|
9
|
+
//# sourceMappingURL=runHarnessTestsInModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runHarnessTestsInModule.d.ts","sourceRoot":"","sources":["../src/runHarnessTestsInModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,8BAA8B,CAAC;AAoCtC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,OAAO,KACpB,OAAO,CAAC,eAAe,CAuBzB,CAAC"}
|