1 | import {assert} from 'chai';
|
2 | import {select} from './version';
|
3 |
|
4 | describe('version', () => {
|
5 | describe('select()', () => {
|
6 | it('selects the greater of two compatible semver ranges', () => {
|
7 | [
|
8 | ['^1.0.0', '^1.1.0', '^1.1.0'],
|
9 | ['^1.1.0', '^1.0.0', '^1.1.0'],
|
10 | ['~1.3.0', '^1.1.0', '^1.3.0'],
|
11 | ['~1.0.0', '~1.0.1', '~1.0.1'],
|
12 | ['^1.0.0', '1.1.0', '^1.1.0'],
|
13 | ].forEach(([left, right, correct]) => {
|
14 | assert.equal(
|
15 | select(left, right),
|
16 | correct,
|
17 | `the greater of [${left}, ${right}] is ${correct}`,
|
18 | );
|
19 | });
|
20 | });
|
21 |
|
22 | it('selects the only version specified if the other is null', () => {
|
23 | [['^1.1.0', null, '^1.1.0'], [null, '^1.1.0', '^1.1.0']].forEach(
|
24 | ([left, right, correct]) => {
|
25 | assert.equal(select(left, right), correct);
|
26 | },
|
27 | );
|
28 | });
|
29 |
|
30 | it('selects the more permissive of two compatible semver ranges', () => {
|
31 | [
|
32 | ['~1.1.0', '^1.0.0', '^1.1.0'],
|
33 | ['^1.0.0', '~1.1.0', '^1.1.0'],
|
34 | ['^1.0.0', '~1.3.0', '^1.3.0'],
|
35 | ['^1.4.0', '~1.4.0', '^1.4.0'],
|
36 | ['^1.4.10', '~1.4.20', '^1.4.20'],
|
37 | ].forEach(([left, right, correct]) => {
|
38 | assert.equal(
|
39 | select(left, right),
|
40 | correct,
|
41 | `the more permissive of [${left}, ${right}] is ${correct}`,
|
42 | );
|
43 | });
|
44 | });
|
45 |
|
46 | it('throws if semver ranges are not compatible', () => {
|
47 | [
|
48 | ['1.0.0', '2.0.0'],
|
49 | ['~1.0.0', '^1.1.0'],
|
50 | ['^0.1.0', '^0.0.1'],
|
51 | ['~0.1.0', '~0.2.0'],
|
52 | ['^1.3.0', '~1.1.0'],
|
53 | ].forEach(([left, right]) => {
|
54 | assert.throws(
|
55 | () => select(left, right),
|
56 | `"${left}" and "${right}" are not compatible`,
|
57 | );
|
58 | });
|
59 |
|
60 | assert.throws(
|
61 | () => select(null, null),
|
62 | 'Cannot select a version from "null" and "null"',
|
63 | );
|
64 | });
|
65 | });
|
66 | });
|