Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
test: rewrite semver test with more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Mar 5, 2021
1 parent 8dcbbbe commit 2b60af9
Showing 1 changed file with 92 additions and 63 deletions.
155 changes: 92 additions & 63 deletions test/internal/semver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '../../src/internal/semver';
import { VERSION } from '../../src/version';

describe('Version Compatibility', () => {
describe('semver', () => {
it('should be compatible if versions are equal', () => {
assert.ok(isCompatible(VERSION));
});
Expand All @@ -36,69 +36,98 @@ describe('Version Compatibility', () => {
assert.ok(!check('this is not semver'));
});

describe('>= 1.x', () => {
it('should be compatible if major and minor versions are equal', () => {
const check = _makeCompatibilityCheck('1.2.3');
assert.ok(check('1.2.2'));
assert.ok(check('1.2.2-alpha'));
assert.ok(check('1.2.4'));
assert.ok(check('1.2.4-alpha'));
});

it('should be incompatible if major versions are equal and minor version is lesser', () => {
// we are ahead of the global and might call functions it doesn't have
const check = _makeCompatibilityCheck('1.2.3');
assert.ok(!check('1.1.2'));
assert.ok(!check('1.1.2-alpha'));
assert.ok(!check('1.1.4'));
assert.ok(!check('1.1.4-alpha'));
});

it('should be incompatible if major versions do not match', () => {
const check = _makeCompatibilityCheck('3.3.3');
assert.ok(!check('0.3.3'));
assert.ok(!check('0.3.3'));
});

it('should be compatible if major versions match but other minor version is greater than our minor version', () => {
// global is ahead of us, but changes are backwards compatible
const check = _makeCompatibilityCheck('1.2.3');
assert.ok(check('1.3.3-alpha'));
assert.ok(check('1.3.3'));
});
describe('>= 1.0.0', () => {
const globalVersion = '5.5.5';
const vers: [string, boolean][] = [
// same major/minor run should be compatible
['5.5.5', true],
['5.5.6', true],
['5.5.4', true],

// if our version has a minor version increase, we may try to call methods which don't exist on the global
['5.6.5', false],
['5.6.6', false],
['5.6.4', false],

// if the global version is ahead of us by a minor revision, it has at least the methods we know about
['5.4.5', true],
['5.4.6', true],
['5.4.4', true],

// major version mismatch is always incompatible
['6.5.5', false],
['6.5.6', false],
['6.5.4', false],
['6.6.5', false],
['6.6.6', false],
['6.6.4', false],
['6.4.5', false],
['6.4.6', false],
['6.4.4', false],
['4.5.5', false],
['4.5.6', false],
['4.5.4', false],
['4.6.5', false],
['4.6.6', false],
['4.6.4', false],
['4.4.5', false],
['4.4.6', false],
['4.4.4', false],
];

test(globalVersion, vers);
});

describe('0.x', () => {
it('should be compatible if minor and patch versions are equal', () => {
const check = _makeCompatibilityCheck('0.1.2');
assert.ok(check('0.1.2'));
assert.ok(check('0.1.2-alpha'));
});

it('should be incompatible if minor versions are equal and patch version is lesser', () => {
// we are ahead of the global and might call functions it doesn't have
const check = _makeCompatibilityCheck('0.1.2');
assert.ok(!check('0.1.1'));
assert.ok(!check('0.1.1-alpha'));
});

it('should be incompatible if minor versions do not match', () => {
const check = _makeCompatibilityCheck('0.3.3');
assert.ok(!check('0.2.3'));
assert.ok(!check('0.4.3'));
});

it('should be incompatible if minor versions do not match', () => {
const check = _makeCompatibilityCheck('0.3.3');
assert.ok(!check('0.2.3'));
assert.ok(!check('0.4.3'));
});

it('should be compatible if minor versions match but other patch version is greater than our patch version', () => {
// global is ahead of us, but changes are backwards compatible
const check = _makeCompatibilityCheck('0.3.3');
assert.ok(check('0.3.4-alpha'));
assert.ok(check('0.3.4'));
});
describe('< 1.0.0', () => {
const globalVersion = '0.5.5';
const vers: [string, boolean][] = [
// same minor/patch should be compatible
['0.5.5', true],

// if our version has a patch version increase, we may try to call methods which don't exist on the global
['0.5.6', false],

// if the global version is ahead of us by a patch revision, it has at least the methods we know about
['0.5.4', true],

// minor version mismatch is always incompatible
['0.6.5', false],
['0.6.6', false],
['0.6.4', false],
['0.4.5', false],
['0.4.6', false],
['0.4.4', false],

// major version mismatch is always incompatible
['1.5.5', false],
['1.5.6', false],
['1.5.4', false],
['1.6.5', false],
['1.6.6', false],
['1.6.4', false],
['1.4.5', false],
['1.4.6', false],
['1.4.4', false],
];

test(globalVersion, vers);
});
});

function test(globalVersion: string, vers: [string, boolean][]) {
describe(`global version is ${globalVersion}`, () => {
for (const [version, compatible] of vers) {
const alphaVersion = `${version}-alpha.1`;
it(`API version ${version} ${
compatible ? 'should' : 'should not'
} be able to access global`, () => {
const check = _makeCompatibilityCheck(version);
assert.strictEqual(check(globalVersion), compatible);

// alpha tag should have no effect different than the regular version
const alphaCheck = _makeCompatibilityCheck(alphaVersion);
assert.strictEqual(alphaCheck(globalVersion), compatible);
});
}
});
}

0 comments on commit 2b60af9

Please sign in to comment.