1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/basic.js

83 lines
2.5 KiB
JavaScript
Raw Normal View History

2013-09-27 14:36:10 +02:00
var assert = require('assert');
var readfile = require('fs').readFileSync;
var ex = module.exports;
var server = process.server;
var server2 = process.server2;
ex['trying to fetch non-existent package'] = function(cb) {
server.get_package('testpkg', function(res, body) {
// shouldn't exist yet
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 404);
2013-09-27 14:36:10 +02:00
assert(~body.error.indexOf('no such package'));
cb();
});
};
ex['creating new package'] = function(cb) {
2013-09-28 18:46:55 +02:00
server.put_package('testpkg', require('./lib/package')('testpkg'), function(res, body) {
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 201);
2013-09-27 14:36:10 +02:00
assert(~body.ok.indexOf('created new package'));
cb();
});
};
ex['downloading non-existent tarball'] = function(cb) {
server.get_tarball('testpkg', 'blahblah', function(res, body) {
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 404);
2013-09-27 14:36:10 +02:00
assert(~body.error.indexOf('no such file'));
cb();
});
};
ex['uploading incomplete tarball'] = function(cb) {
server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000, function(res, body) {
cb();
});
};
ex['uploading new tarball'] = function(cb) {
server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'), function(res, body) {
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 201);
2013-09-27 14:36:10 +02:00
assert(body.ok);
cb();
});
};
ex['downloading newly created tarball'] = function(cb) {
server.get_tarball('testpkg', 'blahblah', function(res, body) {
assert.equal(res.statusCode, 200);
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'));
cb();
});
};
ex['uploading new package version'] = function(cb) {
2013-09-28 18:46:55 +02:00
server.put_version('testpkg', '0.0.1', require('./lib/package')('testpkg'), function(res, body) {
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 201);
2013-09-27 14:36:10 +02:00
assert(~body.ok.indexOf('published'));
cb();
});
};
ex['downloading newly created package'] = function(cb) {
server.get_package('testpkg', function(res, body) {
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 200);
assert.equal(body.name, 'testpkg');
2013-09-28 18:46:55 +02:00
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
2013-09-27 14:36:10 +02:00
cb();
});
};
ex['downloading package via server2'] = function(cb) {
server2.get_package('testpkg', function(res, body) {
2013-09-28 13:14:51 +02:00
assert.equal(res.statusCode, 200);
assert.equal(body.name, 'testpkg');
2013-09-28 18:46:55 +02:00
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
2013-09-27 14:36:10 +02:00
cb();
});
};