Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UT webos devicemanager #1460

Merged
11 commits merged into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app-harness/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const AppContent = () => {
<Image
style={styles.logo}
source={ICON_LOGO}
{...testProps('template-starter-home-screen-renative-image')}
{...testProps('app-harness-home-screen-renative-image')}
/>
<Text style={styles.introText} {...testProps('app-harness-home-screen-intro-text')}>
ReNative Harness
Expand Down
4 changes: 2 additions & 2 deletions packages/app-harness/test/specs/e2e.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Test App Harness', () => {
FlexnRunner.launchApp();
});

it('--> check if element has correct text in Home Page', async () => {
await FlexnRunner.expectToHaveTextById('app-harness-home-screen-intro-text', 'ReNative Harness');
it('--> check if ReNative logo is displayed in Home Page', async () => {
await FlexnRunner.expectToBeDisplayedById('app-harness-home-screen-renative-image');
});
});
2 changes: 2 additions & 0 deletions packages/core/src/context/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('Context tests', () => {
'injectableConfigProps',
'isBuildHooksReady',
'isDefault',
'isSystemLinux',
'isSystemMac',
'isSystemWin',
'logMessages',
'paths',
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/context/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const runtime: RnvContext['runtime'] = {
export const generateContextDefaults = (): RnvContext => ({
isDefault: true,
isSystemWin: false,
isSystemLinux: false,
isSystemMac: false,
logMessages: [],
timeEnd: new Date(),
timeStart: new Date(),
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

if (global.RNV_CONTEXT.paths.rnv.dir !== ctx?.RNV_HOME_DIR) {
// If locations of RNV do not match throw warning as this might produce problems!
console.log(`

Check warning on line 42 in packages/core/src/context/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
=======
WARNING: it seems your project is executed with 2 different versions of RNV:
INITIAL (Will be used) located at: ${global.RNV_CONTEXT.paths.rnv.dir}.
Expand All @@ -62,7 +62,9 @@
c.process = ctx?.process || c.process;
c.command = ctx?.cmd || c.command;
c.subCommand = ctx?.subCmd || c.subCommand;
c.isSystemWin = isSystemWin;
c.isSystemWin = process.platform === 'win32';
c.isSystemLinux = process.platform === 'linux';
c.isSystemMac = process.platform === 'darwin';

c.paths.rnv.dir = ctx?.RNV_HOME_DIR || c.paths.rnv.dir;

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export type RnvContext<Payload = any> = {
runningProcesses: ExecaChildProcess[];
rnvVersion: string;
isSystemWin: boolean;
isSystemLinux: boolean;
isSystemMac: boolean;
_currentTask?: string;
systemPropsInjects: OverridesOptions;
_requiresNpmInstall?: boolean;
Expand Down
104 changes: 104 additions & 0 deletions packages/sdk-webos/src/__tests__/deviceManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { createRnvContext, getContext, getDirectories, getRealPath, inquirerPrompt } from '@rnv/core';
import { launchWebOSimulator } from '../deviceManager';
import * as RnvCore from '@rnv/core';

jest.mock('@rnv/core');
jest.mock('path');

beforeEach(() => {
createRnvContext();
});

afterEach(() => {
jest.resetAllMocks();
});

describe('launchWebOSimulator', () => {
it('should fail if webos SDK path is not defined', async () => {
//GIVEN
const target = true;
const errorMessage = `c.buildConfig.sdks.WEBOS_SDK undefined`;

jest.mocked(getRealPath).mockReturnValue(undefined);

//WHEN & THEN
await expect(launchWebOSimulator(target)).rejects.toBe(errorMessage);
});

it('should give log warning if target not found and resolve', async () => {
//GIVEN
const ctx = getContext();
const target = '';
ctx.isSystemWin = false;
ctx.isSystemMac = true;
ctx.isSystemLinux = false;
jest.mocked(getRealPath).mockReturnValue('mock_webos_SDK_path');
jest.mocked(getDirectories).mockReturnValue(['mock_sim_1', 'mock_sim_2']);
jest.mocked(inquirerPrompt).mockResolvedValue({ selectedSimulator: 'mock_sim_1' });

//WHEN
const result = await launchWebOSimulator(target);

//THEN
expect(RnvCore.logWarning).toHaveBeenCalled();
expect(result).toEqual(true);
});

it('should ask to select sims if no target is specified and run it [macos]', async () => {
//GIVEN
const ctx = getContext();
ctx.isSystemWin = false;
ctx.isSystemMac = true;
ctx.isSystemLinux = false;
const target = true;
jest.mocked(getRealPath).mockReturnValue('mock_webos_SDK_path');
jest.mocked(getDirectories).mockReturnValue(['mock_sim_1', 'mock_sim_2']);

jest.mocked(inquirerPrompt).mockResolvedValue({ selectedSimulator: 'mock_sim_1' });

//WHEN
const result = await launchWebOSimulator(target);

//THEN
expect(result).toEqual(true);
});

it('should ask to select sims if no target is specified and run it [linux]', async () => {
//GIVEN
const ctx = getContext();
ctx.isSystemWin = false;
ctx.isSystemMac = false;
ctx.isSystemLinux = true;
const target = true;
jest.mocked(getRealPath).mockReturnValue('mock_webos_SDK_path');
jest.mocked(getDirectories).mockReturnValue(['mock_sim_1', 'mock_sim_2']);

jest.mocked(inquirerPrompt).mockResolvedValue({ selectedSimulator: 'mock_sim_1' });

//WHEN
const result = await launchWebOSimulator(target);

//THEN
expect(result).toEqual(true);
});

it('should ask to select sims if no target is specified and run it [windows]', async () => {
//GIVEN
const ctx = getContext();
const target = true;
ctx.isSystemWin = true;
ctx.isSystemMac = false;
ctx.isSystemLinux = false;

jest.mocked(getRealPath).mockReturnValue('mock_webos_SDK_path');
jest.mocked(getDirectories).mockReturnValue(['mock_sim_1', 'mock_sim_2']);

jest.mocked(inquirerPrompt).mockResolvedValue({ selectedSimulator: 'mock_sim_1' });

//WHEN
const result = await launchWebOSimulator(target);

//THEN
expect(result).toEqual(true);
});
});
17 changes: 6 additions & 11 deletions packages/sdk-webos/src/deviceManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';
import {
fsExistsSync,
getRealPath,
fsReadFileSync,
getDirectories,
Expand All @@ -14,12 +13,9 @@ import {
logInfo,
logTask,
logWarning,
isSystemWin,
RnvContext,
inquirerPrompt,
ExecOptionsPresets,
isSystemLinux,
isSystemMac,
logError,
logSuccess,
getConfigProp,
Expand Down Expand Up @@ -68,14 +64,13 @@ export const launchWebOSimulator = async (target: string | boolean) => {

const ePath = path.join(
webosSdkPath,
`Simulator/${target}/${target}${isSystemWin ? '.exe' : isSystemLinux ? '.appimage' : '.app'}`
`Simulator/${target}/${target}${c.isSystemWin ? '.exe' : c.isSystemLinux ? '.appimage' : '.app'}`
);

if (!fsExistsSync(ePath)) {
return Promise.reject(`Can't find simulator at path: ${ePath}`);
}
if (isSystemWin || isSystemLinux) {
return executeAsync(ePath, ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY);
if (c.isSystemWin || c.isSystemLinux) {
await executeAsync(ePath, ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY);
logSuccess(`Succesfully launched ${target}`);
return true;
}

await executeAsync(`${openCommand} ${ePath}`, ExecOptionsPresets.FIRE_AND_FORGET);
Expand Down Expand Up @@ -167,7 +162,7 @@ const launchAppOnSimulator = async (c: RnvContext, appPath: string) => {

const regex = /\d+(\.\d+)?/g;
const version = selectedOption.match(regex)[0];
if (isSystemMac) {
if (c.isSystemMac) {
logInfo(
`If you encounter damaged simulator error, run this command line: xattr -c ${simulatorDirPath}/${selectedOption}/${selectedOption}.app`
);
Expand Down
Loading