From 0060a00fc07915c91b1b8e21387a74689da97f1a Mon Sep 17 00:00:00 2001 From: EmmaYuan1015 Date: Wed, 28 Oct 2026 11:12:23 +0800 Subject: [PATCH] Fix Clean Restart Packager progress step count Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../commands/cleanRestartPackager.ts | 8 +++--- .../commands/cleanRestartPackager.test.ts | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/extension/commands/cleanRestartPackager.ts b/src/extension/commands/cleanRestartPackager.ts index ebfbbb4d4..9d4b8eab1 100644 --- a/src/extension/commands/cleanRestartPackager.ts +++ b/src/extension/commands/cleanRestartPackager.ts @@ -42,14 +42,14 @@ export class CleanRestartPackager extends ReactNativeCommand { await this.cleanWatchmanCache(); // Step 4: Restart packager with reset cache - logger.info("Restarting Packager with clean cache..."); + logger.info("Step 4/4: Restarting Packager with clean cache..."); await this.project.getPackager().restart(packagerPort); logger.info("Metro Packager cleanup and restart completed successfully."); } private async killMetroProcess(port: number): Promise { - logger.info(`Step 1/3: Terminating Metro process on port ${port}...`); + logger.info(`Step 1/4: Terminating Metro process on port ${port}...`); try { const platformId = HostPlatform.getPlatformId(); @@ -118,7 +118,7 @@ export class CleanRestartPackager extends ReactNativeCommand { } private async cleanMetroCache(projectPath: string): Promise { - logger.info("Step 2/3: Cleaning Metro cache..."); + logger.info("Step 2/4: Cleaning Metro cache..."); const metroCachePath = path.join(projectPath, "node_modules", ".cache", "metro"); @@ -136,7 +136,7 @@ export class CleanRestartPackager extends ReactNativeCommand { } private async cleanWatchmanCache(): Promise { - logger.info("Step 3/3: Cleaning Watchman cache..."); + logger.info("Step 3/4: Cleaning Watchman cache..."); try { const childProcess = new ChildProcess(); diff --git a/test/extension/commands/cleanRestartPackager.test.ts b/test/extension/commands/cleanRestartPackager.test.ts index ba83b4534..ae7eb81b0 100644 --- a/test/extension/commands/cleanRestartPackager.test.ts +++ b/test/extension/commands/cleanRestartPackager.test.ts @@ -127,6 +127,31 @@ suite("cleanRestartPackagerCommand", function () { removeDirRecursive(tempDir); }); + test("should log all four cleanup and restart steps in order", async function () { + const execStub = Sinon.stub(); + execStub.withArgs("lsof -ti:9090").returns(createExecResult("")); + execStub.withArgs("watchman watch-del-all").returns(createExecResult("")); + const restartStub = Sinon.stub().returns(Promise.resolve()); + const { CleanRestartPackager, logger } = createCommandModule( + HostPlatformId.LINUX, + execStub, + ); + + await runCommand(CleanRestartPackager, tempDir, restartStub); + + const stepMessages = Array.from( + { length: logger.info.callCount }, + (_, index) => logger.info.getCall(index).args[0], + ).filter((message: string) => message.startsWith("Step ")); + assert.deepStrictEqual(stepMessages, [ + "Step 1/4: Terminating Metro process on port 9090...", + "Step 2/4: Cleaning Metro cache...", + "Step 3/4: Cleaning Watchman cache...", + "Step 4/4: Restarting Packager with clean cache...", + ]); + assert.strictEqual(restartStub.calledOnce, true); + }); + test("should kill Metro process on Windows and restart packager", async function () { const execStub = Sinon.stub(); execStub