From 595b742403d5ddb171d412b9a03582a51565db62 Mon Sep 17 00:00:00 2001 From: huymobile Date: Wed, 26 Aug 2026 12:42:10 +0700 Subject: [PATCH] fix(ios): resolve fallback simulator lazily --- .../runCommand/__tests__/createRun.test.ts | 27 ++++++++++++++++++- .../src/commands/runCommand/createRun.ts | 8 +++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/cli-platform-apple/src/commands/runCommand/__tests__/createRun.test.ts b/packages/cli-platform-apple/src/commands/runCommand/__tests__/createRun.test.ts index d4dd3d9ab..9787316da 100644 --- a/packages/cli-platform-apple/src/commands/runCommand/__tests__/createRun.test.ts +++ b/packages/cli-platform-apple/src/commands/runCommand/__tests__/createRun.test.ts @@ -69,7 +69,7 @@ function buildArgs(overrides: Record = {}) { } as any; } -describe('createRun no-flag default targeting (issue #2765)', () => { +describe('createRun device targeting', () => { let chdirSpy: jest.SpyInstance; beforeEach(() => { @@ -153,6 +153,31 @@ describe('createRun no-flag default targeting (issue #2765)', () => { expect(runOnSimulator).not.toHaveBeenCalled(); }); + test('connected iPhone + --udid -> does not resolve a fallback simulator', async () => { + (listDevices as jest.Mock).mockResolvedValue([physicalDevice]); + (getFallbackSimulator as jest.Mock).mockImplementation(() => { + throw new Error('No simulator available'); + }); + + await createRun({platformName: 'ios'})( + [], + buildCtx(), + buildArgs({udid: physicalDevice.udid}), + ); + + expect(getFallbackSimulator).not.toHaveBeenCalled(); + expect(runOnDevice).toHaveBeenCalledTimes(1); + expect(runOnDevice).toHaveBeenCalledWith( + physicalDevice, + 'ios', + 'Debug', + 'Demo', + expect.anything(), + expect.anything(), + ); + expect(runOnSimulator).not.toHaveBeenCalled(); + }); + test('no devices, no flags -> launches fallback simulator', async () => { (listDevices as jest.Mock).mockResolvedValue([fallbackSimulator]); diff --git a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts index 4a600b1da..2667665b9 100644 --- a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts +++ b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts @@ -209,7 +209,7 @@ const createRun = } } - const fallbackSimulator = + const getFallbackDevice = () => platformName === 'ios' || platformName === 'tvos' ? getFallbackSimulator(args) : devices[0]; @@ -268,7 +268,7 @@ const createRun = ); const connectedDevices = devices.filter(({type}) => type === 'device'); - const targetSimulator = bootedSimulators[0] ?? fallbackSimulator; + const targetSimulator = bootedSimulators[0] ?? getFallbackDevice(); if (bootedSimulators.length === 0) { logger.info( @@ -414,7 +414,7 @@ const createRun = mode, scheme, args, - matchedSimulator ?? fallbackSimulator, + matchedSimulator ?? getFallbackDevice(), ); } else { runOnSimulator( @@ -423,7 +423,7 @@ const createRun = mode, scheme, args, - fallbackSimulator, + getFallbackDevice(), ); } };