Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
test(tarball): added tests for registry tarball streams
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 3, 2017
1 parent 28fb412 commit 3bd1a25
Showing 1 changed file with 97 additions and 1 deletion.
98 changes: 97 additions & 1 deletion test/registry.tarball.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
'use strict'

var finished = require('mississippi').finished
var mockTar = require('./util/mock-tarball')
var npmlog = require('npmlog')
var test = require('tap').test
var tnock = require('./util/tnock')

test('basic tarball streaming')
require('./util/test-dir')(__filename)

var tarball = require('../lib/registry/tarball')

var BASE = {
name: 'foo',
version: '1.2.3',
_hasShrinkwrap: false,
dist: {
shasum: 'deadbeef',
tarball: 'https://my.mock.registry/foo/-/foo-1.2.3.tgz'
}
}

var META = {
name: 'foo',
'dist-tags': { latest: '1.2.3' },
versions: {
'1.2.3': BASE
}
}

npmlog.level = process.env.LOGLEVEL || 'silent'
var OPTS = {
log: npmlog,
registry: 'https://my.mock.registry/',
retry: {
retries: 1,
factor: 1,
minTimeout: 1,
maxTimeout: 10
}
}

test('basic tarball streaming', function (t) {
var pkg = {
'package.json': JSON.stringify({
name: 'foo',
version: '1.2.3'
}),
'index.js': 'console.log("hello world!")'
}
mockTar(pkg, function (err, tarData) {
if (err) { throw err }
var srv = tnock(t, OPTS.registry)
srv.get('/foo').reply(200, META)
srv.get('/foo/-/foo-1.2.3.tgz').reply(200, tarData)
var data = ''
finished(tarball({
type: 'range',
raw: 'foo@^1.2.3',
name: 'foo',
escapedName: 'foo',
rawSpec: '^1.2.3',
spec: '>=1.2.3 <2.0.0',
scope: null
}, OPTS).on('data', function (d) { data += d }), function (err) {
if (err) { throw err }
t.equal(data, tarData, 'fetched tarball data matches one from server')
t.done()
})
})
})

// TODO - this is failing because the error is `premature close`, not 404
// test('errors if manifest fails', function (t) {
// var pkg = {
// 'package.json': JSON.stringify({
// name: 'foo',
// version: '1.2.3'
// }),
// 'index.js': 'console.log("hello world!")'
// }
// mockTar(pkg, function (err, tarData) {
// if (err) { throw err }
// var srv = tnock(t, OPTS.registry)
// srv.get('/foo').reply(200, META)
// srv.get('/foo/-/foo-1.2.3.tgz').reply(404)
// finished(tarball({
// type: 'range',
// raw: 'foo@^1.2.3',
// name: 'foo',
// escapedName: 'foo',
// rawSpec: '^1.2.3',
// spec: '>=1.2.3 <2.0.0',
// scope: null
// }, OPTS).on('data', function (d) {}), function (err) {
// t.ok(err, 'correctly errored')
// t.equal(err.code, 'E404', 'got a 404 back')
// t.done()
// })
// })
// })

0 comments on commit 3bd1a25

Please sign in to comment.