Skip to content

Commit

Permalink
added testcase, fixed logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiblaga89 committed Jan 17, 2024
1 parent cfc55f3 commit 0f8688d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
24 changes: 23 additions & 1 deletion packages/core/src/__tests__/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('Testing getAppVersionCode functions', () => {
},
buildConfig: {
common: {
versionCode: -1,
versionCode: '-1',
},
},
},
Expand All @@ -337,4 +337,26 @@ describe('Testing getAppVersionCode functions', () => {
expect(e).toEqual(Error(`'versionCode' should be a positive integer. Check your config`));
}
});

it('should evaluate given versionCode 4.4.4 with 4.4.4 on ios', async () => {
const result = getAppVersionCode(
{
...BUILD_CONF,
files: {
...BUILD_CONF.files,
project: {
...BUILD_CONF.files.project,
package: { version: '1' },
},
},
buildConfig: {
common: {
versionCode: '4.4.4',
},
},
},
'ios'
);
expect(result).toEqual('4.4.4');
});
});
15 changes: 8 additions & 7 deletions packages/core/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,15 @@ const _androidLikePlatform = (platform: RnvPlatform) =>
export const getAppVersionCode = (c: RnvContext, platform: RnvPlatform) => {
const versionCode = getConfigProp(c, platform, 'versionCode');

// android platforms don't allow versionCode to be a string, only positive integer
if (_androidLikePlatform(platform)) {
const isValidVersionCode = Number.isInteger(Number(versionCode)) && Number(versionCode) > 0;
if (isValidVersionCode) {
return versionCode;
} else if (versionCode && !isValidVersionCode) {
throw new Error(`'versionCode' should be a positive integer. Check your config`);
if (versionCode) {
// android platforms don't allow versionCode to be a string, only positive integer
if (_androidLikePlatform(platform)) {
const isValidVersionCode = Number.isInteger(Number(versionCode)) && Number(versionCode) > 0;
if (!isValidVersionCode) {
throw new Error(`'versionCode' should be a positive integer. Check your config`);
}
}
return versionCode;
}

const version = getConfigProp(c, platform, 'version') || c.files.project.package?.version;
Expand Down

0 comments on commit 0f8688d

Please sign in to comment.