From fafc71b5cb93c6f4fbf48ab752155dca5f66220e Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 19 Jun 2024 14:37:48 +0100 Subject: [PATCH] [LOCAL][RN][Tests] Fix JS tests for release (#45062) --- scripts/__tests__/npm-utils-test.js | 48 +++++++++++++++-------------- scripts/npm-utils.js | 5 +-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/scripts/__tests__/npm-utils-test.js b/scripts/__tests__/npm-utils-test.js index a804a968409..86841546dbd 100644 --- a/scripts/__tests__/npm-utils-test.js +++ b/scripts/__tests__/npm-utils-test.js @@ -115,6 +115,11 @@ describe('npm-utils', () => { }); describe('getNpmInfo', () => { + beforeEach(() => { + process.env.CIRCLE_TAG = ''; + process.env.GITHUB_REF = ''; + process.env.GITHUB_REF_NAME = ''; + }); it('return the expected format for prealpha', () => { const isoStringSpy = jest.spyOn(Date.prototype, 'toISOString'); isoStringSpy.mockReturnValue('2023-10-04T15:43:55.123Z'); @@ -147,33 +152,30 @@ describe('npm-utils', () => { version: `0.74.1-rc.0`, tag: '--no-tag', }); - process.env.CIRCLE_TAG = null; }); - }); - it('return the expected format for patch-prereleases on GHA', () => { - const isoStringSpy = jest.spyOn(Date.prototype, 'toISOString'); - isoStringSpy.mockReturnValue('2023-10-04T15:43:55.123Z'); - getCurrentCommitMock.mockImplementation(() => 'abcd1234'); - // exitIfNotOnGit takes a function as a param and it: - // 1. checks if we are on git => if not it exits - // 2. run the function passed as a param and return the output to the caller - // For the mock, we are assuming we are on github and we are returning `false` - // as the `getNpmInfo` function will pass a function that checks if the - // current commit is a tagged with 'latest'. - // In the Mock, we are assuming that we are on git (it does not exits) and the - // checkIfLatest function returns `false` - exitIfNotOnGitMock.mockImplementation(() => false); + it('return the expected format for patch-prereleases on GHA', () => { + const isoStringSpy = jest.spyOn(Date.prototype, 'toISOString'); + isoStringSpy.mockReturnValue('2023-10-04T15:43:55.123Z'); + getCurrentCommitMock.mockImplementation(() => 'abcd1234'); + // exitIfNotOnGit takes a function as a param and it: + // 1. checks if we are on git => if not it exits + // 2. run the function passed as a param and return the output to the caller + // For the mock, we are assuming we are on github and we are returning `false` + // as the `getNpmInfo` function will pass a function that checks if the + // current commit is a tagged with 'latest'. + // In the Mock, we are assuming that we are on git (it does not exits) and the + // checkIfLatest function returns `false` + exitIfNotOnGitMock.mockImplementation(() => false); - process.env.GITHUB_REF = 'refs/tags/v0.74.1-rc.0'; - process.env.GITHUB_REF_NAME = 'v0.74.1-rc.0'; - const returnedValue = getNpmInfo('release'); - expect(returnedValue).toMatchObject({ - version: `0.74.1-rc.0`, - tag: '--no-tag', + process.env.GITHUB_REF = 'refs/tags/v0.74.1-rc.0'; + process.env.GITHUB_REF_NAME = 'v0.74.1-rc.0'; + const returnedValue = getNpmInfo('release'); + expect(returnedValue).toMatchObject({ + version: `0.74.1-rc.0`, + tag: '--no-tag', + }); }); - process.env.GITHUB_REF = null; - process.env.GITHUB_REF_NAME = null; }); describe('getVersionsBySpec', () => { diff --git a/scripts/npm-utils.js b/scripts/npm-utils.js index b7f16ae8a1b..2607be95832 100644 --- a/scripts/npm-utils.js +++ b/scripts/npm-utils.js @@ -90,12 +90,13 @@ function getNpmInfo(buildType /*: BuildType */) /*: NpmInfo */ { if (buildType === 'release') { let versionTag /*: string*/ = ''; - if (process.env.CIRCLE_TAG != null) { + if (process.env.CIRCLE_TAG != null && process.env.CIRCLE_TAG !== '') { versionTag = process.env.CIRCLE_TAG; } else if ( process.env.GITHUB_REF != null && process.env.GITHUB_REF.includes('/tags/') && - process.env.GITHUB_REF_NAME != null + process.env.GITHUB_REF_NAME != null && + process.env.GITHUB_REF_NAME !== '' ) { // GITHUB_REF contains the fully qualified ref, for example refs/tags/v0.75.0-rc.0 // GITHUB_REF_NAME contains the short name, for example v0.75.0-rc.0