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

versions-test: add support for experimental pre-releases #3160

Merged
merged 1 commit into from Jun 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/__tests__/version-test.ts
Expand Up @@ -4,13 +4,6 @@ import { describe, it } from 'mocha';
import { version, versionInfo } from '../version';

describe('Version', () => {
it('version', () => {
expect(version).to.be.a('string');
expect(version).to.match(
/^\d+\.\d+\.\d(-(alpha|beta|rc|(experimental-[\w-]+))\.\d+)?$/,
);
});

it('versionInfo', () => {
expect(versionInfo).to.be.an('object');
expect(versionInfo).to.have.all.keys(
Expand All @@ -21,20 +14,38 @@ describe('Version', () => {
);

const { major, minor, patch, preReleaseTag } = versionInfo;

expect(major).to.be.a('number');
expect(minor).to.be.a('number');
expect(patch).to.be.a('number');
expect(major).to.be.a('number').at.least(0);
expect(minor).to.be.a('number').at.least(0);
expect(patch).to.be.a('number').at.least(0);

// istanbul ignore next (Can't be verified on all versions)
if (preReleaseTag !== null) {
expect(preReleaseTag).to.be.a('string');
switch (preReleaseTag?.split('.').length) {
case null:
break;
case 2:
expect(preReleaseTag).to.match(
/^(alpha|beta|rc|experimental-[\w-]+)\.\d+/,
);
break;
case 4:
expect(preReleaseTag).to.match(
/^(alpha|beta|rc)\.\d+.experimental-[\w-]+\.\d+/,
);
break;
default:
expect.fail('Invalid pre-release tag: ' + preReleaseTag);
}
});

it('version', () => {
expect(version).to.be.a('string');

expect(
`${major}.${minor}.${patch}` +
// istanbul ignore next (Can't be verified on all versions)
(preReleaseTag !== null ? '-' + preReleaseTag : ''),
).to.equal(version);
const { major, minor, patch, preReleaseTag } = versionInfo;
expect(version).to.equal(
// istanbul ignore next (Can't be verified on all versions)
preReleaseTag === null
? `${major}.${minor}.${patch}`
: `${major}.${minor}.${patch}-${preReleaseTag}`,
);
});
});