Skip to content

Commit

Permalink
update UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
pavjacko committed Oct 3, 2023
1 parent 73a8312 commit 7e388b5
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 167 deletions.
259 changes: 259 additions & 0 deletions __mocks__/@rnv/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,203 @@ const _chalkMono = {
..._chalkCols,
};

export const generateRnvConfigPathObj = () => {
return {
configs: [],
configsPrivate: [],
configsLocal: [],
appConfigsDir: '',
config: '',
configLocal: '',
configPrivate: '',
dir: '',
dirs: [],
fontsDir: '',
fontsDirs: [],
pluginDirs: [],
};
};

export const generateRnvConfigFileObj = () => {
return {
configs: [],
configsLocal: [],
configsPrivate: [],
};
};

const runtime: any = {
enginesByPlatform: {},
enginesByIndex: [],
enginesById: {},
};

export const generateContextDefaults = () => ({
isSystemWin: false,
logMessages: [],
timeEnd: new Date(),
timeStart: new Date(),
payload: {},
assetConfig: {},
rnvVersion: '',
buildHooks: {},
buildPipes: {},
isBuildHooksReady: false,
runtimePropsInjects: [],
supportedPlatforms: [],
systemPropsInjects: [],
program: {},
buildConfig: {},
command: '',
subCommand: '',
platform: '',
process: {},
//==========
_renativePluginCache: {},
cli: {},
configPropsInjects: {},
runtime,
paths: {
CURRENT_DIR: '',
IS_LINKED: false,
RNV_HOME_DIR: '',
RNV_NODE_MODULES_DIR: '',
appConfigBase: '',
GLOBAL_RNV_CONFIG: '',
rnv: {
configWorkspaces: {},
dir: '',
package: '',
pluginTemplates: {
configs: {},
dirs: {},
},
platformTemplates: {},
projectTemplates: {},
platformTemplate: {},
plugins: {},
engines: {},
projectTemplate: {},
},
workspace: {
...generateRnvConfigPathObj(),
project: {
...generateRnvConfigPathObj(),
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
appConfigsDirs: [],
appConfigsDirNames: [],
},
appConfig: {
...generateRnvConfigPathObj(),
},
},
defaultWorkspace: {
...generateRnvConfigPathObj(),
project: {
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
appConfigsDirs: [],
appConfigsDirNames: [],
},
appConfig: {
configs: [],
configsPrivate: [],
configsLocal: [],
},
},
project: {
...generateRnvConfigPathObj(),
config: '',
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
appConfigsDirs: [],
appConfigsDirNames: [],
dir: '',
platformTemplatesDirs: {},
nodeModulesDir: '',
},
appConfig: {
...generateRnvConfigPathObj(),
},
// EXTRA
GLOBAL_RNV_DIR: '',
buildHooks: {
dist: {},
dir: '',
index: '',
},
home: {},
template: {
...generateRnvConfigPathObj(),
configTemplate: '',
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
},
},
files: {
rnv: {
pluginTemplates: {},
platformTemplates: {},
projectTemplates: {},
platformTemplate: {},
plugins: {},
engines: {},
projectTemplate: {},
configWorkspaces: {},
package: {},
},
workspace: {
...generateRnvConfigFileObj(),
project: {
...generateRnvConfigFileObj(),
configs: [],
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
},
appConfig: {
...generateRnvConfigFileObj(),
},
},
defaultWorkspace: {
...generateRnvConfigPathObj(),
project: {
...generateRnvConfigPathObj(),
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
},
appConfig: {
configs: [],
configsPrivate: [],
configsLocal: [],
},
},
project: {
...generateRnvConfigFileObj(),
appConfigBase: {},
builds: {},
assets: {},
platformTemplates: {},
package: {},
},
appConfig: {
...generateRnvConfigFileObj(),
},
},
});

rnvcore.getEngineRunnerByPlatform = () => ({
getOriginalPlatformTemplatesDir: () => 'sometemptdir',
});
Expand Down Expand Up @@ -51,6 +248,68 @@ rnvcore.logSuccess = jest.fn();
rnvcore.logSummary = jest.fn();
rnvcore.chalk = () => _chalkMono;

rnvcore.inquirerPrompt = async () => {
return {};
};

rnvcore.createRnvContext = () => {
global.MOCK_RNV_CONTEXT = generateContextDefaults();
};
rnvcore.getContext = () => {
return global.MOCK_RNV_CONTEXT;
};

rnvcore.createRnvApi = () => {
global.MOCK_RNV_API = {
doResolve: jest.fn(),
getConfigProp: jest.fn(),
logger: jest.fn(),
analytics: {
captureEvent: () => {
//NOOP
},
captureException() {
//NOOP
},
teardown: async () => {
//NOOP
},
},
prompt: {
generateOptions() {
//NOOP
return {
asString: '',
keysAsArray: [],
keysAsObject: {},
optionsAsArray: [],
valuesAsArray: [],
valuesAsObject: {},
};
},
inquirerPrompt: async () => {
return {};
},
pressAnyKeyToContinue: async () => {
return {};
},
inquirerSeparator() {
return {};
},
},
spinner: jest.fn(),
fsExistsSync: jest.fn(),
fsReadFileSync: jest.fn(),
fsReaddirSync: jest.fn(),
fsWriteFileSync: jest.fn(),
path: jest.fn(),
};
};

rnvcore.getApi = () => {
return global.MOCK_RNV_API;
};

// Common: {
// getConfigProp: (c, platform, key) => configPropMocks[key],
// confirmActiveBundler: () => null,
Expand Down
56 changes: 14 additions & 42 deletions packages/engine-core/src/__tests__/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,33 @@ import taskRnvPlatformList from '../tasks/task.rnv.platform.list';
import taskRnvKill from '../tasks/task.rnv.kill';
import taskRnvPlatformConfigure from '../tasks/task.rnv.platform.configure';
import taskRnvClean from '../tasks/task.rnv.clean';
import { getContext, executeTask, executeAsync, removeDirs } from '@rnv/core';
import { getContext, executeTask, executeAsync, removeDirs, createRnvContext, createRnvApi } from '@rnv/core';

jest.mock('fs');
jest.mock('child_process');
jest.mock('@rnv/core');
jest.mock('inquirer');

// jest.mock('../../src/core/engineManager/index.ts', () => ({
// // getEngineConfigByPlatform: () => ({
// // platforms: {
// // ios: {
// // npm: {}
// // }
// // }
// // }),
// getEngineRunnerByPlatform: () => ({
// getOriginalPlatformTemplatesDir: () => 'sometemptdir',
// }),
// }));

// jest.mock('../../src/core/system/utils.ts', () => ({
// isSystemWin: false,
// }));

// jest.mock('../../src/core/system/logger.ts');

// const c = generateMockConfig({
// buildConfig: {
// sdks: {
// ANDROID_SDK: '',
// },
// },
// });

// const parentTask = null;
const originTask = undefined;

// const { executeTask, executeAsync, removeDirs } = require('@rnv/core');

beforeEach(() => {
//Do nothing
});

afterEach(() => {
//Do nothing
createRnvContext();
createRnvApi();
});

test('Execute task.rnv.platform.list', async () => {
await taskRnvPlatformList.fn(getContext(), undefined, originTask);
await expect(taskRnvPlatformList.fn(getContext(), undefined, originTask)).resolves.toEqual(true);
expect(executeTask).toHaveBeenCalledWith(getContext(), 'project configure', 'platform list', originTask);
const ctx = getContext();

await taskRnvPlatformList.fn(ctx, undefined, originTask);
await expect(taskRnvPlatformList.fn(ctx, undefined, originTask)).resolves.toEqual(true);
expect(executeTask).toHaveBeenCalledWith(ctx, 'project configure', 'platform list', originTask);
});

test('Execute task.rnv.platform.configure', async () => {
await expect(taskRnvPlatformConfigure.fn(getContext(), undefined, originTask)).resolves.toEqual(true);
expect(executeTask).toHaveBeenCalledWith(getContext(), 'project configure', 'platform configure', originTask);
const ctx = getContext();

await expect(taskRnvPlatformConfigure.fn(ctx, undefined, originTask)).resolves.toEqual(true);
expect(executeTask).toHaveBeenCalledWith(ctx, 'project configure', 'platform configure', originTask);
});

test('Execute task.rnv.kill', async () => {
Expand All @@ -68,7 +39,8 @@ test('Execute task.rnv.kill', async () => {
test('Execute task.rnv.clean', async () => {
const ctx = getContext();

await expect(taskRnvClean.fn(getContext())).resolves.toEqual(true);
await expect(taskRnvClean.fn(ctx)).resolves.toEqual(true);

expect(removeDirs).toHaveBeenCalledTimes(3);
expect(executeAsync).toHaveBeenCalledWith(ctx, 'watchman watch-del-all');
expect(executeAsync).toHaveBeenCalledWith(
Expand Down
Loading

0 comments on commit 7e388b5

Please sign in to comment.