From 8d1781489bfc455a2a82597bbde93b6a13012831 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 18 Sep 2014 00:04:15 +0400 Subject: [PATCH] tag_version should return if tag is fresh --- lib/utils.js | 4 ++- test/unit/tag_version.js | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/unit/tag_version.js diff --git a/lib/utils.js b/lib/utils.js index 5ddb81b95..41178796c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -98,7 +98,7 @@ function can_add_tag(tag, config) { } module.exports.tag_version = function(data, version, tag, config) { - if (!can_add_tag(tag, config)) return + if (!can_add_tag(tag, config)) return false switch(typeof(data['dist-tags'][tag])) { case 'string': @@ -112,7 +112,9 @@ module.exports.tag_version = function(data, version, tag, config) { if (data['dist-tags'][tag].indexOf(version) === -1) { data['dist-tags'][tag].push(version) data['dist-tags'][tag] = module.exports.semver_sort(data['dist-tags'][tag]) + return data['dist-tags'][tag][data['dist-tags'][tag].length - 1] === version } + return false } // gets version from a package object taking into account semver weirdness diff --git a/test/unit/tag_version.js b/test/unit/tag_version.js new file mode 100644 index 000000000..9e3b8075e --- /dev/null +++ b/test/unit/tag_version.js @@ -0,0 +1,55 @@ +var assert = require('assert') + , tag_version = require('../../lib/utils').tag_version + +require('../../lib/logger').setup([]) + +describe('tag_version', function() { + it('add new one', function() { + var x = { + versions: {}, + 'dist-tags': {}, + } + assert(tag_version(x, '1.1.1', 'foo', {})) + assert.deepEqual(x, { + versions: {}, + 'dist-tags': {foo: ['1.1.1']}, + }) + }) + + it('add (compat)', function() { + var x = { + versions: {}, + 'dist-tags': {foo: '1.1.0'}, + } + assert(tag_version(x, '1.1.1', 'foo', {})) + assert.deepEqual(x, { + versions: {}, + 'dist-tags': {foo: ['1.1.0', '1.1.1']}, + }) + }) + + it('add fresh tag', function() { + var x = { + versions: {}, + 'dist-tags': {foo: ['1.1.0']}, + } + assert(tag_version(x, '1.1.1', 'foo', {})) + assert.deepEqual(x, { + versions: {}, + 'dist-tags': {foo: ['1.1.0', '1.1.1']}, + }) + }) + + it('add stale tag', function() { + var x = { + versions: {}, + 'dist-tags': {foo: ['1.1.2']}, + } + assert(!tag_version(x, '1.1.1', 'foo', {})) + assert.deepEqual(x, { + versions: {}, + 'dist-tags': {foo: ['1.1.1', '1.1.2']}, + }) + }) +}) +