0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-03-25 02:32:52 -05:00

better tests for various tags (including bad ones), ref

This commit is contained in:
Alex Kocharin 2013-12-12 01:22:35 +04:00
parent 47a92ff273
commit 7ee2361700
7 changed files with 108 additions and 13 deletions

View file

@ -514,8 +514,7 @@ Storage._merge_versions = function(local, up) {
// exported for unit tests only // exported for unit tests only
Storage._semver_sort = function semver_sort(array) { Storage._semver_sort = function semver_sort(array) {
return array return array
.map(function(x) { return semver.parse(x, true) }) .filter(function(x) { return semver.parse(x, true) != null })
.filter(function(x) { return !!x })
.sort(semver.compareLoose) .sort(semver.compareLoose)
.map(String) .map(String)
} }

View file

@ -5,6 +5,8 @@ users:
password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
uplinks: uplinks:
express:
url: http://localhost:55550/
server2: server2:
url: http://localhost:55552/ url: http://localhost:55552/
@ -24,6 +26,11 @@ packages:
proxy_access: server2 proxy_access: server2
proxy_publish: server2 proxy_publish: server2
'testexp*':
allow_access: all
allow_publish: all
proxy_access: express
'*': '*':
allow_access: test undefined allow_access: test undefined
allow_publish: test undefined allow_publish: test undefined

50
test/fixtures/tags.json vendored Normal file
View file

@ -0,0 +1,50 @@
{
"name": "testexp_tags",
"versions": {
"0.1.0": {
"name": "testexp_tags",
"version": "0.0.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
}
},
"0.1.1alpha": {
"name": "testexp_tags",
"version": "0.0.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
}
},
"0.1.2": {
"name": "testexp_tags",
"version": "0.0.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
}
},
"0.1.3alpha": {
"name": "testexp_tags",
"version": "0.0.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
}
},
"1.1": {
"name": "testexp_tags",
"version": "0.0.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55551/testexp_tags/-/blahblah"
}
}
},
"dist-tags": {
"latest": "5.4.3",
"something": "0.1.1alpha",
"bad": "1.1"
}
}

View file

@ -1,8 +1,8 @@
module.exports = function(name) { module.exports = function(name, version) {
return { return {
"name": name, "name": name,
"version": "0.0.0", "version": version || "0.0.0",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/"+escape(name)+"/-/blahblah" "tarball": "http://localhost:55551/"+escape(name)+"/-/blahblah"

View file

@ -40,14 +40,14 @@ exports['Merge'] = {
'dist-tags': {w:["1.1.1","2.2.2-rc2","2.2.2","3.3.3","12.2.2"]}, 'dist-tags': {w:["1.1.1","2.2.2-rc2","2.2.2","3.3.3","12.2.2"]},
}) })
}, },
}
'semver_sort': function() {
exports['semver_sort'] = function() { assert.deepEqual(semver_sort(['1.2.3','1.2','1.2.3a','1.2.3c','1.2.3-b']),
assert.deepEqual(semver_sort(['1.2.3','1.2','1.2.3a','1.2.3c','1.2.3-b']), [ '1.2.3a',
[ '1.2.3-a', '1.2.3-b',
'1.2.3-b', '1.2.3c',
'1.2.3-c', '1.2.3' ]
'1.2.3' ] )
) },
} }

34
test/tags.js Normal file
View file

@ -0,0 +1,34 @@
var assert = require('assert')
, ex = module.exports
, server = process.server
, readfile = require('fs').readFileSync
, express = process.express
ex['testing for 404'] = function(cb) {
server.get_package('testexp_tags', function(res, body) {
// shouldn't exist yet
assert.equal(res.statusCode, 404)
assert(~body.error.indexOf('no such package'))
cb()
})
}
ex['setting up server with bad tags'] = function(cb) {
express.get('/testexp_tags', function(req, res) {
res.send(JSON.parse(readfile('fixtures/tags.json')))
})
cb()
}
ex['fetching package again'] = function(cb) {
server.get_package('testexp_tags', function(res, body) {
// shouldn't exist yet
assert.equal(res.statusCode, 200)
assert.equal(typeof(body.versions['1.1']), 'object')
assert.equal(body['dist-tags'].something, '0.1.1alpha')
assert.equal(body['dist-tags'].latest, '0.1.3alpha')
assert.equal(body['dist-tags'].bad, null)
cb()
})
}

View file

@ -3,16 +3,21 @@ var fs = require('fs')
, assert = require('assert') , assert = require('assert')
, Server = require('./lib/server') , Server = require('./lib/server')
, readfile = require('fs').readFileSync , readfile = require('fs').readFileSync
, express = require('express')
, ex = module.exports , ex = module.exports
var forks = process.forks = [] var forks = process.forks = []
process.server = new Server('http://localhost:55551/') process.server = new Server('http://localhost:55551/')
process.server2 = new Server('http://localhost:55552/') process.server2 = new Server('http://localhost:55552/')
process.express = express()
process.express.listen(55550)
ex['Startup:'] = require('./startup') ex['Startup:'] = require('./startup')
ex['Basic:'] = require('./basic') ex['Basic:'] = require('./basic')
ex['Mirror:'] = require('./mirror') ex['Mirror:'] = require('./mirror')
ex['Race:'] = require('./race') ex['Race:'] = require('./race')
ex['Tags:'] = require('./tags')
process.on('exit', function() { process.on('exit', function() {
if (forks[0]) forks[0].kill() if (forks[0]) forks[0].kill()