Skip to content

[Feature] Add unit tests for enableExpoHermes app.json manipulation logic #2738

Description

@ConnorQi01

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions