diff --git a/src/extension/commands/cleanRestartPackager.ts b/src/extension/commands/cleanRestartPackager.ts index a0abbb160..964908b2c 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(); @@ -119,7 +119,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"); @@ -132,7 +132,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 6e8bbd4c0..0f511222f 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