From 472624a0541393b3af80aab3814e37a7d33d76e4 Mon Sep 17 00:00:00 2001 From: Justinas Date: Tue, 6 Aug 2024 10:01:59 +0300 Subject: [PATCH 1/9] tizen/tizenwatch/tizenmobile now show different emulators when running target list --- packages/sdk-tizen/src/deviceManager.ts | 50 ++++++++++++++++--- .../sdk-tizen/src/tasks/taskTargetList.ts | 4 +- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index 0d9ea910d..c30f4e67c 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -117,16 +117,52 @@ export const launchTizenSimulator = async (name: string | true): Promise { +export const listTizenTargets = async (platform: string) => { const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); - const emulatorArr = emulatorsString.split('\n'); - // Removed first line because cli gives header ("List of devices attached") before devices list - const deviceArr = devicesString.split('\n').slice(1); + const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators + const specificPlatformEmulators: string[] = []; // tizen, tizenwatch, tizenmobile - only 1 of them + for (let i = 0; i < allDownloadedEmulators.length; i++) { + try { + const detailString = await execCLI(CLI_TIZEN_EMULATOR, 'detail -n ' + allDownloadedEmulators[i]); + if (detailString.includes('Error:')) { + // emulator doesn't exist. Won't ever really happen, but just in case. + // throw new Error(detailString); + throw new Error(detailString); + } + + const detailLines = detailString // turn the command return into array + .split('\n') + .map((line: string) => line.trim()) + .filter((line: string) => line !== ''); + + const detailObj = detailLines.reduce<{ [key: string]: string }>((acc: any, line: string) => { + // make it into a readable object + const [key, ...value] = line.split(':'); + if (key && value) { + acc[key.trim()] = value.join(':').trim(); + } + return acc; + }, {}); + + const TizenEmulatorTemplate = detailObj.Template.toLowerCase(); + if ( + (platform === 'tizen' && TizenEmulatorTemplate.includes('tizen')) || + (platform === 'tizenwatch' && TizenEmulatorTemplate.includes('wearable')) || + (platform === 'tizenmobile' && TizenEmulatorTemplate.includes('mobile')) + ) { + specificPlatformEmulators.push(allDownloadedEmulators[i]); + } + } catch (err) { + console.log(err); + } + } + let targetStr = ''; - const targetArr = emulatorArr.concat(deviceArr); - targetArr.forEach((_, i) => { - targetStr += `[${i}]> ${targetArr[i]}\n`; + const devicesArr = devicesString.split('\n').slice(1); + const finalTargetList = specificPlatformEmulators.concat(devicesArr); + finalTargetList.forEach((_, i) => { + targetStr += `[${i}]> ${finalTargetList[i]}\n`; }); logToSummary(`Tizen Targets:\n${targetStr}`); }; diff --git a/packages/sdk-tizen/src/tasks/taskTargetList.ts b/packages/sdk-tizen/src/tasks/taskTargetList.ts index 697a5777a..b4692ecec 100644 --- a/packages/sdk-tizen/src/tasks/taskTargetList.ts +++ b/packages/sdk-tizen/src/tasks/taskTargetList.ts @@ -6,10 +6,10 @@ import { SdkPlatforms } from '../constants'; export default createTask({ description: 'List all available targets for specific platform', dependsOn: [RnvTaskName.workspaceConfigure], - fn: async () => { + fn: async ({ ctx }) => { await checkAndConfigureTizenSdks(); await checkTizenSdk(); - return listTizenTargets(); + return listTizenTargets(ctx.platform || ''); }, task: RnvTaskName.targetList, options: [RnvTaskOptions.target], From 650789eb59391c302e0ec14c752f7c1e5a723edb Mon Sep 17 00:00:00 2001 From: Justinas Date: Wed, 7 Aug 2024 11:15:44 +0300 Subject: [PATCH 2/9] tests added; target launch command updated --- .../src/__tests__/deviceManager.test.ts | 70 +++++++++++++++++++ packages/sdk-tizen/src/deviceManager.ts | 37 ++++++---- 2 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 packages/sdk-tizen/src/__tests__/deviceManager.test.ts diff --git a/packages/sdk-tizen/src/__tests__/deviceManager.test.ts b/packages/sdk-tizen/src/__tests__/deviceManager.test.ts new file mode 100644 index 000000000..efdf85aed --- /dev/null +++ b/packages/sdk-tizen/src/__tests__/deviceManager.test.ts @@ -0,0 +1,70 @@ +import { createRnvContext, fsExistsSync, getContext } from '@rnv/core'; +import { listTizenTargets } from '../deviceManager'; +import { execCLI, logToSummary } from '@rnv/core'; + +jest.mock('@rnv/core'); + +beforeEach(() => { + createRnvContext(); +}); + +afterEach(() => { + jest.resetAllMocks(); +}); + +describe('DeviceManager', () => { + it('listTizenTargets when calling npx rnv target list -p tizen', async () => { + //GIVEN + const execCLIMock = jest.mocked(execCLI); + execCLIMock + .mockImplementationOnce(() => Promise.resolve('emulatorTizen\nemulatorMobile')) + .mockImplementationOnce(() => Promise.resolve('List of devices attached\ndeviceTizen\ndeviceMobile')) + .mockImplementationOnce(() => Promise.resolve('Template: Tizen')) + .mockImplementationOnce(() => Promise.resolve('Template: Mobile')); + jest.mocked(fsExistsSync).mockReturnValueOnce(true); + //WHEN + await listTizenTargets('tizen'); + //THEN + + const correctResultString = 'Tizen Targets:\n[0]> emulatorTizen\n[1]> deviceTizen\n[2]> deviceMobile\n'; + // right now all of the devices are added to the end, no matter if -p tizen, -p tizenwatch or -p tizenmobile was called + // when the function is updated, update the test as well, because it will fail + expect(logToSummary).toHaveBeenCalledWith(correctResultString); + }); + it('listTizenTargets when calling npx rnv target list -p tizenwatch', async () => { + //GIVEN + const execCLIMock = jest.mocked(execCLI); + execCLIMock + .mockImplementationOnce(() => Promise.resolve('emulatorTizenmobile\nemulatorTizenwatch')) + .mockImplementationOnce(() => Promise.resolve('')) // the return for devices + .mockImplementationOnce(() => Promise.resolve('Template: Tizen')) + .mockImplementationOnce(() => Promise.resolve('Template: Wearable')); + jest.mocked(fsExistsSync).mockReturnValueOnce(true); + //WHEN + await listTizenTargets('tizenwatch'); + //THEN + + const correctResultString = 'Tizen Targets:\n[0]> emulatorTizenwatch\n'; + // right now all of the devices are added to the end, no matter if -p tizen, -p tizenwatch or -p tizenmobile was called + // when the function is updated, update the test as well, because it will fail + expect(logToSummary).toHaveBeenCalledWith(correctResultString); + }); + it('listTizenTargets when calling npx rnv target list -p tizenmobile', async () => { + //GIVEN + const execCLIMock = jest.mocked(execCLI); + execCLIMock + .mockImplementationOnce(() => Promise.resolve('emulatorTizenmobile\nemulatorTizenwatch')) + .mockImplementationOnce(() => Promise.resolve('')) // the return for devices + .mockImplementationOnce(() => Promise.resolve('Template: Mobile')) + .mockImplementationOnce(() => Promise.resolve('Template: Wearable')); + jest.mocked(fsExistsSync).mockReturnValueOnce(true); + //WHEN + await listTizenTargets('tizenmobile'); + //THEN + + const correctResultString = 'Tizen Targets:\n[0]> emulatorTizenmobile\n'; + // right now all of the devices are added to the end, no matter if -p tizen, -p tizenwatch or -p tizenmobile was called + // when the function is updated, update the test as well, because it will fail + expect(logToSummary).toHaveBeenCalledWith(correctResultString); + }); +}); diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index c30f4e67c..bd261b019 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -78,11 +78,16 @@ export const launchTizenSimulator = async (name: string | true): Promise ({ id: line, name: line })); const choices = _composeDevicesString(targetsArray); + const { chosenEmulator } = await inquirerPrompt({ name: 'chosenEmulator', type: 'list', @@ -117,14 +122,12 @@ export const launchTizenSimulator = async (name: string | true): Promise { - const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); - const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); - const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators - const specificPlatformEmulators: string[] = []; // tizen, tizenwatch, tizenmobile - only 1 of them - for (let i = 0; i < allDownloadedEmulators.length; i++) { +const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform: string) => { + // subplatform meaning tizen, tizenwatch or tizenmobile + const specificEmulators = []; + for (let i = 0; i < allTizenEmulators.length; i++) { try { - const detailString = await execCLI(CLI_TIZEN_EMULATOR, 'detail -n ' + allDownloadedEmulators[i]); + const detailString = await execCLI(CLI_TIZEN_EMULATOR, 'detail -n ' + allTizenEmulators[i]); if (detailString.includes('Error:')) { // emulator doesn't exist. Won't ever really happen, but just in case. // throw new Error(detailString); @@ -147,16 +150,24 @@ export const listTizenTargets = async (platform: string) => { const TizenEmulatorTemplate = detailObj.Template.toLowerCase(); if ( - (platform === 'tizen' && TizenEmulatorTemplate.includes('tizen')) || - (platform === 'tizenwatch' && TizenEmulatorTemplate.includes('wearable')) || - (platform === 'tizenmobile' && TizenEmulatorTemplate.includes('mobile')) + (neededPlatform === 'tizen' && TizenEmulatorTemplate.includes('tizen')) || + (neededPlatform === 'tizenwatch' && TizenEmulatorTemplate.includes('wearable')) || + (neededPlatform === 'tizenmobile' && TizenEmulatorTemplate.includes('mobile')) ) { - specificPlatformEmulators.push(allDownloadedEmulators[i]); + specificEmulators.push(allTizenEmulators[i]); } } catch (err) { console.log(err); } } + return specificEmulators; +}; + +export const listTizenTargets = async (platform: string) => { + const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); + const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); + const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators + const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators, platform); // tizen, tizenwatch, tizenmobile - only 1 of them let targetStr = ''; const devicesArr = devicesString.split('\n').slice(1); From 1ee10c01ef858354ed787f3e34e68db6e588af4c Mon Sep 17 00:00:00 2001 From: Justinas Date: Wed, 7 Aug 2024 11:53:24 +0300 Subject: [PATCH 3/9] small fix --- packages/sdk-tizen/src/deviceManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index bd261b019..f7badc4ab 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -81,7 +81,7 @@ export const launchTizenSimulator = async (name: string | true): Promise Date: Wed, 7 Aug 2024 12:33:33 +0300 Subject: [PATCH 4/9] unnecessary import removed --- packages/sdk-tizen/src/__tests__/deviceManager.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-tizen/src/__tests__/deviceManager.test.ts b/packages/sdk-tizen/src/__tests__/deviceManager.test.ts index efdf85aed..1aacf9e75 100644 --- a/packages/sdk-tizen/src/__tests__/deviceManager.test.ts +++ b/packages/sdk-tizen/src/__tests__/deviceManager.test.ts @@ -1,4 +1,4 @@ -import { createRnvContext, fsExistsSync, getContext } from '@rnv/core'; +import { createRnvContext, fsExistsSync } from '@rnv/core'; import { listTizenTargets } from '../deviceManager'; import { execCLI, logToSummary } from '@rnv/core'; From 192f1c97d9421bc6c28b0f9fef63fd4aaac1224a Mon Sep 17 00:00:00 2001 From: Justinas Date: Thu, 8 Aug 2024 08:46:53 +0300 Subject: [PATCH 5/9] a quick test for real devices --- packages/sdk-tizen/src/deviceManager.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index f7badc4ab..556dec195 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -166,11 +166,13 @@ const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform export const listTizenTargets = async (platform: string) => { const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); - const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators - const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators, platform); // tizen, tizenwatch, tizenmobile - only 1 of them + const devicesArr = devicesString.split('\n').slice(1); + const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators + const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators.concat(devicesArr), platform); // tizen, tizenwatch, tizenmobile - only 1 of them + console.log('REAL DEVICES:'); + console.log(devicesArr); let targetStr = ''; - const devicesArr = devicesString.split('\n').slice(1); const finalTargetList = specificPlatformEmulators.concat(devicesArr); finalTargetList.forEach((_, i) => { targetStr += `[${i}]> ${finalTargetList[i]}\n`; From 046193cbae93248e9033ddb470c029fc72fce2f5 Mon Sep 17 00:00:00 2001 From: Justinas Date: Thu, 8 Aug 2024 08:50:37 +0300 Subject: [PATCH 6/9] a quick test for real devices --- packages/sdk-tizen/src/deviceManager.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index 556dec195..f7badc4ab 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -166,13 +166,11 @@ const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform export const listTizenTargets = async (platform: string) => { const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); - const devicesArr = devicesString.split('\n').slice(1); - const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators - const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators.concat(devicesArr), platform); // tizen, tizenwatch, tizenmobile - only 1 of them - console.log('REAL DEVICES:'); - console.log(devicesArr); + const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators, platform); // tizen, tizenwatch, tizenmobile - only 1 of them + let targetStr = ''; + const devicesArr = devicesString.split('\n').slice(1); const finalTargetList = specificPlatformEmulators.concat(devicesArr); finalTargetList.forEach((_, i) => { targetStr += `[${i}]> ${finalTargetList[i]}\n`; From 47d9b7449f75da3b495f40e24ab04c17f8512c4c Mon Sep 17 00:00:00 2001 From: Justinas Date: Thu, 8 Aug 2024 08:50:54 +0300 Subject: [PATCH 7/9] a quick test for real devices --- packages/sdk-tizen/src/deviceManager.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index f7badc4ab..eee4c2447 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -128,6 +128,8 @@ const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform for (let i = 0; i < allTizenEmulators.length; i++) { try { const detailString = await execCLI(CLI_TIZEN_EMULATOR, 'detail -n ' + allTizenEmulators[i]); + console.log('details:'); + console.log(detailString); if (detailString.includes('Error:')) { // emulator doesn't exist. Won't ever really happen, but just in case. // throw new Error(detailString); @@ -166,11 +168,13 @@ const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform export const listTizenTargets = async (platform: string) => { const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); - const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators - const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators, platform); // tizen, tizenwatch, tizenmobile - only 1 of them + const devicesArr = devicesString.split('\n').slice(1); + const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators + const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators.concat(devicesArr), platform); // tizen, tizenwatch, tizenmobile - only 1 of them + console.log('REAL DEVICES:'); + console.log(devicesArr); let targetStr = ''; - const devicesArr = devicesString.split('\n').slice(1); const finalTargetList = specificPlatformEmulators.concat(devicesArr); finalTargetList.forEach((_, i) => { targetStr += `[${i}]> ${finalTargetList[i]}\n`; From 37e7002078ef3ee017535ccd1598f0f344dee61c Mon Sep 17 00:00:00 2001 From: Justinas Date: Wed, 14 Aug 2024 10:07:07 +0300 Subject: [PATCH 8/9] more tests; small change in deivceManager --- .../src/__tests__/deviceManager.test.ts | 113 ++++++++++++++++-- packages/sdk-tizen/src/deviceManager.ts | 11 +- 2 files changed, 105 insertions(+), 19 deletions(-) diff --git a/packages/sdk-tizen/src/__tests__/deviceManager.test.ts b/packages/sdk-tizen/src/__tests__/deviceManager.test.ts index 1aacf9e75..71004e0bb 100644 --- a/packages/sdk-tizen/src/__tests__/deviceManager.test.ts +++ b/packages/sdk-tizen/src/__tests__/deviceManager.test.ts @@ -1,20 +1,33 @@ -import { createRnvContext, fsExistsSync } from '@rnv/core'; -import { listTizenTargets } from '../deviceManager'; -import { execCLI, logToSummary } from '@rnv/core'; +import { + createRnvContext, + fsExistsSync, + execCLI, + executeAsync, + logToSummary, + getContext, + logDefault, + logError, + inquirerPrompt, + ExecOptionsPresets, +} from '@rnv/core'; +import { listTizenTargets, launchTizenSimulator } from '../deviceManager'; +import { CLI_TIZEN_EMULATOR, CLI_SDB_TIZEN } from '../constants'; + +const ERROR_MSG = { + UNKNOWN_VM: 'does not match any VM', + ALREADY_RUNNING: 'is running now', +}; jest.mock('@rnv/core'); beforeEach(() => { - createRnvContext(); -}); - -afterEach(() => { - jest.resetAllMocks(); + jest.clearAllMocks(); }); -describe('DeviceManager', () => { +describe('listTizenTargets', () => { it('listTizenTargets when calling npx rnv target list -p tizen', async () => { //GIVEN + createRnvContext(); const execCLIMock = jest.mocked(execCLI); execCLIMock .mockImplementationOnce(() => Promise.resolve('emulatorTizen\nemulatorMobile')) @@ -34,6 +47,7 @@ describe('DeviceManager', () => { it('listTizenTargets when calling npx rnv target list -p tizenwatch', async () => { //GIVEN const execCLIMock = jest.mocked(execCLI); + createRnvContext(); execCLIMock .mockImplementationOnce(() => Promise.resolve('emulatorTizenmobile\nemulatorTizenwatch')) .mockImplementationOnce(() => Promise.resolve('')) // the return for devices @@ -52,6 +66,7 @@ describe('DeviceManager', () => { it('listTizenTargets when calling npx rnv target list -p tizenmobile', async () => { //GIVEN const execCLIMock = jest.mocked(execCLI); + createRnvContext(); execCLIMock .mockImplementationOnce(() => Promise.resolve('emulatorTizenmobile\nemulatorTizenwatch')) .mockImplementationOnce(() => Promise.resolve('')) // the return for devices @@ -68,3 +83,83 @@ describe('DeviceManager', () => { expect(logToSummary).toHaveBeenCalledWith(correctResultString); }); }); + +describe('launchTizenSimulator', () => { + it('should launch the specified emulator by name', async () => { + const mockContext = { cli: { [CLI_TIZEN_EMULATOR]: 'tizen-emulator' }, platform: 'tizen' }; + const ctx = { ...getContext(), ...mockContext }; + createRnvContext(ctx); + + (executeAsync as jest.Mock).mockResolvedValue(true); + + const result = await launchTizenSimulator('emulatorName'); + + expect(logDefault).toHaveBeenCalledWith('launchTizenSimulator:emulatorName'); + expect(executeAsync).toHaveBeenCalledWith( + 'tizen-emulator launch --name emulatorName', + ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY + ); + expect(result).toBe(true); + }); + it('should prompt the user to choose an emulator if name is true', async () => { + const mockContext = { cli: { [CLI_TIZEN_EMULATOR]: 'tizen-emulator' }, platform: 'tizen' }; + const ctx = { ...getContext(), ...mockContext }; + createRnvContext(ctx); + + (execCLI as jest.Mock).mockResolvedValueOnce('emulator1\nemulator2').mockResolvedValueOnce('device1\ndevice2'); + (inquirerPrompt as jest.Mock).mockResolvedValue({ chosenEmulator: 'emulator1' }); + (executeAsync as jest.Mock).mockResolvedValue(true); + const result = await launchTizenSimulator(true); + expect(execCLI).toHaveBeenCalledWith(CLI_TIZEN_EMULATOR, 'list-vm'); + expect(execCLI).toHaveBeenCalledWith(CLI_SDB_TIZEN, 'devices'); + expect(inquirerPrompt).toHaveBeenCalledWith({ + name: 'chosenEmulator', + type: 'list', + message: 'What emulator would you like to launch?', + choices: expect.any(Array), + }); + expect(executeAsync).toHaveBeenCalledWith( + 'tizen-emulator launch --name emulator1', + ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY + ); + expect(result).toBe(true); + }); + it('should handle unknown VM error and retry with prompt', async () => { + const mockContext = { cli: { [CLI_TIZEN_EMULATOR]: 'tizen-emulator' }, platform: 'tizen' }; + const ctx = { ...getContext(), ...mockContext }; + createRnvContext(ctx); + + (executeAsync as jest.Mock).mockRejectedValueOnce(ERROR_MSG.UNKNOWN_VM); + (execCLI as jest.Mock).mockResolvedValueOnce('emulator1\nemulator2').mockResolvedValueOnce('device1\ndevice2'); + (inquirerPrompt as jest.Mock).mockResolvedValue({ chosenEmulator: 'emulator1' }); + (executeAsync as jest.Mock).mockResolvedValue(true); + const result = await launchTizenSimulator('unknownEmulator'); + expect(logError).toHaveBeenCalledWith('The VM "unknownEmulator" does not exist.'); + expect(execCLI).toHaveBeenCalledWith(CLI_TIZEN_EMULATOR, 'list-vm'); + expect(execCLI).toHaveBeenCalledWith(CLI_SDB_TIZEN, 'devices'); + expect(inquirerPrompt).toHaveBeenCalledWith({ + name: 'chosenEmulator', + type: 'list', + message: 'What emulator would you like to launch?', + choices: expect.any(Array), + }); + expect(executeAsync).toHaveBeenCalledWith( + 'tizen-emulator launch --name emulator1', + ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY + ); + expect(result).toBe(true); + }); + it('should handle already running VM error and return true', async () => { + const mockContext = { cli: { [CLI_TIZEN_EMULATOR]: 'tizen-emulator' }, platform: 'tizen' }; + const ctx = { ...getContext(), ...mockContext }; + createRnvContext(ctx); + + (executeAsync as jest.Mock).mockRejectedValueOnce(ERROR_MSG.ALREADY_RUNNING); + const result = await launchTizenSimulator('runningEmulator'); + expect(logError).toHaveBeenCalledWith('The VM "runningEmulator" is already running.'); + expect(result).toBe(true); + }); + it('should reject if no name is specified', async () => { + await expect(launchTizenSimulator('')).rejects.toEqual('No simulator -t target name specified!'); + }); +}); diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index eee4c2447..cbee5df68 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -128,13 +128,7 @@ const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform for (let i = 0; i < allTizenEmulators.length; i++) { try { const detailString = await execCLI(CLI_TIZEN_EMULATOR, 'detail -n ' + allTizenEmulators[i]); - console.log('details:'); - console.log(detailString); - if (detailString.includes('Error:')) { - // emulator doesn't exist. Won't ever really happen, but just in case. - // throw new Error(detailString); - throw new Error(detailString); - } + if (detailString === undefined) continue; const detailLines = detailString // turn the command return into array .split('\n') @@ -169,11 +163,8 @@ export const listTizenTargets = async (platform: string) => { const emulatorsString = await execCLI(CLI_TIZEN_EMULATOR, 'list-vm'); const devicesString = await execCLI(CLI_SDB_TIZEN, 'devices'); const devicesArr = devicesString.split('\n').slice(1); - const allDownloadedEmulators = emulatorsString.split('\n'); // all tizen, tizenwatch and tizenmobile emulators const specificPlatformEmulators = await getSubplatformDevices(allDownloadedEmulators.concat(devicesArr), platform); // tizen, tizenwatch, tizenmobile - only 1 of them - console.log('REAL DEVICES:'); - console.log(devicesArr); let targetStr = ''; const finalTargetList = specificPlatformEmulators.concat(devicesArr); finalTargetList.forEach((_, i) => { From 1a9b1868ae7d6dbef75e351c60b056bcaa9afaf0 Mon Sep 17 00:00:00 2001 From: Justinas Date: Fri, 16 Aug 2024 11:14:51 +0300 Subject: [PATCH 9/9] tvs addition --- packages/sdk-tizen/src/deviceManager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/sdk-tizen/src/deviceManager.ts b/packages/sdk-tizen/src/deviceManager.ts index cbee5df68..6e4060307 100644 --- a/packages/sdk-tizen/src/deviceManager.ts +++ b/packages/sdk-tizen/src/deviceManager.ts @@ -146,7 +146,8 @@ const getSubplatformDevices = async (allTizenEmulators: string[], neededPlatform const TizenEmulatorTemplate = detailObj.Template.toLowerCase(); if ( - (neededPlatform === 'tizen' && TizenEmulatorTemplate.includes('tizen')) || + (neededPlatform === 'tizen' && + (TizenEmulatorTemplate.includes('tizen') || TizenEmulatorTemplate.includes('tv'))) || (neededPlatform === 'tizenwatch' && TizenEmulatorTemplate.includes('wearable')) || (neededPlatform === 'tizenmobile' && TizenEmulatorTemplate.includes('mobile')) ) {