0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/test/functional/incomplete.js

68 lines
2 KiB
JavaScript
Raw Normal View History

2014-03-07 14:48:24 -05:00
var assert = require('assert')
module.exports = function() {
var server = process.server
var express = process.express
2014-03-07 14:48:24 -05:00
describe('Incomplete', function() {
before(function() {
express.get('/testexp-incomplete', function(_, res) {
res.send({
"name": "testexp-incomplete",
"versions": {
"0.1.0": {
"name": "testexp_tags",
"version": "0.1.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55550/testexp-incomplete/-/content-length.tar.gz"
}
},
"0.1.1": {
"name": "testexp_tags",
"version": "0.1.1",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55550/testexp-incomplete/-/chunked.tar.gz"
}
}
}
})
})
})
2014-03-07 14:48:24 -05:00
;[ 'content-length', 'chunked' ].forEach(function(type) {
it('should not store tarballs / ' + type, function(_cb) {
var called
express.get('/testexp-incomplete/-/'+type+'.tar.gz', function(_, res) {
if (called) return res.socket.destroy()
called = true
if (type !== 'chunked') res.header('content-length', 1e6)
res.write('test test test\n')
setTimeout(function() {
res.socket.write('200\nsss\n')
res.socket.destroy()
cb()
}, 10)
})
2014-03-07 14:48:24 -05:00
server.request({ uri: '/testexp-incomplete/-/'+type+'.tar.gz' })
.status(200)
.response(function (res) {
if (type !== 'chunked') assert.equal(res.headers['content-length'], 1e6)
})
.then(function (body) {
assert(body.match(/test test test/))
})
2014-03-07 14:48:24 -05:00
function cb() {
server.request({ uri: '/testexp-incomplete/-/'+type+'.tar.gz' })
.body_error('internal server error')
.then(function () { _cb() })
}
})
})
})
2014-03-07 14:48:24 -05:00
}