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
14 changes: 14 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,20 @@ function findMatchingBrace(contents: string, openIndex: number): number {
}
continue;
}
// Comments may contain quotes and braces ("// don't pin a model", "/* { */"), which
// desynced the quote tracker and made onboarding fail on — or rewrite — the wrong block.
if (char === "/" && contents[index + 1] === "/") {
const newline = contents.indexOf("\n", index);
if (newline === -1) return -1;
index = newline;
continue;
}
if (char === "/" && contents[index + 1] === "*") {
const close = contents.indexOf("*/", index + 2);
if (close === -1) return -1;
index = close + 1;
continue;
}
if (char === '"' || char === "'" || char === "`") {
quote = char;
continue;
Expand Down
30 changes: 30 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,33 @@ test("ensureAppiumDriver install failure on iOS points at the full-Xcode require
/full Xcode installed .*xcode-select -p/,
);
});

test("updateConfigAppPath survives comments containing apostrophes and braces", () => {
const contents = `export default defineConfig({
projects: [
{
name: "ios",
platform: "ios",
// don't pin a simulator model, it's auto-selected
/* legacy shape: { "appium:app": "./x.app" } */
capabilities: {
"appium:app": "./old.app",
},
},
{
name: "android",
platform: "android",
// Gradle's debug output lands here
capabilities: {
"appium:app": "./old.apk",
},
},
],
});
`;
const updated = updateConfigAppPath(contents, { platform: "ios", appPath: "./New.app" });
const androidAt = updated.indexOf('"android"');
assert.match(updated.slice(0, androidAt), /"appium:app": "\.\/New\.app"/); // ios block updated
assert.match(updated.slice(androidAt), /"appium:app": "\.\/old\.apk"/); // android untouched
assert.doesNotMatch(updated.slice(androidAt), /New\.app/);
});