@react-native-harness/jest 1.0.0 → 1.1.0-rc.2
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/__tests__/crash-supervisor.test.d.ts +2 -0
- package/dist/__tests__/crash-supervisor.test.d.ts.map +1 -0
- package/dist/__tests__/crash-supervisor.test.js +151 -0
- package/dist/__tests__/errors.test.d.ts +2 -0
- package/dist/__tests__/errors.test.d.ts.map +1 -0
- package/dist/__tests__/errors.test.js +54 -0
- package/dist/__tests__/harness-cache.test.d.ts +2 -0
- package/dist/__tests__/harness-cache.test.d.ts.map +1 -0
- package/dist/__tests__/harness-cache.test.js +51 -0
- package/dist/__tests__/harness.test.d.ts +2 -0
- package/dist/__tests__/harness.test.d.ts.map +1 -0
- package/dist/__tests__/harness.test.js +399 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +42 -0
- package/dist/cli-args.d.ts +1 -0
- package/dist/cli-args.d.ts.map +1 -1
- package/dist/cli-args.js +5 -0
- package/dist/crash-supervisor.d.ts +21 -0
- package/dist/crash-supervisor.d.ts.map +1 -0
- package/dist/crash-supervisor.js +210 -0
- package/dist/errors.d.ts +9 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +43 -8
- package/dist/harness.d.ts +30 -8
- package/dist/harness.d.ts.map +1 -1
- package/dist/harness.js +440 -98
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -57
- package/dist/logs.d.ts +1 -0
- package/dist/logs.d.ts.map +1 -1
- package/dist/logs.js +3 -0
- package/dist/run.d.ts +7 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +13 -8
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +18 -6
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/__tests__/crash-supervisor.test.ts +200 -0
- package/src/__tests__/errors.test.ts +70 -0
- package/src/__tests__/harness-cache.test.ts +74 -0
- package/src/__tests__/harness.test.ts +547 -0
- package/src/__tests__/index.test.ts +61 -0
- package/src/cli-args.ts +6 -0
- package/src/crash-supervisor.ts +321 -0
- package/src/env.d.ts +1 -1
- package/src/errors.ts +68 -8
- package/src/harness.ts +566 -120
- package/src/index.ts +276 -66
- package/src/logs.ts +4 -0
- package/src/run.ts +20 -10
- package/src/setup.ts +22 -6
- package/tsconfig.json +3 -3
- package/tsconfig.lib.json +6 -6
- package/dist/cli-args.test.d.ts +0 -2
- package/dist/cli-args.test.d.ts.map +0 -1
- package/dist/cli-args.test.js +0 -1
- package/dist/crash-monitor.d.ts +0 -16
- package/dist/crash-monitor.d.ts.map +0 -1
- package/dist/crash-monitor.js +0 -75
- package/dist/event-mapper.d.ts +0 -16
- package/dist/event-mapper.d.ts.map +0 -1
- package/dist/event-mapper.js +0 -120
- package/dist/global-setup.d.ts +0 -3
- package/dist/global-setup.d.ts.map +0 -1
- package/dist/global-setup.js +0 -60
- package/dist/global-teardown.d.ts +0 -3
- package/dist/global-teardown.d.ts.map +0 -1
- package/dist/global-teardown.js +0 -11
- package/dist/harness-reporter.d.ts +0 -8
- package/dist/harness-reporter.d.ts.map +0 -1
- package/dist/harness-reporter.js +0 -12
- package/dist/jest-options.d.ts +0 -2
- package/dist/jest-options.d.ts.map +0 -1
- package/dist/jest-options.js +0 -1
- package/dist/types.d.ts +0 -17
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
- package/src/crash-monitor.ts +0 -109
package/dist/crash-monitor.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { NativeCrashError } from './errors.js';
|
|
2
|
-
import { logger } from '@react-native-harness/tools';
|
|
3
|
-
export const createCrashMonitor = ({ interval, platformRunner, bridgeServer, }) => {
|
|
4
|
-
let pollingInterval = null;
|
|
5
|
-
let isIntentionalRestart = false;
|
|
6
|
-
let currentTestFilePath = null;
|
|
7
|
-
let rejectFn = null;
|
|
8
|
-
const handleDisconnect = () => {
|
|
9
|
-
// Verify if it's actually a crash by checking if app is still running
|
|
10
|
-
if (!isIntentionalRestart && currentTestFilePath) {
|
|
11
|
-
// Capture the value to avoid it being null when setTimeout callback runs
|
|
12
|
-
const testFilePath = currentTestFilePath;
|
|
13
|
-
logger.debug('Bridge disconnected, checking if app crashed');
|
|
14
|
-
// Use a slight delay to allow the OS to clean up the process
|
|
15
|
-
setTimeout(async () => {
|
|
16
|
-
const isRunning = await platformRunner.isAppRunning();
|
|
17
|
-
if (!isRunning && !isIntentionalRestart && rejectFn) {
|
|
18
|
-
logger.debug(`Native crash detected during: ${testFilePath}`);
|
|
19
|
-
rejectFn(new NativeCrashError(testFilePath));
|
|
20
|
-
}
|
|
21
|
-
}, 100);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const startMonitoring = (testFilePath) => {
|
|
25
|
-
currentTestFilePath = testFilePath;
|
|
26
|
-
return new Promise((_, reject) => {
|
|
27
|
-
rejectFn = reject;
|
|
28
|
-
// Listen for bridge disconnect as early indicator
|
|
29
|
-
bridgeServer.on('disconnect', handleDisconnect);
|
|
30
|
-
// Poll for app running status
|
|
31
|
-
pollingInterval = setInterval(async () => {
|
|
32
|
-
// Skip check during intentional restarts
|
|
33
|
-
if (isIntentionalRestart) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const isRunning = await platformRunner.isAppRunning();
|
|
38
|
-
if (!isRunning && currentTestFilePath) {
|
|
39
|
-
logger.debug(`Native crash detected during: ${currentTestFilePath}`);
|
|
40
|
-
stopMonitoring();
|
|
41
|
-
reject(new NativeCrashError(currentTestFilePath));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
logger.error('Error checking app status:', error);
|
|
46
|
-
}
|
|
47
|
-
}, interval);
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const stopMonitoring = () => {
|
|
51
|
-
if (pollingInterval) {
|
|
52
|
-
clearInterval(pollingInterval);
|
|
53
|
-
pollingInterval = null;
|
|
54
|
-
}
|
|
55
|
-
bridgeServer.off('disconnect', handleDisconnect);
|
|
56
|
-
currentTestFilePath = null;
|
|
57
|
-
rejectFn = null;
|
|
58
|
-
};
|
|
59
|
-
const markIntentionalRestart = () => {
|
|
60
|
-
isIntentionalRestart = true;
|
|
61
|
-
};
|
|
62
|
-
const clearIntentionalRestart = () => {
|
|
63
|
-
isIntentionalRestart = false;
|
|
64
|
-
};
|
|
65
|
-
const dispose = () => {
|
|
66
|
-
stopMonitoring();
|
|
67
|
-
};
|
|
68
|
-
return {
|
|
69
|
-
startMonitoring,
|
|
70
|
-
stopMonitoring,
|
|
71
|
-
markIntentionalRestart,
|
|
72
|
-
clearIntentionalRestart,
|
|
73
|
-
dispose,
|
|
74
|
-
};
|
|
75
|
-
};
|
package/dist/event-mapper.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { TestEvents } from '@jest/test-result';
|
|
2
|
-
import type { Test } from 'jest-runner';
|
|
3
|
-
import type { BridgeEvents } from '@react-native-harness/bridge';
|
|
4
|
-
import type { TestCaseResult } from '@jest/test-result';
|
|
5
|
-
export type EventMapperState = {
|
|
6
|
-
currentTest?: Test;
|
|
7
|
-
suiteHierarchy: string[];
|
|
8
|
-
testResults: Map<string, TestCaseResult>;
|
|
9
|
-
fileStartTime: number;
|
|
10
|
-
};
|
|
11
|
-
export type HarnessEventMapper = {
|
|
12
|
-
handleBridgeEvent: (event: BridgeEvents, test: Test) => void;
|
|
13
|
-
reset: () => void;
|
|
14
|
-
};
|
|
15
|
-
export declare const getHarnessEventMapper: (emit: <T extends keyof TestEvents>(eventName: T, eventData: TestEvents[T]) => void) => HarnessEventMapper;
|
|
16
|
-
//# sourceMappingURL=event-mapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-mapper.d.ts","sourceRoot":"","sources":["../src/event-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EASV,YAAY,EACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC7D,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,MAAM,CAAC,CAAC,SAAS,MAAM,UAAU,EAC/B,SAAS,EAAE,CAAC,EACZ,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,IAAI,KACR,kBA8JF,CAAC"}
|
package/dist/event-mapper.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
export const getHarnessEventMapper = (emit) => {
|
|
2
|
-
const state = {
|
|
3
|
-
suiteHierarchy: [],
|
|
4
|
-
testResults: new Map(),
|
|
5
|
-
fileStartTime: 0,
|
|
6
|
-
};
|
|
7
|
-
const handleBridgeEvent = (event, test) => {
|
|
8
|
-
// Filter to only process test runner events
|
|
9
|
-
if (event.type.startsWith('test-') ||
|
|
10
|
-
event.type.startsWith('suite-') ||
|
|
11
|
-
event.type.startsWith('file-')) {
|
|
12
|
-
switch (event.type) {
|
|
13
|
-
case 'file-started':
|
|
14
|
-
handleFileStarted(event, test);
|
|
15
|
-
break;
|
|
16
|
-
case 'file-finished':
|
|
17
|
-
handleFileFinished(event, test);
|
|
18
|
-
break;
|
|
19
|
-
case 'suite-started':
|
|
20
|
-
handleSuiteStarted(event);
|
|
21
|
-
break;
|
|
22
|
-
case 'suite-finished':
|
|
23
|
-
handleSuiteFinished(event);
|
|
24
|
-
break;
|
|
25
|
-
case 'test-started':
|
|
26
|
-
handleTestStarted(event, test);
|
|
27
|
-
break;
|
|
28
|
-
case 'test-finished':
|
|
29
|
-
handleTestFinished(event, test);
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const handleFileStarted = (event, test) => {
|
|
35
|
-
state.currentTest = test;
|
|
36
|
-
state.fileStartTime = Date.now();
|
|
37
|
-
state.suiteHierarchy = [];
|
|
38
|
-
state.testResults.clear();
|
|
39
|
-
// Don't emit test-file-start here - that should be handled by the Jest runner
|
|
40
|
-
// when it actually starts running the test file
|
|
41
|
-
};
|
|
42
|
-
const handleFileFinished = (_event, _test) => {
|
|
43
|
-
// File finished - all test results should already be emitted
|
|
44
|
-
// The final TestResult will be handled by the runHarnessTestFile function
|
|
45
|
-
};
|
|
46
|
-
const handleSuiteStarted = (event) => {
|
|
47
|
-
state.suiteHierarchy.push(event.name);
|
|
48
|
-
};
|
|
49
|
-
const handleSuiteFinished = (event) => {
|
|
50
|
-
// Remove the suite from hierarchy when it finishes
|
|
51
|
-
const index = state.suiteHierarchy.lastIndexOf(event.name);
|
|
52
|
-
if (index !== -1) {
|
|
53
|
-
state.suiteHierarchy.splice(index, 1);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const handleTestStarted = (event, test) => {
|
|
57
|
-
const testCaseStartInfo = {
|
|
58
|
-
ancestorTitles: [...state.suiteHierarchy],
|
|
59
|
-
fullName: `${state.suiteHierarchy.join(' ')} ${event.name}`.trim(),
|
|
60
|
-
title: event.name,
|
|
61
|
-
mode: 'skip', // Default mode, will be updated based on test status
|
|
62
|
-
};
|
|
63
|
-
emit('test-case-start', [test.path, testCaseStartInfo]);
|
|
64
|
-
};
|
|
65
|
-
const handleTestFinished = (event, test) => {
|
|
66
|
-
const testCaseResult = {
|
|
67
|
-
ancestorTitles: [...state.suiteHierarchy],
|
|
68
|
-
duration: event.duration,
|
|
69
|
-
failureDetails: [],
|
|
70
|
-
failureMessages: event.error ? [formatError(event.error)] : [],
|
|
71
|
-
fullName: `${state.suiteHierarchy.join(' ')} ${event.name}`.trim(),
|
|
72
|
-
numPassingAsserts: event.status === 'passed' ? 1 : 0,
|
|
73
|
-
status: mapStatus(event.status),
|
|
74
|
-
title: event.name,
|
|
75
|
-
startedAt: Date.now() - event.duration,
|
|
76
|
-
};
|
|
77
|
-
state.testResults.set(event.name, testCaseResult);
|
|
78
|
-
emit('test-case-result', [test.path, testCaseResult]);
|
|
79
|
-
};
|
|
80
|
-
const mapStatus = (status) => {
|
|
81
|
-
return status;
|
|
82
|
-
};
|
|
83
|
-
const formatError = (error) => {
|
|
84
|
-
let errorMessage = `${error.name}: ${error.message}`;
|
|
85
|
-
if (error.codeFrame) {
|
|
86
|
-
errorMessage += '\n\n' + formatCodeFrame(error.codeFrame);
|
|
87
|
-
}
|
|
88
|
-
return errorMessage;
|
|
89
|
-
};
|
|
90
|
-
const formatCodeFrame = (codeFrame) => {
|
|
91
|
-
const lines = codeFrame.content.split('\n');
|
|
92
|
-
const lineNumber = codeFrame.location?.row || 1;
|
|
93
|
-
const column = codeFrame.location?.column || 1;
|
|
94
|
-
let formatted = `\n${codeFrame.fileName}:${lineNumber}:${column}\n`;
|
|
95
|
-
// Add context lines around the error
|
|
96
|
-
const startLine = Math.max(0, lineNumber - 3);
|
|
97
|
-
const endLine = Math.min(lines.length, lineNumber + 2);
|
|
98
|
-
for (let i = startLine; i < endLine; i++) {
|
|
99
|
-
const lineNum = i + 1;
|
|
100
|
-
const line = lines[i];
|
|
101
|
-
const isErrorLine = lineNum === lineNumber;
|
|
102
|
-
formatted += `${lineNum.toString().padStart(3)} | ${line}\n`;
|
|
103
|
-
if (isErrorLine && column > 0) {
|
|
104
|
-
const pointer = ' '.repeat(column + 5) + '^';
|
|
105
|
-
formatted += pointer + '\n';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return formatted;
|
|
109
|
-
};
|
|
110
|
-
const reset = () => {
|
|
111
|
-
state.suiteHierarchy = [];
|
|
112
|
-
state.testResults.clear();
|
|
113
|
-
state.fileStartTime = 0;
|
|
114
|
-
state.currentTest = undefined;
|
|
115
|
-
};
|
|
116
|
-
return {
|
|
117
|
-
handleBridgeEvent,
|
|
118
|
-
reset,
|
|
119
|
-
};
|
|
120
|
-
};
|
package/dist/global-setup.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-setup.d.ts","sourceRoot":"","sources":["../src/global-setup.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AA4CxD,yBAA+B,YAAY,EAAE,UAAU,CAAC,YAAY,iBA4CnE"}
|
package/dist/global-setup.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { getConfig, } from '@react-native-harness/config';
|
|
2
|
-
import { getHarness as getHarnessExternal, NoRunnerSpecifiedError, RunnerNotFoundError, } from '@react-native-harness/cli/external';
|
|
3
|
-
import { preRunMessage } from 'jest-util';
|
|
4
|
-
import { getAdditionalCliArgs } from './cli-args.js';
|
|
5
|
-
import { logTestEnvironmentReady, logTestRunHeader } from './logs.js';
|
|
6
|
-
const getHarnessConfig = async (globalConfig) => {
|
|
7
|
-
const projectRoot = globalConfig.rootDir;
|
|
8
|
-
const { config: harnessConfig } = await getConfig(projectRoot);
|
|
9
|
-
return harnessConfig;
|
|
10
|
-
};
|
|
11
|
-
const getHarnessRunner = (config, cliArgs) => {
|
|
12
|
-
const selectedRunnerName = cliArgs.harnessRunner ?? config.defaultRunner;
|
|
13
|
-
if (!selectedRunnerName) {
|
|
14
|
-
throw new NoRunnerSpecifiedError(config.runners);
|
|
15
|
-
}
|
|
16
|
-
const runner = config.runners.find((runner) => runner.name === selectedRunnerName);
|
|
17
|
-
if (!runner) {
|
|
18
|
-
throw new RunnerNotFoundError(selectedRunnerName, config.runners);
|
|
19
|
-
}
|
|
20
|
-
return runner;
|
|
21
|
-
};
|
|
22
|
-
const getHarness = async (runner) => {
|
|
23
|
-
return await getHarnessExternal(runner);
|
|
24
|
-
};
|
|
25
|
-
export default async function (globalConfig) {
|
|
26
|
-
preRunMessage.remove(process.stderr);
|
|
27
|
-
const harnessConfig = global.HARNESS_CONFIG ?? (await getHarnessConfig(globalConfig));
|
|
28
|
-
const isWatchMode = globalConfig.watch || globalConfig.watchAll;
|
|
29
|
-
if (global.HARNESS) {
|
|
30
|
-
// Do not setup again if HARNESS is already initialized
|
|
31
|
-
// This is useful when running tests in watch mode
|
|
32
|
-
if (harnessConfig.resetEnvironmentBetweenTestFiles) {
|
|
33
|
-
// In watch mode, we want to restart the environment before each test run
|
|
34
|
-
await new Promise((resolve) => {
|
|
35
|
-
global.HARNESS.bridge.once('ready', resolve);
|
|
36
|
-
global.HARNESS.environment.restart();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (isWatchMode) {
|
|
42
|
-
// In watch mode, we want to dispose the Harness when the process exits.
|
|
43
|
-
process.on('exit', async () => {
|
|
44
|
-
await global.HARNESS.bridge.dispose();
|
|
45
|
-
await global.HARNESS.environment.dispose();
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const cliArgs = getAdditionalCliArgs();
|
|
49
|
-
const selectedRunner = getHarnessRunner(harnessConfig, cliArgs);
|
|
50
|
-
if (globalConfig.collectCoverage) {
|
|
51
|
-
// This is going to be used by @react-native-harness/babel-preset
|
|
52
|
-
// to enable instrumentation of test files.
|
|
53
|
-
process.env.RN_HARNESS_COLLECT_COVERAGE = 'true';
|
|
54
|
-
}
|
|
55
|
-
logTestRunHeader(selectedRunner);
|
|
56
|
-
const harness = await getHarness(selectedRunner);
|
|
57
|
-
logTestEnvironmentReady(selectedRunner);
|
|
58
|
-
global.HARNESS_CONFIG = harnessConfig;
|
|
59
|
-
global.HARNESS = harness;
|
|
60
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-teardown.d.ts","sourceRoot":"","sources":["../src/global-teardown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAExD,yBAA+B,YAAY,EAAE,UAAU,CAAC,YAAY,iBAYnE"}
|
package/dist/global-teardown.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default async function (globalConfig) {
|
|
2
|
-
const isWatchMode = globalConfig.watch || globalConfig.watchAll;
|
|
3
|
-
if (isWatchMode) {
|
|
4
|
-
// In watch mode, we don't want to dispose the Harness.
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
if (global.HARNESS) {
|
|
8
|
-
await global.HARNESS.bridge.dispose();
|
|
9
|
-
await global.HARNESS.environment.dispose();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseReporter } from '@jest/reporters';
|
|
2
|
-
import { Config } from '@jest/types';
|
|
3
|
-
export default class HarnessReporter extends BaseReporter {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(globalConfig: Config.GlobalConfig);
|
|
6
|
-
onRunStart(): void;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=harness-reporter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"harness-reporter.d.ts","sourceRoot":"","sources":["../src/harness-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,YAAY;;gBAE3C,YAAY,EAAE,MAAM,CAAC,YAAY;IAKpC,UAAU,IAAI,IAAI;CAM5B"}
|
package/dist/harness-reporter.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseReporter } from '@jest/reporters';
|
|
2
|
-
export default class HarnessReporter extends BaseReporter {
|
|
3
|
-
#globalConfig;
|
|
4
|
-
constructor(globalConfig) {
|
|
5
|
-
super();
|
|
6
|
-
this.#globalConfig = globalConfig;
|
|
7
|
-
}
|
|
8
|
-
onRunStart() {
|
|
9
|
-
super.onRunStart();
|
|
10
|
-
this.log(`Selected runner: ${this.#globalConfig.selectedRunner.name}`);
|
|
11
|
-
}
|
|
12
|
-
}
|
package/dist/jest-options.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest-options.d.ts","sourceRoot":"","sources":["../src/jest-options.ts"],"names":[],"mappings":""}
|
package/dist/jest-options.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TestContext, TestResult } from '@jest/test-result';
|
|
2
|
-
import type { Config, TestRunnerOptions } from 'jest-runner';
|
|
3
|
-
import type { CustomEnvironment } from '@react-native-harness/cli';
|
|
4
|
-
export type RunTestOptions<ExtraOptions extends Record<string, unknown> = Record<string, unknown>> = {
|
|
5
|
-
config: Config.ProjectConfig;
|
|
6
|
-
extraOptions: ExtraOptions;
|
|
7
|
-
globalConfig: Config.GlobalConfig;
|
|
8
|
-
rawModuleMap: ReturnType<TestContext['moduleMap']['getRawModuleMap']> | null;
|
|
9
|
-
options: TestRunnerOptions;
|
|
10
|
-
testPath: string;
|
|
11
|
-
};
|
|
12
|
-
export type RunTest<ExtraOptions extends Record<string, unknown> = Record<string, unknown>> = (options: RunTestOptions<ExtraOptions>, environment: CustomEnvironment) => TestResult | Promise<TestResult>;
|
|
13
|
-
export interface TestDetail {
|
|
14
|
-
title: string;
|
|
15
|
-
path: string;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACpE;IACF,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC;IAClC,YAAY,EAAE,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,iBAAiB,CAAC,CAAC,GAAG,IAAI,CAAC;IAC7E,OAAO,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,OAAO,CACjB,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACpE,CACF,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,WAAW,EAAE,iBAAiB,KAC3B,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/crash-monitor.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { HarnessPlatformRunner } from '@react-native-harness/platforms';
|
|
2
|
-
import { BridgeServer } from '@react-native-harness/bridge/server';
|
|
3
|
-
import { NativeCrashError } from './errors.js';
|
|
4
|
-
import { logger } from '@react-native-harness/tools';
|
|
5
|
-
|
|
6
|
-
export type CrashMonitor = {
|
|
7
|
-
startMonitoring(testFilePath: string): Promise<never>;
|
|
8
|
-
stopMonitoring(): void;
|
|
9
|
-
markIntentionalRestart(): void;
|
|
10
|
-
clearIntentionalRestart(): void;
|
|
11
|
-
dispose(): void;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type CrashMonitorOptions = {
|
|
15
|
-
interval: number;
|
|
16
|
-
platformRunner: HarnessPlatformRunner;
|
|
17
|
-
bridgeServer: BridgeServer;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const createCrashMonitor = ({
|
|
21
|
-
interval,
|
|
22
|
-
platformRunner,
|
|
23
|
-
bridgeServer,
|
|
24
|
-
}: CrashMonitorOptions): CrashMonitor => {
|
|
25
|
-
let pollingInterval: NodeJS.Timeout | null = null;
|
|
26
|
-
let isIntentionalRestart = false;
|
|
27
|
-
let currentTestFilePath: string | null = null;
|
|
28
|
-
let rejectFn: ((error: NativeCrashError) => void) | null = null;
|
|
29
|
-
|
|
30
|
-
const handleDisconnect = () => {
|
|
31
|
-
// Verify if it's actually a crash by checking if app is still running
|
|
32
|
-
if (!isIntentionalRestart && currentTestFilePath) {
|
|
33
|
-
// Capture the value to avoid it being null when setTimeout callback runs
|
|
34
|
-
const testFilePath = currentTestFilePath;
|
|
35
|
-
logger.debug('Bridge disconnected, checking if app crashed');
|
|
36
|
-
// Use a slight delay to allow the OS to clean up the process
|
|
37
|
-
setTimeout(async () => {
|
|
38
|
-
const isRunning = await platformRunner.isAppRunning();
|
|
39
|
-
if (!isRunning && !isIntentionalRestart && rejectFn) {
|
|
40
|
-
logger.debug(`Native crash detected during: ${testFilePath}`);
|
|
41
|
-
rejectFn(new NativeCrashError(testFilePath));
|
|
42
|
-
}
|
|
43
|
-
}, 100);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const startMonitoring = (testFilePath: string): Promise<never> => {
|
|
48
|
-
currentTestFilePath = testFilePath;
|
|
49
|
-
|
|
50
|
-
return new Promise<never>((_, reject) => {
|
|
51
|
-
rejectFn = reject;
|
|
52
|
-
|
|
53
|
-
// Listen for bridge disconnect as early indicator
|
|
54
|
-
bridgeServer.on('disconnect', handleDisconnect);
|
|
55
|
-
|
|
56
|
-
// Poll for app running status
|
|
57
|
-
pollingInterval = setInterval(async () => {
|
|
58
|
-
// Skip check during intentional restarts
|
|
59
|
-
if (isIntentionalRestart) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const isRunning = await platformRunner.isAppRunning();
|
|
65
|
-
|
|
66
|
-
if (!isRunning && currentTestFilePath) {
|
|
67
|
-
logger.debug(
|
|
68
|
-
`Native crash detected during: ${currentTestFilePath}`
|
|
69
|
-
);
|
|
70
|
-
stopMonitoring();
|
|
71
|
-
reject(new NativeCrashError(currentTestFilePath));
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
logger.error('Error checking app status:', error);
|
|
75
|
-
}
|
|
76
|
-
}, interval);
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const stopMonitoring = () => {
|
|
81
|
-
if (pollingInterval) {
|
|
82
|
-
clearInterval(pollingInterval);
|
|
83
|
-
pollingInterval = null;
|
|
84
|
-
}
|
|
85
|
-
bridgeServer.off('disconnect', handleDisconnect);
|
|
86
|
-
currentTestFilePath = null;
|
|
87
|
-
rejectFn = null;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const markIntentionalRestart = () => {
|
|
91
|
-
isIntentionalRestart = true;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const clearIntentionalRestart = () => {
|
|
95
|
-
isIntentionalRestart = false;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const dispose = () => {
|
|
99
|
-
stopMonitoring();
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
startMonitoring,
|
|
104
|
-
stopMonitoring,
|
|
105
|
-
markIntentionalRestart,
|
|
106
|
-
clearIntentionalRestart,
|
|
107
|
-
dispose,
|
|
108
|
-
};
|
|
109
|
-
};
|