@react-native-harness/jest 1.1.0-rc.1 → 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__/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.js +340 -47
- 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.map +1 -1
- package/dist/crash-supervisor.js +7 -6
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -0
- package/dist/harness.d.ts +23 -1
- package/dist/harness.d.ts.map +1 -1
- package/dist/harness.js +396 -50
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -58
- 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 -2
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/__tests__/harness-cache.test.ts +74 -0
- package/src/__tests__/harness.test.ts +469 -51
- package/src/__tests__/index.test.ts +61 -0
- package/src/cli-args.ts +6 -0
- package/src/crash-supervisor.ts +13 -6
- package/src/env.d.ts +1 -1
- package/src/errors.ts +5 -0
- package/src/harness.ts +504 -58
- package/src/index.ts +276 -64
- package/src/logs.ts +4 -0
- package/src/run.ts +20 -10
- package/src/setup.ts +22 -1
- 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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { Harness } from '../harness.js';
|
|
3
|
+
import type { Config as HarnessConfig } from '@react-native-harness/config';
|
|
4
|
+
import type { Config, Test, TestWatcher } from 'jest-runner';
|
|
5
|
+
import JestHarness from '../index.js';
|
|
6
|
+
import { StartupStallError } from '../errors.js';
|
|
7
|
+
|
|
8
|
+
describe('JestHarness', () => {
|
|
9
|
+
it('reports StartupStallError without a stack trace', async () => {
|
|
10
|
+
const runner = new JestHarness({} as Config.GlobalConfig);
|
|
11
|
+
const onFailure = vi.fn();
|
|
12
|
+
|
|
13
|
+
const harness = {
|
|
14
|
+
ensureAppReady: vi
|
|
15
|
+
.fn()
|
|
16
|
+
.mockRejectedValue(new StartupStallError(1500, 3)),
|
|
17
|
+
callHook: vi.fn(async () => undefined),
|
|
18
|
+
setRunState: vi.fn(),
|
|
19
|
+
getRunState: vi.fn(() => null),
|
|
20
|
+
crashSupervisor: {
|
|
21
|
+
beginTestRun: vi.fn(),
|
|
22
|
+
waitForCrash: vi.fn(),
|
|
23
|
+
cancelCrashWaiters: vi.fn(),
|
|
24
|
+
reset: vi.fn(),
|
|
25
|
+
},
|
|
26
|
+
} as unknown as Harness;
|
|
27
|
+
|
|
28
|
+
await runner._createInBandTestRun(
|
|
29
|
+
[
|
|
30
|
+
{
|
|
31
|
+
path: '/tmp/example.harness.ts',
|
|
32
|
+
context: {
|
|
33
|
+
config: {},
|
|
34
|
+
},
|
|
35
|
+
} as Test,
|
|
36
|
+
],
|
|
37
|
+
{
|
|
38
|
+
isInterrupted: () => false,
|
|
39
|
+
} as TestWatcher,
|
|
40
|
+
harness,
|
|
41
|
+
{
|
|
42
|
+
detectNativeCrashes: true,
|
|
43
|
+
resetEnvironmentBetweenTestFiles: false,
|
|
44
|
+
} as HarnessConfig,
|
|
45
|
+
() => Promise.resolve(),
|
|
46
|
+
() => Promise.resolve(),
|
|
47
|
+
onFailure
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(onFailure).toHaveBeenCalledWith(
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
path: '/tmp/example.harness.ts',
|
|
53
|
+
}),
|
|
54
|
+
{
|
|
55
|
+
message:
|
|
56
|
+
'The app did not request its Metro bundle after 3 launch attempts within 1500ms. Last Metro status: unknown.',
|
|
57
|
+
stack: '',
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
});
|
package/src/cli-args.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { hideBin } from 'yargs/helpers';
|
|
|
3
3
|
|
|
4
4
|
export type HarnessCliArgs = {
|
|
5
5
|
harnessRunner?: string;
|
|
6
|
+
metroPort?: number;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export const getAdditionalCliArgs = (): HarnessCliArgs => {
|
|
@@ -11,6 +12,10 @@ export const getAdditionalCliArgs = (): HarnessCliArgs => {
|
|
|
11
12
|
type: 'string',
|
|
12
13
|
description: 'Specify which Harness runner to use',
|
|
13
14
|
})
|
|
15
|
+
.option('metroPort', {
|
|
16
|
+
type: 'number',
|
|
17
|
+
description: 'Override the Metro bundler port',
|
|
18
|
+
})
|
|
14
19
|
.strict(false)
|
|
15
20
|
.help(false)
|
|
16
21
|
.version(false)
|
|
@@ -19,5 +24,6 @@ export const getAdditionalCliArgs = (): HarnessCliArgs => {
|
|
|
19
24
|
|
|
20
25
|
return {
|
|
21
26
|
harnessRunner: argv.harnessRunner,
|
|
27
|
+
metroPort: argv.metroPort,
|
|
22
28
|
};
|
|
23
29
|
};
|
package/src/crash-supervisor.ts
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
} from './errors.js';
|
|
13
13
|
import { logger } from '@react-native-harness/tools';
|
|
14
14
|
|
|
15
|
+
const crashLogger = logger.child('crash');
|
|
16
|
+
|
|
15
17
|
export type CrashSupervisorState =
|
|
16
18
|
| 'idle'
|
|
17
19
|
| 'launching'
|
|
@@ -113,15 +115,20 @@ export const createCrashSupervisor = ({
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
if (!activeTestFilePath) {
|
|
116
|
-
|
|
118
|
+
crashLogger.debug('ignoring crash signal without active test: %s', reason);
|
|
117
119
|
return;
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
isResolvingCrash = true;
|
|
121
|
-
|
|
123
|
+
crashLogger.debug(
|
|
124
|
+
'native crash detected during %s (state=%s reason=%s)',
|
|
125
|
+
activeTestFilePath,
|
|
126
|
+
state,
|
|
127
|
+
reason || '(none)'
|
|
128
|
+
);
|
|
122
129
|
|
|
123
130
|
for (const line of details?.rawLines ?? []) {
|
|
124
|
-
|
|
131
|
+
crashLogger.debug('%s', line);
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
const phase = getCrashPhase(state);
|
|
@@ -136,7 +143,7 @@ export const createCrashSupervisor = ({
|
|
|
136
143
|
});
|
|
137
144
|
|
|
138
145
|
const mergedDetails = mergeCrashDetails(phase, details, enrichedDetails, reason);
|
|
139
|
-
|
|
146
|
+
crashLogger.debug('crash details: %o', {
|
|
140
147
|
phase: mergedDetails.phase,
|
|
141
148
|
source: mergedDetails.source,
|
|
142
149
|
summary: mergedDetails.summary,
|
|
@@ -160,10 +167,10 @@ export const createCrashSupervisor = ({
|
|
|
160
167
|
const isRunning = await platformRunner.isAppRunning();
|
|
161
168
|
|
|
162
169
|
if (!isRunning) {
|
|
163
|
-
handleCrash(reason, details);
|
|
170
|
+
void handleCrash(reason, details);
|
|
164
171
|
}
|
|
165
172
|
} catch (error) {
|
|
166
|
-
|
|
173
|
+
crashLogger.debug('crash confirmation failed', error);
|
|
167
174
|
}
|
|
168
175
|
};
|
|
169
176
|
|
package/src/env.d.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { HarnessError } from '@react-native-harness/tools';
|
|
2
2
|
import type { AppCrashDetails } from '@react-native-harness/platforms';
|
|
3
|
+
export {
|
|
4
|
+
StartupStallError,
|
|
5
|
+
type StartupStallCode,
|
|
6
|
+
type StartupStallDetails,
|
|
7
|
+
} from '@react-native-harness/bundler-metro';
|
|
3
8
|
|
|
4
9
|
export class NoRunnerSpecifiedError extends HarnessError {
|
|
5
10
|
constructor() {
|