Skip to content

Commit 19a911b

Browse files
committed
fix: print crash artifact paths relative to cwd
Add a shared tools formatPath helper and use it when rendering native crash artifact paths in Jest error output.
1 parent c5b6bee commit 19a911b

7 files changed

Lines changed: 89 additions & 24 deletions

File tree

actions/shared/index.cjs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ function getErrorMap() {
633633

634634
// ../../node_modules/zod/dist/esm/v3/helpers/parseUtil.js
635635
var makeIssue = (params) => {
636-
const { data, path: path7, errorMaps, issueData } = params;
637-
const fullPath = [...path7, ...issueData.path || []];
636+
const { data, path: path8, errorMaps, issueData } = params;
637+
const fullPath = [...path8, ...issueData.path || []];
638638
const fullIssue = {
639639
...issueData,
640640
path: fullPath
@@ -750,11 +750,11 @@ var errorUtil;
750750

751751
// ../../node_modules/zod/dist/esm/v3/types.js
752752
var ParseInputLazyPath = class {
753-
constructor(parent, value, path7, key) {
753+
constructor(parent, value, path8, key) {
754754
this._cachedPath = [];
755755
this.parent = parent;
756756
this.data = value;
757-
this._path = path7;
757+
this._path = path8;
758758
this._key = key;
759759
}
760760
get path() {
@@ -4345,14 +4345,17 @@ var HarnessError = class extends Error {
43454345
var import_node_path3 = __toESM(require("path"), 1);
43464346
var import_node_fs3 = __toESM(require("fs"), 1);
43474347

4348+
// ../tools/dist/path.js
4349+
var import_node_path4 = __toESM(require("path"), 1);
4350+
43484351
// ../tools/dist/crash-artifacts.js
43494352
var import_node_fs4 = __toESM(require("fs"), 1);
4350-
var import_node_path4 = __toESM(require("path"), 1);
4351-
var DEFAULT_ARTIFACT_ROOT = import_node_path4.default.join(process.cwd(), ".harness", "crash-reports");
4353+
var import_node_path5 = __toESM(require("path"), 1);
4354+
var DEFAULT_ARTIFACT_ROOT = import_node_path5.default.join(process.cwd(), ".harness", "crash-reports");
43524355

43534356
// ../tools/dist/harness-artifacts.js
43544357
var import_node_fs5 = __toESM(require("fs"), 1);
4355-
var import_node_path5 = __toESM(require("path"), 1);
4358+
var import_node_path6 = __toESM(require("path"), 1);
43564359

43574360
// ../plugins/dist/utils.js
43584361
var isHookTree = (value) => {
@@ -4512,13 +4515,13 @@ var ConfigLoadError = class extends HarnessError {
45124515
};
45134516

45144517
// ../config/dist/reader.js
4515-
var import_node_path6 = __toESM(require("path"), 1);
4518+
var import_node_path7 = __toESM(require("path"), 1);
45164519
var import_node_fs6 = __toESM(require("fs"), 1);
45174520
var import_node_module2 = require("module");
45184521
var import_meta = {};
45194522
var extensions = [".js", ".mjs", ".cjs", ".json"];
45204523
var importUp = async (dir, name) => {
4521-
const filePath = import_node_path6.default.join(dir, name);
4524+
const filePath = import_node_path7.default.join(dir, name);
45224525
for (const ext of extensions) {
45234526
const filePathWithExt = `${filePath}${ext}`;
45244527
if (import_node_fs6.default.existsSync(filePathWithExt)) {
@@ -4539,16 +4542,16 @@ var importUp = async (dir, name) => {
45394542
} catch (error) {
45404543
if (error instanceof ZodError) {
45414544
const validationErrors = error.errors.map((err) => {
4542-
const path7 = err.path.length > 0 ? ` at "${err.path.join(".")}"` : "";
4543-
return `${err.message}${path7}`;
4545+
const path8 = err.path.length > 0 ? ` at "${err.path.join(".")}"` : "";
4546+
return `${err.message}${path8}`;
45444547
});
45454548
throw new ConfigValidationError(filePathWithExt, validationErrors);
45464549
}
45474550
throw error;
45484551
}
45494552
}
45504553
}
4551-
const parentDir = import_node_path6.default.dirname(dir);
4554+
const parentDir = import_node_path7.default.dirname(dir);
45524555
if (parentDir === dir) {
45534556
throw new ConfigNotFoundError(dir);
45544557
}
@@ -4563,7 +4566,7 @@ var getConfig = async (dir) => {
45634566
};
45644567

45654568
// src/shared/index.ts
4566-
var import_node_path7 = __toESM(require("path"));
4569+
var import_node_path8 = __toESM(require("path"));
45674570
var import_node_fs7 = __toESM(require("fs"));
45684571
var getHostAndroidSystemImageArch = () => {
45694572
switch (process.arch) {
@@ -4632,7 +4635,7 @@ var run = async () => {
46324635
if (!runnerInput) {
46334636
throw new Error("Runner input is required");
46344637
}
4635-
const projectRoot = projectRootInput ? import_node_path7.default.resolve(projectRootInput) : process.cwd();
4638+
const projectRoot = projectRootInput ? import_node_path8.default.resolve(projectRootInput) : process.cwd();
46364639
console.info(`Loading React Native Harness config from: ${projectRoot}`);
46374640
const { config, projectRoot: resolvedProjectRoot } = await getConfig(
46384641
projectRoot
@@ -4646,7 +4649,7 @@ var run = async () => {
46464649
throw new Error("GITHUB_OUTPUT environment variable is not set");
46474650
}
46484651
const resolvedRunner = getResolvedRunner(runner);
4649-
const relativeProjectRoot = import_node_path7.default.relative(process.cwd(), resolvedProjectRoot) || ".";
4652+
const relativeProjectRoot = import_node_path8.default.relative(process.cwd(), resolvedProjectRoot) || ".";
46504653
const output = `config=${JSON.stringify(
46514654
resolvedRunner
46524655
)}

packages/jest/src/__tests__/crash-monitor.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it, vi } from 'vitest';
2+
import path from 'node:path';
23
import type {
34
AppSession,
45
AppSessionEvent,
@@ -166,7 +167,10 @@ describe('createCrashMonitor', () => {
166167
'/tmp/.harness/crash-reports/crash-logcat.txt'
167168
);
168169
expect(error.message).toContain(
169-
'Harness extracted the crash log: /tmp/.harness/crash-reports/crash-logcat.txt'
170+
`Harness extracted the crash log: ${path.relative(
171+
process.cwd(),
172+
'/tmp/.harness/crash-reports/crash-logcat.txt'
173+
)}`
170174
);
171175
});
172176

packages/jest/src/__tests__/errors.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2+
import path from 'node:path';
23
import { NativeCrashError, PlatformReadyTimeoutError } from '../errors.js';
34

45
describe('PlatformReadyTimeoutError', () => {
@@ -13,29 +14,48 @@ describe('NativeCrashError', () => {
1314
it('reports the extracted crash log path when available', () => {
1415
const error = new NativeCrashError('/tmp/crash.harness.ts', {
1516
phase: 'execution',
16-
artifactPath: '/tmp/.harness/crash-reports/crash.ips',
17+
artifactPath: path.join(
18+
process.cwd(),
19+
'.harness',
20+
'crash-reports',
21+
'crash.ips'
22+
),
1723
});
1824

1925
expect(error.message).toContain(
20-
'Harness extracted the crash log: /tmp/.harness/crash-reports/crash.ips'
26+
`Harness extracted the crash log: ${path.join(
27+
'.harness',
28+
'crash-reports',
29+
'crash.ips'
30+
)}`
2131
);
2232
});
2333

2434
it('lists enrichment artifact paths when available', () => {
2535
const error = new NativeCrashError('/tmp/crash.harness.ts', {
2636
phase: 'execution',
27-
artifactPath: '/tmp/.harness/crash-reports/logcat.txt',
37+
artifactPath: path.join(
38+
process.cwd(),
39+
'.harness',
40+
'crash-reports',
41+
'logcat.txt'
42+
),
2843
enrichmentArtifacts: [
2944
{
3045
artifactType: 'dropbox-native-crash',
31-
artifactPath: '/tmp/.harness/crash-reports/dropbox-native-crash.txt',
46+
artifactPath: path.join(
47+
process.cwd(),
48+
'.harness',
49+
'crash-reports',
50+
'dropbox-native-crash.txt'
51+
),
3252
},
3353
],
3454
});
3555

3656
expect(error.message).toContain('Additional crash artifacts:');
3757
expect(error.message).toContain(
38-
'/tmp/.harness/crash-reports/dropbox-native-crash.txt'
58+
path.join('.harness', 'crash-reports', 'dropbox-native-crash.txt')
3959
);
4060
});
4161

packages/jest/src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HarnessError } from '@react-native-harness/tools';
1+
import { formatPath, HarnessError } from '@react-native-harness/tools';
22
import type { AppCrashDetails } from '@react-native-harness/platforms';
33
export {
44
StartupStallError,
@@ -79,14 +79,14 @@ const buildNativeCrashMessage = ({
7979

8080
lines.push(
8181
artifactPath
82-
? `Harness extracted the crash log: ${artifactPath}`
82+
? `Harness extracted the crash log: ${formatPath(artifactPath)}`
8383
: "Harness couldn't extract the crash log."
8484
);
8585

8686
if (enrichmentArtifacts && enrichmentArtifacts.length > 0) {
8787
lines.push('Additional crash artifacts:');
8888
for (const artifact of enrichmentArtifacts) {
89-
lines.push(` - ${artifact.artifactPath}`);
89+
lines.push(` - ${formatPath(artifact.artifactPath)}`);
9090
}
9191
}
9292

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, it } from 'vitest';
2+
import path from 'node:path';
3+
import { formatPath } from '../path.js';
4+
5+
describe('formatPath', () => {
6+
it('formats absolute paths relative to the current working directory', () => {
7+
expect(
8+
formatPath(
9+
path.join('/project', '.harness', 'crash-reports', 'log.txt'),
10+
{
11+
cwd: '/project',
12+
}
13+
)
14+
).toBe(path.join('.harness', 'crash-reports', 'log.txt'));
15+
});
16+
17+
it('leaves relative paths unchanged', () => {
18+
expect(formatPath(path.join('.harness', 'crash-reports', 'log.txt'))).toBe(
19+
path.join('.harness', 'crash-reports', 'log.txt')
20+
);
21+
});
22+
23+
it('formats the working directory as a dot', () => {
24+
expect(formatPath('/project', { cwd: '/project' })).toBe('.');
25+
});
26+
});

packages/tools/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './react-native.js';
88
export * from './error.js';
99
export * from './events.js';
1010
export * from './packages.js';
11+
export * from './path.js';
1112
export * from './crash-artifacts.js';
1213
export * from './harness-artifacts.js';
1314
export * from './regex.js';

packages/tools/src/path.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import path from 'node:path';
2+
3+
export type FormatPathOptions = {
4+
cwd?: string;
5+
};
6+
7+
export const formatPath = (
8+
filePath: string,
9+
{ cwd = process.cwd() }: FormatPathOptions = {}
10+
) =>
11+
path.isAbsolute(filePath) ? path.relative(cwd, filePath) || '.' : filePath;

0 commit comments

Comments
 (0)