react-native-harness 1.0.0-alpha.1 → 1.0.0-alpha.11
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 +2 -2
- package/bin.js +1 -1
- package/dist/babel.d.ts +2 -0
- package/dist/babel.d.ts.map +1 -0
- package/dist/babel.js +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -37
- package/dist/metro.d.ts +2 -0
- package/dist/metro.d.ts.map +1 -0
- package/dist/metro.js +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/eslint.config.mjs +1 -1
- package/package.json +31 -12
- package/src/babel.ts +1 -0
- package/src/index.ts +1 -52
- package/src/metro.ts +1 -0
- package/tsconfig.json +9 -3
- package/tsconfig.lib.json +8 -14
- package/types/index.d.ts +1 -0
- package/dist/bundlers/metro.d.ts +0 -5
- package/dist/bundlers/metro.d.ts.map +0 -1
- package/dist/bundlers/metro.js +0 -52
- package/dist/bundlers/webpack.d.ts +0 -2
- package/dist/bundlers/webpack.d.ts.map +0 -1
- package/dist/bundlers/webpack.js +0 -49
- package/dist/commands/test.d.ts +0 -2
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/commands/test.js +0 -111
- package/dist/errors/appNotInstalledError.d.ts +0 -7
- package/dist/errors/appNotInstalledError.d.ts.map +0 -1
- package/dist/errors/appNotInstalledError.js +0 -12
- package/dist/errors/bridgeTimeoutError.d.ts +0 -7
- package/dist/errors/bridgeTimeoutError.d.ts.map +0 -1
- package/dist/errors/bridgeTimeoutError.js +0 -12
- package/dist/errors/errorHandler.d.ts +0 -2
- package/dist/errors/errorHandler.d.ts.map +0 -1
- package/dist/errors/errorHandler.js +0 -138
- package/dist/errors/errors.d.ts +0 -41
- package/dist/errors/errors.d.ts.map +0 -1
- package/dist/errors/errors.js +0 -83
- package/dist/platforms/android/build.d.ts +0 -5
- package/dist/platforms/android/build.d.ts.map +0 -1
- package/dist/platforms/android/build.js +0 -29
- package/dist/platforms/android/device.d.ts +0 -5
- package/dist/platforms/android/device.d.ts.map +0 -1
- package/dist/platforms/android/device.js +0 -36
- package/dist/platforms/android/emulator.d.ts +0 -11
- package/dist/platforms/android/emulator.d.ts.map +0 -1
- package/dist/platforms/android/emulator.js +0 -110
- package/dist/platforms/android/index.d.ts +0 -4
- package/dist/platforms/android/index.d.ts.map +0 -1
- package/dist/platforms/android/index.js +0 -56
- package/dist/platforms/ios/build.d.ts +0 -7
- package/dist/platforms/ios/build.d.ts.map +0 -1
- package/dist/platforms/ios/build.js +0 -51
- package/dist/platforms/ios/device.d.ts +0 -7
- package/dist/platforms/ios/device.d.ts.map +0 -1
- package/dist/platforms/ios/device.js +0 -51
- package/dist/platforms/ios/index.d.ts +0 -4
- package/dist/platforms/ios/index.d.ts.map +0 -1
- package/dist/platforms/ios/index.js +0 -38
- package/dist/platforms/ios/simulator.d.ts +0 -11
- package/dist/platforms/ios/simulator.d.ts.map +0 -1
- package/dist/platforms/ios/simulator.js +0 -133
- package/dist/platforms/platform-adapter.d.ts +0 -10
- package/dist/platforms/platform-adapter.d.ts.map +0 -1
- package/dist/platforms/platform-adapter.js +0 -1
- package/dist/platforms/platform-registry.d.ts +0 -3
- package/dist/platforms/platform-registry.d.ts.map +0 -1
- package/dist/platforms/platform-registry.js +0 -19
- package/dist/platforms/web/index.d.ts +0 -4
- package/dist/platforms/web/index.d.ts.map +0 -1
- package/dist/platforms/web/index.js +0 -73
- package/dist/process.d.ts +0 -3
- package/dist/process.d.ts.map +0 -1
- package/dist/process.js +0 -28
- package/dist/reporters/default-reporter.d.ts +0 -3
- package/dist/reporters/default-reporter.d.ts.map +0 -1
- package/dist/reporters/default-reporter.js +0 -116
- package/dist/reporters/junit-reporter.d.ts +0 -3
- package/dist/reporters/junit-reporter.d.ts.map +0 -1
- package/dist/reporters/junit-reporter.js +0 -119
- package/dist/reporters/live-reporter.d.ts +0 -20
- package/dist/reporters/live-reporter.d.ts.map +0 -1
- package/dist/reporters/live-reporter.js +0 -176
- package/dist/src/reporters/default-reporter.js +0 -135
- package/dist/test-reporter-demo.js +0 -95
- package/dist/utils.d.ts +0 -5
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -11
- package/src/bundlers/metro.ts +0 -79
- package/src/commands/test.ts +0 -189
- package/src/errors/errorHandler.ts +0 -184
- package/src/errors/errors.ts +0 -109
- package/src/platforms/android/build.ts +0 -48
- package/src/platforms/android/device.ts +0 -48
- package/src/platforms/android/emulator.ts +0 -139
- package/src/platforms/android/index.ts +0 -87
- package/src/platforms/ios/build.ts +0 -76
- package/src/platforms/ios/device.ts +0 -76
- package/src/platforms/ios/index.ts +0 -55
- package/src/platforms/ios/simulator.ts +0 -177
- package/src/platforms/platform-adapter.ts +0 -11
- package/src/platforms/platform-registry.ts +0 -24
- package/src/platforms/web/index.ts +0 -95
- package/src/process.ts +0 -33
- package/src/reporters/default-reporter.ts +0 -149
- package/src/reporters/junit-reporter.ts +0 -179
- package/src/utils.ts +0 -12
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { defaultReporter } from './src/reporters/default-reporter.js';
|
|
2
|
-
// Sample test results to demonstrate the new styling
|
|
3
|
-
const sampleResults = [
|
|
4
|
-
{
|
|
5
|
-
name: 'User Authentication Tests',
|
|
6
|
-
status: 'passed',
|
|
7
|
-
duration: 1250,
|
|
8
|
-
tests: [
|
|
9
|
-
{
|
|
10
|
-
name: 'should login with valid credentials',
|
|
11
|
-
status: 'passed',
|
|
12
|
-
duration: 450,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: 'should show error with invalid credentials',
|
|
16
|
-
status: 'passed',
|
|
17
|
-
duration: 320,
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: 'should handle network errors gracefully',
|
|
21
|
-
status: 'failed',
|
|
22
|
-
duration: 180,
|
|
23
|
-
error: {
|
|
24
|
-
name: 'NetworkError',
|
|
25
|
-
message: 'Connection timeout after 30 seconds',
|
|
26
|
-
stack: 'NetworkError: Connection timeout after 30 seconds\n at fetch (native)\n at login (auth.js:15:10)',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
suites: [],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: 'Navigation Tests',
|
|
34
|
-
status: 'passed',
|
|
35
|
-
duration: 890,
|
|
36
|
-
tests: [
|
|
37
|
-
{
|
|
38
|
-
name: 'should navigate to home screen',
|
|
39
|
-
status: 'passed',
|
|
40
|
-
duration: 210,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'should navigate to profile screen',
|
|
44
|
-
status: 'skipped',
|
|
45
|
-
duration: 0,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'should handle deep linking',
|
|
49
|
-
status: 'todo',
|
|
50
|
-
duration: 0,
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
suites: [],
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'Component Tests',
|
|
57
|
-
status: 'failed',
|
|
58
|
-
duration: 650,
|
|
59
|
-
tests: [
|
|
60
|
-
{
|
|
61
|
-
name: 'should render button correctly',
|
|
62
|
-
status: 'passed',
|
|
63
|
-
duration: 120,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'should handle button press',
|
|
67
|
-
status: 'failed',
|
|
68
|
-
duration: 95,
|
|
69
|
-
error: {
|
|
70
|
-
name: 'AssertionError',
|
|
71
|
-
message: 'Expected element to be visible but it was not found',
|
|
72
|
-
stack: 'AssertionError: Expected element to be visible but it was not found\n at expect (test-utils.js:25:10)',
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
suites: [
|
|
77
|
-
{
|
|
78
|
-
name: 'Nested Component Tests',
|
|
79
|
-
status: 'passed',
|
|
80
|
-
duration: 280,
|
|
81
|
-
tests: [
|
|
82
|
-
{
|
|
83
|
-
name: 'should render nested component',
|
|
84
|
-
status: 'passed',
|
|
85
|
-
duration: 150,
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
suites: [],
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
];
|
|
93
|
-
// Run the demo
|
|
94
|
-
console.log('🧪 Testing Updated Default Reporter\n');
|
|
95
|
-
await defaultReporter.report(sampleResults);
|
package/dist/utils.d.ts
DELETED
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAI7E;AAED,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/utils.js
DELETED
package/src/bundlers/metro.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { type ChildProcess } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
getReactNativeCliPath,
|
|
4
|
-
getExpoCliPath,
|
|
5
|
-
getTimeoutSignal,
|
|
6
|
-
spawn,
|
|
7
|
-
SubprocessError,
|
|
8
|
-
} from '@react-native-harness/tools';
|
|
9
|
-
|
|
10
|
-
const METRO_PORT = 8081;
|
|
11
|
-
|
|
12
|
-
export const runMetro = async (isExpo = false): Promise<ChildProcess> => {
|
|
13
|
-
const metro = spawn(
|
|
14
|
-
'node',
|
|
15
|
-
[
|
|
16
|
-
isExpo ? getExpoCliPath() : getReactNativeCliPath(),
|
|
17
|
-
'start',
|
|
18
|
-
'--port',
|
|
19
|
-
METRO_PORT.toString(),
|
|
20
|
-
],
|
|
21
|
-
{
|
|
22
|
-
env: {
|
|
23
|
-
...process.env,
|
|
24
|
-
RN_HARNESS: 'true',
|
|
25
|
-
...(isExpo && { EXPO_NO_METRO_WORKSPACE_ROOT: 'true' }),
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
metro.catch((error) => {
|
|
31
|
-
// This process is going to be killed by us, so we don't need to throw an error
|
|
32
|
-
if (error instanceof SubprocessError && error.signalName === 'SIGTERM') {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
throw error;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
await waitForMetro();
|
|
40
|
-
return metro.nodeChildProcess;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const waitForMetro = async (
|
|
44
|
-
port = 8081,
|
|
45
|
-
maxRetries = 20,
|
|
46
|
-
retryDelay = 1000
|
|
47
|
-
): Promise<void> => {
|
|
48
|
-
let attempts = 0;
|
|
49
|
-
|
|
50
|
-
while (attempts < maxRetries) {
|
|
51
|
-
attempts++;
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const response = await fetch(`http://localhost:${port}/status`, {
|
|
55
|
-
signal: getTimeoutSignal(100),
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (response.ok) {
|
|
59
|
-
const body = await response.text();
|
|
60
|
-
|
|
61
|
-
if (body === 'packager-status:running') {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
} catch {
|
|
66
|
-
// Errors are expected here, we're just waiting for the process to be ready
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (attempts < maxRetries) {
|
|
70
|
-
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new Error(`Metro bundler is not ready after ${maxRetries} attempts`);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const reloadApp = async (): Promise<void> => {
|
|
78
|
-
await fetch(`http://localhost:${METRO_PORT}/reload`);
|
|
79
|
-
};
|
package/src/commands/test.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getBridgeServer,
|
|
3
|
-
type BridgeServer,
|
|
4
|
-
} from '@react-native-harness/bridge/server';
|
|
5
|
-
import {
|
|
6
|
-
Config,
|
|
7
|
-
getConfig,
|
|
8
|
-
TestRunnerConfig,
|
|
9
|
-
} from '@react-native-harness/config';
|
|
10
|
-
import { getPlatformAdapter } from '../platforms/platform-registry.js';
|
|
11
|
-
import { Glob } from 'glob';
|
|
12
|
-
import { defaultReporter } from '../reporters/default-reporter.js';
|
|
13
|
-
import {
|
|
14
|
-
intro,
|
|
15
|
-
logger,
|
|
16
|
-
outro,
|
|
17
|
-
spinner,
|
|
18
|
-
progress,
|
|
19
|
-
} from '@react-native-harness/tools';
|
|
20
|
-
import { type Environment } from '../platforms/platform-adapter.js';
|
|
21
|
-
import { BridgeTimeoutError } from '../errors/errors.js';
|
|
22
|
-
import { assert } from '../utils.js';
|
|
23
|
-
import {
|
|
24
|
-
EnvironmentInitializationError,
|
|
25
|
-
NoRunnerSpecifiedError,
|
|
26
|
-
RpcClientError,
|
|
27
|
-
RunnerNotFoundError,
|
|
28
|
-
} from '../errors/errors.js';
|
|
29
|
-
import { TestResult } from '@react-native-harness/bridge';
|
|
30
|
-
|
|
31
|
-
type TestRunContext = {
|
|
32
|
-
config: Config;
|
|
33
|
-
runner: TestRunnerConfig;
|
|
34
|
-
bridge?: BridgeServer;
|
|
35
|
-
environment?: Environment;
|
|
36
|
-
testFiles?: string[];
|
|
37
|
-
results?: TestResult[];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const setupEnvironment = async (context: TestRunContext): Promise<void> => {
|
|
41
|
-
const startSpinner = spinner();
|
|
42
|
-
const platform = context.runner.platform;
|
|
43
|
-
|
|
44
|
-
startSpinner.start(`Starting "${context.runner.name}" (${platform}) runner`);
|
|
45
|
-
|
|
46
|
-
const platformAdapter = await getPlatformAdapter(platform);
|
|
47
|
-
const serverBridge = await getBridgeServer({
|
|
48
|
-
port: 3001,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
context.bridge = serverBridge;
|
|
52
|
-
|
|
53
|
-
const readyPromise = new Promise<void>((resolve, reject) => {
|
|
54
|
-
const timeout = setTimeout(() => {
|
|
55
|
-
reject(
|
|
56
|
-
new BridgeTimeoutError(
|
|
57
|
-
context.config.bridgeTimeout,
|
|
58
|
-
context.runner.name,
|
|
59
|
-
platform
|
|
60
|
-
)
|
|
61
|
-
);
|
|
62
|
-
}, context.config.bridgeTimeout);
|
|
63
|
-
|
|
64
|
-
serverBridge.once('ready', () => {
|
|
65
|
-
clearTimeout(timeout);
|
|
66
|
-
resolve();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
context.environment = await platformAdapter.getEnvironment(context.runner);
|
|
71
|
-
|
|
72
|
-
logger.debug('Waiting for bridge to be ready');
|
|
73
|
-
await readyPromise;
|
|
74
|
-
logger.debug('Bridge is ready');
|
|
75
|
-
|
|
76
|
-
if (!context.environment) {
|
|
77
|
-
throw new EnvironmentInitializationError(
|
|
78
|
-
'Failed to initialize environment',
|
|
79
|
-
context.runner.name,
|
|
80
|
-
platform,
|
|
81
|
-
'Platform adapter returned null environment'
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
startSpinner.stop(`"${context.runner.name}" (${platform}) runner started`);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const findTestFiles = async (
|
|
89
|
-
context: TestRunContext,
|
|
90
|
-
pattern?: string
|
|
91
|
-
): Promise<void> => {
|
|
92
|
-
const discoverSpinner = spinner();
|
|
93
|
-
discoverSpinner.start('Discovering tests');
|
|
94
|
-
|
|
95
|
-
const globPattern = pattern || context.config.include;
|
|
96
|
-
const glob = new Glob(globPattern, {
|
|
97
|
-
cwd: process.cwd(),
|
|
98
|
-
});
|
|
99
|
-
context.testFiles = await glob.walk();
|
|
100
|
-
discoverSpinner.stop(`Found ${context.testFiles.length} test files`);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const runTests = async (context: TestRunContext): Promise<void> => {
|
|
104
|
-
const { bridge, environment, testFiles } = context;
|
|
105
|
-
assert(bridge != null, 'Bridge not initialized');
|
|
106
|
-
assert(environment != null, 'Environment not initialized');
|
|
107
|
-
assert(testFiles != null, 'Test files not initialized');
|
|
108
|
-
|
|
109
|
-
let runSpinner = progress({ style: 'block' });
|
|
110
|
-
runSpinner.start('Running tests');
|
|
111
|
-
|
|
112
|
-
let shouldRestart = false;
|
|
113
|
-
|
|
114
|
-
for (const testFile of testFiles) {
|
|
115
|
-
if (shouldRestart) {
|
|
116
|
-
runSpinner = progress({ style: 'block' });
|
|
117
|
-
runSpinner.message(`Restarting environment for next test file`);
|
|
118
|
-
|
|
119
|
-
await new Promise((resolve) => {
|
|
120
|
-
bridge.once('ready', resolve);
|
|
121
|
-
environment.restart();
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
runSpinner.message(`Running tests in ${testFile}`);
|
|
126
|
-
const client = bridge.rpc.clients.at(-1);
|
|
127
|
-
if (!client) {
|
|
128
|
-
throw new RpcClientError(
|
|
129
|
-
'No RPC client available',
|
|
130
|
-
3001,
|
|
131
|
-
'No clients connected'
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const result = await client.runTests(testFile);
|
|
136
|
-
context.results = [...(context.results ?? []), ...result.suites];
|
|
137
|
-
shouldRestart = true;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const cleanUp = async (context: TestRunContext): Promise<void> => {
|
|
142
|
-
if (context.bridge) {
|
|
143
|
-
context.bridge.ws.close();
|
|
144
|
-
}
|
|
145
|
-
if (context.environment) {
|
|
146
|
-
await context.environment.dispose();
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export const testCommand = async (
|
|
151
|
-
runnerName?: string,
|
|
152
|
-
pattern?: string
|
|
153
|
-
): Promise<void> => {
|
|
154
|
-
intro('React Native Test Harness');
|
|
155
|
-
|
|
156
|
-
const config = await getConfig(process.cwd());
|
|
157
|
-
config.reporter = defaultReporter;
|
|
158
|
-
|
|
159
|
-
const selectedRunnerName = runnerName ?? config.defaultRunner;
|
|
160
|
-
|
|
161
|
-
if (!selectedRunnerName) {
|
|
162
|
-
throw new NoRunnerSpecifiedError(config.runners);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const runner = config.runners.find((r) => r.name === selectedRunnerName);
|
|
166
|
-
|
|
167
|
-
if (!runner) {
|
|
168
|
-
throw new RunnerNotFoundError(selectedRunnerName, config.runners);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const context: TestRunContext = {
|
|
172
|
-
config,
|
|
173
|
-
runner,
|
|
174
|
-
testFiles: [],
|
|
175
|
-
results: [],
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
await setupEnvironment(context);
|
|
180
|
-
await findTestFiles(context, pattern);
|
|
181
|
-
await runTests(context);
|
|
182
|
-
|
|
183
|
-
assert(context.results != null, 'Results not initialized');
|
|
184
|
-
config.reporter?.report(context.results);
|
|
185
|
-
outro('Test run completed successfully');
|
|
186
|
-
} finally {
|
|
187
|
-
await cleanUp(context);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConfigLoadError,
|
|
3
|
-
ConfigNotFoundError,
|
|
4
|
-
ConfigValidationError,
|
|
5
|
-
} from '@react-native-harness/config';
|
|
6
|
-
import { AssertionError } from '../utils.js';
|
|
7
|
-
import {
|
|
8
|
-
NoRunnerSpecifiedError,
|
|
9
|
-
RunnerNotFoundError,
|
|
10
|
-
EnvironmentInitializationError,
|
|
11
|
-
TestExecutionError,
|
|
12
|
-
RpcClientError,
|
|
13
|
-
AppNotInstalledError,
|
|
14
|
-
BridgeTimeoutError,
|
|
15
|
-
} from './errors.js';
|
|
16
|
-
|
|
17
|
-
export const handleError = (error: unknown): void => {
|
|
18
|
-
if (error instanceof AssertionError) {
|
|
19
|
-
console.error(`\n❌ Assertion Error`);
|
|
20
|
-
console.error(`\nError: ${error.message}`);
|
|
21
|
-
console.error(`\nPlease check your configuration and try again.`);
|
|
22
|
-
} else if (error instanceof ConfigValidationError) {
|
|
23
|
-
console.error(`\n❌ Configuration Error`);
|
|
24
|
-
console.error(`\nFile: ${error.filePath}`);
|
|
25
|
-
console.error(`\nValidation errors:`);
|
|
26
|
-
error.validationErrors.forEach((err) => {
|
|
27
|
-
console.error(` • ${err}`);
|
|
28
|
-
});
|
|
29
|
-
console.error(`\nPlease fix the configuration errors and try again.`);
|
|
30
|
-
} else if (error instanceof ConfigNotFoundError) {
|
|
31
|
-
console.error(`\n❌ Configuration Not Found`);
|
|
32
|
-
console.error(
|
|
33
|
-
`\nCould not find 'rn-harness.config' in '${error.searchPath}' or any parent directories.`
|
|
34
|
-
);
|
|
35
|
-
console.error(`\nSupported file extensions: .js, .mjs, .cjs, .json`);
|
|
36
|
-
console.error(
|
|
37
|
-
`\nPlease create a configuration file or run from a directory that contains one.`
|
|
38
|
-
);
|
|
39
|
-
} else if (error instanceof ConfigLoadError) {
|
|
40
|
-
console.error(`\n❌ Configuration Load Error`);
|
|
41
|
-
console.error(`\nFile: ${error.filePath}`);
|
|
42
|
-
console.error(`Error: ${error.message}`);
|
|
43
|
-
if (error.cause) {
|
|
44
|
-
console.error(`\nCause: ${error.cause.message}`);
|
|
45
|
-
}
|
|
46
|
-
console.error(
|
|
47
|
-
`\nPlease check your configuration file syntax and try again.`
|
|
48
|
-
);
|
|
49
|
-
} else if (error instanceof NoRunnerSpecifiedError) {
|
|
50
|
-
console.error('\n❌ No runner specified');
|
|
51
|
-
console.error(
|
|
52
|
-
'\nPlease specify a runner name or set a defaultRunner in your config.'
|
|
53
|
-
);
|
|
54
|
-
console.error('\nUsage: react-native-harness test [runner-name] [pattern]');
|
|
55
|
-
console.error('\nAvailable runners:');
|
|
56
|
-
error.availableRunners.forEach((r) => {
|
|
57
|
-
console.error(` • ${r.name} (${r.platform})`);
|
|
58
|
-
});
|
|
59
|
-
console.error(
|
|
60
|
-
'\nTo set a default runner, add "defaultRunner" to your config:'
|
|
61
|
-
);
|
|
62
|
-
console.error(' { "defaultRunner": "your-runner-name" }');
|
|
63
|
-
} else if (error instanceof RunnerNotFoundError) {
|
|
64
|
-
console.error(`\n❌ Runner "${error.runnerName}" not found`);
|
|
65
|
-
console.error('\nAvailable runners:');
|
|
66
|
-
error.availableRunners.forEach((r) => {
|
|
67
|
-
console.error(` • ${r.name} (${r.platform})`);
|
|
68
|
-
});
|
|
69
|
-
console.error('\nTo add a new runner, update your rn-harness.config file.');
|
|
70
|
-
} else if (error instanceof EnvironmentInitializationError) {
|
|
71
|
-
console.error(`\n❌ Environment Initialization Error`);
|
|
72
|
-
console.error(`\nRunner: ${error.runnerName} (${error.platform})`);
|
|
73
|
-
console.error(`\nError: ${error.message}`);
|
|
74
|
-
if (error.details) {
|
|
75
|
-
console.error(`\nDetails: ${error.details}`);
|
|
76
|
-
}
|
|
77
|
-
console.error(`\nTroubleshooting steps:`);
|
|
78
|
-
console.error(
|
|
79
|
-
` • Verify that ${error.platform} development environment is properly set up`
|
|
80
|
-
);
|
|
81
|
-
console.error(` • Check that the app is built and ready for testing`);
|
|
82
|
-
console.error(` • Ensure all required dependencies are installed`);
|
|
83
|
-
if (error.platform === 'ios') {
|
|
84
|
-
console.error(` • Verify Xcode and iOS Simulator are working correctly`);
|
|
85
|
-
} else if (error.platform === 'android') {
|
|
86
|
-
console.error(
|
|
87
|
-
` • Verify Android SDK and emulator are working correctly`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
console.error(
|
|
91
|
-
`\nPlease check your environment configuration and try again.`
|
|
92
|
-
);
|
|
93
|
-
} else if (error instanceof TestExecutionError) {
|
|
94
|
-
console.error(`\n❌ Test Execution Error`);
|
|
95
|
-
console.error(`\nFile: ${error.testFile}`);
|
|
96
|
-
if (error.testSuite) {
|
|
97
|
-
console.error(`\nSuite: ${error.testSuite}`);
|
|
98
|
-
}
|
|
99
|
-
if (error.testName) {
|
|
100
|
-
console.error(`\nTest: ${error.testName}`);
|
|
101
|
-
}
|
|
102
|
-
console.error(`\nError: ${error.message}`);
|
|
103
|
-
console.error(`\nTroubleshooting steps:`);
|
|
104
|
-
console.error(` • Check the test file syntax and logic`);
|
|
105
|
-
console.error(` • Verify all test dependencies are available`);
|
|
106
|
-
console.error(` • Ensure the app is in the expected state for the test`);
|
|
107
|
-
console.error(
|
|
108
|
-
` • Check device/emulator logs for additional error details`
|
|
109
|
-
);
|
|
110
|
-
console.error(`\nPlease check your test file and try again.`);
|
|
111
|
-
} else if (error instanceof RpcClientError) {
|
|
112
|
-
console.error(`\n❌ RPC Client Error`);
|
|
113
|
-
console.error(`\nError: ${error.message}`);
|
|
114
|
-
if (error.bridgePort) {
|
|
115
|
-
console.error(`\nBridge Port: ${error.bridgePort}`);
|
|
116
|
-
}
|
|
117
|
-
if (error.connectionStatus) {
|
|
118
|
-
console.error(`\nConnection Status: ${error.connectionStatus}`);
|
|
119
|
-
}
|
|
120
|
-
console.error(`\nTroubleshooting steps:`);
|
|
121
|
-
console.error(` • Verify the React Native app is running and connected`);
|
|
122
|
-
console.error(` • Check that the bridge port is not blocked by firewall`);
|
|
123
|
-
console.error(
|
|
124
|
-
` • Ensure the app has the React Native Harness runtime integrated`
|
|
125
|
-
);
|
|
126
|
-
console.error(` • Try restarting the app and test harness`);
|
|
127
|
-
console.error(`\nPlease check your bridge connection and try again.`);
|
|
128
|
-
} else if (error instanceof AppNotInstalledError) {
|
|
129
|
-
console.error(`\n❌ App Not Installed`);
|
|
130
|
-
console.error(
|
|
131
|
-
`\nThe app "${error.bundleId}" is not installed on ${
|
|
132
|
-
error.platform === 'ios' ? 'simulator' : 'emulator'
|
|
133
|
-
} "${error.deviceName}".`
|
|
134
|
-
);
|
|
135
|
-
console.error(`\nTo resolve this issue:`);
|
|
136
|
-
if (error.platform === 'ios') {
|
|
137
|
-
console.error(
|
|
138
|
-
` • Build and install the app: npx react-native run-ios --simulator="${error.deviceName}"`
|
|
139
|
-
);
|
|
140
|
-
console.error(
|
|
141
|
-
` • Or install from Xcode: Open ios/*.xcworkspace and run the project`
|
|
142
|
-
);
|
|
143
|
-
} else {
|
|
144
|
-
console.error(
|
|
145
|
-
` • Build and install the app: npx react-native run-android`
|
|
146
|
-
);
|
|
147
|
-
console.error(
|
|
148
|
-
` • Or build manually: ./gradlew assembleDebug && adb install android/app/build/outputs/apk/debug/app-debug.apk`
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
console.error(`\nPlease install the app and try running the tests again.`);
|
|
152
|
-
} else if (error instanceof BridgeTimeoutError) {
|
|
153
|
-
console.error(`\n❌ Bridge Connection Timeout`);
|
|
154
|
-
console.error(
|
|
155
|
-
`\nThe bridge connection timed out after ${error.timeout}ms while waiting for the "${error.runnerName}" (${error.platform}) runner to be ready.`
|
|
156
|
-
);
|
|
157
|
-
console.error(`\nThis usually indicates that:`);
|
|
158
|
-
console.error(
|
|
159
|
-
` • The React Native app failed to load or connect to the bridge`
|
|
160
|
-
);
|
|
161
|
-
console.error(` • The app crashed during startup`);
|
|
162
|
-
console.error(
|
|
163
|
-
` • Network connectivity issues between the app and the test harness`
|
|
164
|
-
);
|
|
165
|
-
console.error(` • The app is taking longer than expected to initialize`);
|
|
166
|
-
console.error(`\nTo resolve this issue:`);
|
|
167
|
-
console.error(
|
|
168
|
-
` • Check that the app is properly installed and can start normally`
|
|
169
|
-
);
|
|
170
|
-
console.error(
|
|
171
|
-
` • Verify that the app has the React Native Harness runtime integrated`
|
|
172
|
-
);
|
|
173
|
-
console.error(` • Check device/emulator logs for any startup errors`);
|
|
174
|
-
console.error(
|
|
175
|
-
` • Ensure the test harness bridge port (3001) is not blocked`
|
|
176
|
-
);
|
|
177
|
-
console.error(
|
|
178
|
-
`\nIf the app needs more time to start, consider increasing the timeout in the configuration.`
|
|
179
|
-
);
|
|
180
|
-
} else {
|
|
181
|
-
console.error(`\n❌ Unexpected Error`);
|
|
182
|
-
console.error(error);
|
|
183
|
-
}
|
|
184
|
-
};
|
package/src/errors/errors.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { TestRunnerConfig } from '@react-native-harness/config';
|
|
2
|
-
|
|
3
|
-
export class NoRunnerSpecifiedError extends Error {
|
|
4
|
-
constructor(availableRunners: TestRunnerConfig[]) {
|
|
5
|
-
super('No runner specified');
|
|
6
|
-
this.name = 'NoRunnerSpecifiedError';
|
|
7
|
-
this.availableRunners = availableRunners;
|
|
8
|
-
}
|
|
9
|
-
availableRunners: TestRunnerConfig[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class RunnerNotFoundError extends Error {
|
|
13
|
-
constructor(runnerName: string, availableRunners: TestRunnerConfig[]) {
|
|
14
|
-
super(`Runner "${runnerName}" not found`);
|
|
15
|
-
this.name = 'RunnerNotFoundError';
|
|
16
|
-
this.runnerName = runnerName;
|
|
17
|
-
this.availableRunners = availableRunners;
|
|
18
|
-
}
|
|
19
|
-
runnerName: string;
|
|
20
|
-
availableRunners: TestRunnerConfig[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class EnvironmentInitializationError extends Error {
|
|
24
|
-
constructor(
|
|
25
|
-
message: string,
|
|
26
|
-
runnerName: string,
|
|
27
|
-
platform: string,
|
|
28
|
-
details?: string
|
|
29
|
-
) {
|
|
30
|
-
super(
|
|
31
|
-
`Failed to initialize environment for "${runnerName}" (${platform}): ${message}`
|
|
32
|
-
);
|
|
33
|
-
this.name = 'EnvironmentInitializationError';
|
|
34
|
-
this.runnerName = runnerName;
|
|
35
|
-
this.platform = platform;
|
|
36
|
-
this.details = details;
|
|
37
|
-
}
|
|
38
|
-
runnerName: string;
|
|
39
|
-
platform: string;
|
|
40
|
-
details?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class TestExecutionError extends Error {
|
|
44
|
-
constructor(
|
|
45
|
-
testFile: string,
|
|
46
|
-
error: unknown,
|
|
47
|
-
testSuite?: string,
|
|
48
|
-
testName?: string
|
|
49
|
-
) {
|
|
50
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
51
|
-
const suiteInfo = testSuite ? ` in suite "${testSuite}"` : '';
|
|
52
|
-
const testInfo = testName ? ` test "${testName}"` : '';
|
|
53
|
-
|
|
54
|
-
super(
|
|
55
|
-
`Test execution failed for ${testFile}${suiteInfo}${testInfo}: ${errorMessage}`
|
|
56
|
-
);
|
|
57
|
-
this.name = 'TestExecutionError';
|
|
58
|
-
this.testFile = testFile;
|
|
59
|
-
this.testSuite = testSuite;
|
|
60
|
-
this.testName = testName;
|
|
61
|
-
this.originalError = error;
|
|
62
|
-
}
|
|
63
|
-
testFile: string;
|
|
64
|
-
testSuite?: string;
|
|
65
|
-
testName?: string;
|
|
66
|
-
originalError: unknown;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class RpcClientError extends Error {
|
|
70
|
-
constructor(message: string, bridgePort?: number, connectionStatus?: string) {
|
|
71
|
-
const portInfo = bridgePort ? ` (port ${bridgePort})` : '';
|
|
72
|
-
const statusInfo = connectionStatus ? ` - Status: ${connectionStatus}` : '';
|
|
73
|
-
|
|
74
|
-
super(`RPC client error${portInfo}: ${message}${statusInfo}`);
|
|
75
|
-
this.name = 'RpcClientError';
|
|
76
|
-
this.bridgePort = bridgePort;
|
|
77
|
-
this.connectionStatus = connectionStatus;
|
|
78
|
-
}
|
|
79
|
-
bridgePort?: number;
|
|
80
|
-
connectionStatus?: string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class BridgeTimeoutError extends Error {
|
|
84
|
-
constructor(
|
|
85
|
-
public readonly timeout: number,
|
|
86
|
-
public readonly runnerName: string,
|
|
87
|
-
public readonly platform: string
|
|
88
|
-
) {
|
|
89
|
-
super(
|
|
90
|
-
`Bridge connection timed out after ${timeout}ms while waiting for "${runnerName}" (${platform}) runner to be ready`
|
|
91
|
-
);
|
|
92
|
-
this.name = 'BridgeTimeoutError';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class AppNotInstalledError extends Error {
|
|
97
|
-
constructor(
|
|
98
|
-
public readonly deviceName: string,
|
|
99
|
-
public readonly bundleId: string,
|
|
100
|
-
public readonly platform: 'ios' | 'android'
|
|
101
|
-
) {
|
|
102
|
-
super(
|
|
103
|
-
`App "${bundleId}" is not installed on ${
|
|
104
|
-
platform === 'ios' ? 'simulator' : 'emulator'
|
|
105
|
-
} "${deviceName}"`
|
|
106
|
-
);
|
|
107
|
-
this.name = 'AppNotInstalledError';
|
|
108
|
-
}
|
|
109
|
-
}
|