mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
better tests for various tags (including bad ones), ref #21
This commit is contained in:
parent
47a92ff273
commit
7ee2361700
@ -514,8 +514,7 @@ Storage._merge_versions = function(local, up) {
|
||||
// exported for unit tests only
|
||||
Storage._semver_sort = function semver_sort(array) {
|
||||
return array
|
||||
.map(function(x) { return semver.parse(x, true) })
|
||||
.filter(function(x) { return !!x })
|
||||
.filter(function(x) { return semver.parse(x, true) != null })
|
||||
.sort(semver.compareLoose)
|
||||
.map(String)
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ users:
|
||||
password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
|
||||
uplinks:
|
||||
express:
|
||||
url: http://localhost:55550/
|
||||
server2:
|
||||
url: http://localhost:55552/
|
||||
|
||||
@ -24,6 +26,11 @@ packages:
|
||||
proxy_access: server2
|
||||
proxy_publish: server2
|
||||
|
||||
'testexp*':
|
||||
allow_access: all
|
||||
allow_publish: all
|
||||
proxy_access: express
|
||||
|
||||
'*':
|
||||
allow_access: test undefined
|
||||
allow_publish: test undefined
|
||||
|
50
test/fixtures/tags.json
vendored
Normal file
50
test/fixtures/tags.json
vendored
Normal 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"
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
|
||||
module.exports = function(name) {
|
||||
module.exports = function(name, version) {
|
||||
return {
|
||||
"name": name,
|
||||
"version": "0.0.0",
|
||||
"version": version || "0.0.0",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/"+escape(name)+"/-/blahblah"
|
||||
|
@ -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"]},
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
exports['semver_sort'] = function() {
|
||||
assert.deepEqual(semver_sort(['1.2.3','1.2','1.2.3a','1.2.3c','1.2.3-b']),
|
||||
[ '1.2.3-a',
|
||||
'1.2.3-b',
|
||||
'1.2.3-c',
|
||||
'1.2.3' ]
|
||||
)
|
||||
|
||||
'semver_sort': function() {
|
||||
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-b',
|
||||
'1.2.3c',
|
||||
'1.2.3' ]
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
|
34
test/tags.js
Normal file
34
test/tags.js
Normal 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()
|
||||
})
|
||||
}
|
||||
|
@ -3,16 +3,21 @@ var fs = require('fs')
|
||||
, assert = require('assert')
|
||||
, Server = require('./lib/server')
|
||||
, readfile = require('fs').readFileSync
|
||||
, express = require('express')
|
||||
, ex = module.exports
|
||||
|
||||
var forks = process.forks = []
|
||||
process.server = new Server('http://localhost:55551/')
|
||||
process.server2 = new Server('http://localhost:55552/')
|
||||
process.express = express()
|
||||
|
||||
process.express.listen(55550)
|
||||
|
||||
ex['Startup:'] = require('./startup')
|
||||
ex['Basic:'] = require('./basic')
|
||||
ex['Mirror:'] = require('./mirror')
|
||||
ex['Race:'] = require('./race')
|
||||
ex['Tags:'] = require('./tags')
|
||||
|
||||
process.on('exit', function() {
|
||||
if (forks[0]) forks[0].kill()
|
||||
|
Loading…
Reference in New Issue
Block a user