Latest tag with any prefix + tests (#1188)

This commit is contained in:
Marcin Mielnicki
2017-10-26 22:31:13 +02:00
committed by Paul Melnikow
parent ffb6fdb884
commit f89b317542
2 changed files with 39 additions and 1 deletions

38
lib/version.spec.js Normal file
View File

@@ -0,0 +1,38 @@
'use strict';
const assert = require('assert');
const {latest} = require('./version');
describe('latest', function () {
it('should handle semver compatible versions', function () {
assert.equal(latest(['1.0.0', '1.0.2', '1.0.1']), '1.0.2');
assert.equal(latest(['1.0.0', '2.0.0', '3.0.0']), '3.0.0');
assert.equal(latest(['0.0.1', '0.0.10', '0.0.2', '0.0.20']), '0.0.20');
});
it('should handle versions with and without prefix', function () {
assert.equal(latest(['1.0.0', 'v1.0.2', 'r1.0.1', 'release-2.0.0']), 'release-2.0.0');
assert.equal(latest(['1.0.0', 'v2.0.0', 'r1.0.1', 'release-1.0.3']), 'v2.0.0');
assert.equal(latest(['2.0.0', 'v1.0.3', 'r1.0.1', 'release-1.0.3']), '2.0.0');
assert.equal(latest(['1.0.0', 'v1.0.2', 'r2.0.0', 'release-1.0.3']), 'r2.0.0');
});
it('should handle simple dotted versions', function () {
assert.equal(latest(['0.1', '0.3', '0.2']), '0.3');
assert.equal(latest(['0.1', '0.5', '0.12', '0.21']), '0.21');
assert.equal(latest(['1.0', '2.0', '3.0']), '3.0');
});
it('should handle versions with "v" prefix', function () {
assert.equal(latest(['v1.0.0', 'v1.0.2', 'v1.0.1']), 'v1.0.2');
assert.equal(latest(['v1.0.0', 'v3.0.0', 'v2.0.0']), 'v3.0.0');
});
it('should handle versions with "-release" prefix', function () {
assert.equal(latest(['release-1.0.0', 'release-1.0.2', 'release-1.0.20', 'release-1.0.3']), 'release-1.0.20');
});
it('should handle simple (one number) versions', function () {
assert.equal(latest(['2', '10', '1']), '10');
});
});