diff --git a/scripts/__tests__/version-utils-test.js b/scripts/__tests__/version-utils-test.js index 0dd087e20b01ba..da5b67402a4810 100644 --- a/scripts/__tests__/version-utils-test.js +++ b/scripts/__tests__/version-utils-test.js @@ -171,14 +171,19 @@ describe('version-utils', () => { expect(prerelease).toBeUndefined(); }); - it('should reject nightly with no prerelease', () => { + it('should parse nightly with no prerelease', () => { // this should fail - function testInvalidFunction() { - parseVersion('0.0.0', 'nightly'); - } - expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot( - `"Version 0.0.0 is not valid for nightlies"`, + + const {version, major, minor, patch, prerelease} = parseVersion( + '0.0.0', + 'nightly', ); + + expect(version).toBe('0.0.0'); + expect(major).toBe('0'); + expect(minor).toBe('0'); + expect(patch).toBe('0'); + expect(prerelease).toBeUndefined(); }); it('should reject nightly with prerelease but wrong version numbers', () => { @@ -308,13 +313,17 @@ describe('version-utils', () => { ); }); - it('should reject dryrun for nightlies with invalid prerelease', () => { - function testInvalidFunction() { - parseVersion('0.0.0', 'dry-run'); - } - expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot( - `"Version 0.0.0 is not valid for dry-runs"`, + it('should parse dryrun for nightlies with no prerelease', () => { + const {version, major, minor, patch, prerelease} = parseVersion( + '0.0.0', + 'dry-run', ); + + expect(version).toBe('0.0.0'); + expect(major).toBe('0'); + expect(minor).toBe('0'); + expect(patch).toBe('0'); + expect(prerelease).toBeUndefined(); }); }); diff --git a/scripts/version-utils.js b/scripts/version-utils.js index e73ea62ed44249..f482e1cc70a8a6 100644 --- a/scripts/version-utils.js +++ b/scripts/version-utils.js @@ -18,7 +18,7 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/; * Some examples of valid versions are: * - stable: 0.68.1 * - stable prerelease: 0.70.0-rc.0 - * - nightly: 0.0.0-20221116-2018-0bc4547fc + * - nightly: 0.0.0-20221116-2018-0bc4547fc | 0.0.0 * - dryrun: 1000.0.0 * * Parameters: @@ -95,11 +95,9 @@ function validateRelease(version) { } function validateDryRun(version) { - const isNightly = isNightlyBuild(version) && version.prerelease != null; - if ( !isMain(version) && - !isNightly && + !isNightlyBuild(version) && !isStableRelease(version) && !isStablePrerelease(version) ) { @@ -109,9 +107,7 @@ function validateDryRun(version) { function validateNightly(version) { // a valid nightly is a prerelease - const isPrerelease = version.prerelease != null; - const isValidNightly = isNightlyBuild(version) && isPrerelease; - if (!isValidNightly) { + if (!isNightlyBuild(version)) { throw new Error(`Version ${version.version} is not valid for nightlies`); } }