Summary
The EnableExpoHermes command (src/extension/commands/enableExpoHermes.ts) modifies app.json to set the jsEngine field for Expo, Android, or iOS platforms. It has two distinct code paths — a regex-based in-place replacement and a JSON-parse-and-insert path — but currently has no unit test coverage. The regex replacement path has a correctness issue: it detects the platform-specific section using a scoped regex, but then replaces the first "jsEngine" occurrence in the entire file regardless of platform, which can silently update the wrong platform's entry when multiple jsEngine keys are present.
Why this is useful
- Prevents regressions in file manipulation logic, which is hard to spot via type checking alone.
- Surfaces the existing replacement scoping issue so it can be corrected alongside the test.
- Consistent with the recent pattern of adding targeted unit tests for command file-manipulation logic (
setNewArch, enableHermes, installPods).
Suggested scope
- Add a
test/extension/commands/enableExpoHermes.test.ts file covering:
- Expo platform path (JSON-parse path): sets
expo.jsEngine when no existing key
- Android/iOS platform path (JSON-parse path): sets
expo.android.jsEngine / expo.ios.jsEngine
- Regex-update path: updates an existing
jsEngine value in the matched platform section
- Scoping regression: verify updating "Android" does not modify the "iOS" jsEngine value when both exist
- Early return when
app.json is missing
- If the scoping bug is confirmed, fix the replacement regex to scope it to the matched platform block.
Evidence
- Source:
src/extension/commands/enableExpoHermes.ts:46–56 — platform-aware match, but platform-unaware replace
- Comparable test:
test/extension/commands/enableHermes.test.ts (covers Podfile and Gradle edits per platform)
- No existing test file for
enableExpoHermes in test/extension/commands/
Validation
- Run
npm test / mocha unit tests and confirm all new cases pass.
- Manually invoke "Enable Expo Hermes" from the command palette on a project with both
expo.android.jsEngine and expo.ios.jsEngine defined and verify only the selected platform is updated.
Summary
The
EnableExpoHermescommand (src/extension/commands/enableExpoHermes.ts) modifiesapp.jsonto set thejsEnginefield for Expo, Android, or iOS platforms. It has two distinct code paths — a regex-based in-place replacement and a JSON-parse-and-insert path — but currently has no unit test coverage. The regex replacement path has a correctness issue: it detects the platform-specific section using a scoped regex, but then replaces the first"jsEngine"occurrence in the entire file regardless of platform, which can silently update the wrong platform's entry when multiplejsEnginekeys are present.Why this is useful
setNewArch,enableHermes,installPods).Suggested scope
test/extension/commands/enableExpoHermes.test.tsfile covering:expo.jsEnginewhen no existing keyexpo.android.jsEngine/expo.ios.jsEnginejsEnginevalue in the matched platform sectionapp.jsonis missingEvidence
src/extension/commands/enableExpoHermes.ts:46–56— platform-aware match, but platform-unaware replacetest/extension/commands/enableHermes.test.ts(covers Podfile and Gradle edits per platform)enableExpoHermesintest/extension/commands/Validation
npm test/ mocha unit tests and confirm all new cases pass.expo.android.jsEngineandexpo.ios.jsEnginedefined and verify only the selected platform is updated.