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
12 changes: 12 additions & 0 deletions src/android/__tests__/expo-templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ describe("app/build.gradle", () => {
});

describe("MainApplication", () => {
it("accepts a trailing comma after the SDK 57 package list", () => {
const template = sdk57MainApplication.replace(
" }\n )",
" },\n )",
);
const result = applyMainApplication(template, "kt");
expect(result).toContain(
" },\n jsBundleFilePath = CodePush.getJSBundleFile()",
);
expect(result).not.toContain(",,");
expect(applyMainApplication(result, "kt")).toBe(result);
});
it("passes the CodePush bundle to the SDK 57 ReactHost factory", () => {
const result = applyMainApplication(sdk57MainApplication, "kt");

Expand Down
12 changes: 12 additions & 0 deletions src/utils/__tests__/insert-last-argument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ describe("insertLastArgument", () => {
);
});

it.each(["", " // keep the comment", " /* keep the comment */"])(
"preserves an existing trailing comma%s",
(comment) => {
const result = insertLastArgument(
`foo(\n a = 1,${comment}\n)`,
"foo",
"b = 2",
);
expect(result).toBe(`foo(\n a = 1,\n b = 2${comment}\n)`);
},
);

it("fills an empty argument list", () => {
expect(insertLastArgument(`foo()`, "foo", "c = 1")).toBe(`foo(c = 1)`);
});
Expand Down
3 changes: 2 additions & 1 deletion src/utils/insert-last-argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ export function insertLastArgument(
const closeIndent = /^[\t ]*/.exec(source.slice(lineStart, closeIndex))?.[0];
const indent = `${closeIndent ?? ""} `;

return `${source.slice(0, endOfArguments)},\n${indent}${argument}${source.slice(endOfArguments)}`;
const separator = source[endOfArguments - 1] === "," ? "" : ",";
return `${source.slice(0, endOfArguments)}${separator}\n${indent}${argument}${source.slice(endOfArguments)}`;
}
Loading