diff --git a/src/cli.ts b/src/cli.ts index 1314801..ae37e4d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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; diff --git a/test/cli.test.ts b/test/cli.test.ts index 9661a36..09dd724 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -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/); +});