Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/cli/src/commands/react-native/xcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ function runWrappedBuild(

const status = runScript(script, scriptArgs, env);

const report = JSON.parse(
readFileSync(reportPath, "utf-8")
) as SourceMapReport;
let report: SourceMapReport;
try {
report = JSON.parse(readFileSync(reportPath, "utf-8")) as SourceMapReport;
} catch (error) {
log.debug("Failed to read sourcemap report file", error);
return { status, pair: null };
}
if (!(report.packager_bundle_path && report.packager_sourcemap_path)) {
return { status, pair: null };
}
Expand Down
39 changes: 39 additions & 0 deletions packages/cli/test/commands/react-native/xcode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,45 @@ describe("react-native xcode", () => {
expect(sourcemaps.uploadSourcemaps).not.toHaveBeenCalled();
});

test.each([
["missing", 0],
["missing", 7],
["malformed", 0],
["malformed", 7],
] as const)("skips upload for a %s report and preserves build status %i", async (reportState, status) => {
spawnMock.mockImplementation(
(
_cmd: string,
_args: readonly string[] | undefined,
spawnOpts?: { env?: NodeJS.ProcessEnv }
) => {
const reportPath = spawnOpts?.env?.SENTRY_RN_SOURCEMAP_REPORT;
if (reportPath) {
if (reportState === "missing") {
rmSync(reportPath);
} else {
writeFileSync(reportPath, '{"packager_bundle_path":');
}
}
return {
status,
stdout: "",
stderr: "",
pid: 1,
output: [],
signal: null,
};
}
);

const ctx = createContext({ CONFIGURATION: "Release" });
const func = await xcodeCommand.loader();
await func.call(ctx, { "build-script": script });

expect(ctx.process.exitCode).toBe(status === 0 ? undefined : status);
expect(sourcemaps.uploadSourcemaps).not.toHaveBeenCalled();
});

test("warns and skips upload when the build produced no sourcemaps", async () => {
spawnMock.mockImplementation(
(
Expand Down
Loading