mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: unit test for readme, preserve tags on publish
This commit is contained in:
parent
6f006fbf40
commit
1e6c7dd6ea
11 changed files with 249 additions and 145 deletions
|
@ -19,7 +19,7 @@ module.exports = function(config, auth, storage) {
|
|||
|
||||
// Static
|
||||
router.get('/-/static/:filename', function(req, res, next) {
|
||||
let file = `${env.APP_ROOT}/static/${req.params.filename}`;
|
||||
const file = `${env.APP_ROOT}/static/${req.params.filename}`;
|
||||
res.sendFile(file, function(err) {
|
||||
if (!err) {
|
||||
return;
|
||||
|
|
|
@ -63,11 +63,12 @@ describe('Create registry servers', function() {
|
|||
require('./gzip')();
|
||||
require('./incomplete')();
|
||||
require('./mirror')();
|
||||
require('./newnpmreg')();
|
||||
require('./tags/preserve_tags')();
|
||||
require('./readme/readme.spec')();
|
||||
require('./nullstorage')();
|
||||
require('./race')();
|
||||
require('./racycrash')();
|
||||
require('./scoped')();
|
||||
require('./package/scoped')();
|
||||
require('./security')();
|
||||
require('./adduser')();
|
||||
require('./logout')();
|
||||
|
|
13
test/functional/lib/test.utils.js
Normal file
13
test/functional/lib/test.utils.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
exports.generateSha = function generateSha(key) {
|
||||
return crypto.createHash('sha1', 'binary').update(key).digest('hex');
|
||||
};
|
||||
|
||||
|
||||
exports.readFile = function readFile(filePath) {
|
||||
return fs.readFileSync(path.join(__dirname, `/${filePath}`));
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
let assert = require('assert');
|
||||
|
||||
function readfile(x) {
|
||||
return require('fs').readFileSync(__dirname + '/' + x);
|
||||
}
|
||||
|
||||
function sha(x) {
|
||||
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex');
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
let server = process.server;
|
||||
let server2 = process.server2;
|
||||
let express = process.express;
|
||||
|
||||
describe('newnpmreg', function() {
|
||||
before(function() {
|
||||
return server.request({
|
||||
uri: '/testpkg-newnpmreg',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: JSON.parse(readfile('fixtures/newnpmreg.json')),
|
||||
}).status(201);
|
||||
});
|
||||
|
||||
it('add pkg', function() {});
|
||||
|
||||
it('server1 - tarball', function() {
|
||||
return server.getTarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function(body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
|
||||
});
|
||||
});
|
||||
|
||||
it('server2 - tarball', function() {
|
||||
return server2.getTarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function(body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
|
||||
});
|
||||
});
|
||||
|
||||
it('server1 - package', function() {
|
||||
return server.getPackage('testpkg-newnpmreg')
|
||||
.status(200)
|
||||
.then(function(body) {
|
||||
assert.equal(body.name, 'testpkg-newnpmreg');
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg');
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55551/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz');
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'});
|
||||
});
|
||||
});
|
||||
|
||||
it('server2 - package', function() {
|
||||
return server2.getPackage('testpkg-newnpmreg')
|
||||
.status(200)
|
||||
.then(function(body) {
|
||||
assert.equal(body.name, 'testpkg-newnpmreg');
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg');
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55552/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz');
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'});
|
||||
});
|
||||
});
|
||||
|
||||
// FIXME: Review this block of test
|
||||
// it('server1 - readme', function() {
|
||||
// return server.request({uri: '/-/readme/testpkg-newnpmreg'})
|
||||
// .status(200)
|
||||
// .then(function(body) {
|
||||
// assert.equal(body, '<p>blah blah blah</p>\n');
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// it('server2 - readme', function() {
|
||||
// return server2.request({uri: '/-/readme/testpkg-newnpmreg'})
|
||||
// .status(200)
|
||||
// .then(function(body) {
|
||||
// assert.equal(body, '<p>blah blah blah</p>\n');
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('search', function() {
|
||||
function check(obj) {
|
||||
obj['testpkg-newnpmreg'].time.modified = '2014-10-02T07:07:51.000Z';
|
||||
assert.deepEqual(obj['testpkg-newnpmreg'],
|
||||
{'name': 'testpkg-newnpmreg',
|
||||
'description': '',
|
||||
'author': '',
|
||||
'license': 'ISC',
|
||||
'dist-tags': {latest: '0.0.0'},
|
||||
'maintainers': [{name: 'alex', email: 'alex@kocharin.ru'}],
|
||||
'readmeFilename': '',
|
||||
'time': {modified: '2014-10-02T07:07:51.000Z'},
|
||||
'versions': {},
|
||||
'repository': {type: 'git', url: ''}});
|
||||
}
|
||||
|
||||
before(function() {
|
||||
express.get('/-/all', function(req, res) {
|
||||
res.send({});
|
||||
});
|
||||
});
|
||||
|
||||
it('server1 - search', function() {
|
||||
return server.request({uri: '/-/all'})
|
||||
.status(200)
|
||||
.then(check);
|
||||
});
|
||||
|
||||
it('server2 - search', function() {
|
||||
return server2.request({uri: '/-/all'})
|
||||
.status(200)
|
||||
.then(check);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,14 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
let assert = require('assert');
|
||||
|
||||
function readfile(x) {
|
||||
return require('fs').readFileSync(__dirname + '/' + x);
|
||||
}
|
||||
|
||||
function sha(x) {
|
||||
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex');
|
||||
}
|
||||
const assert = require('assert');
|
||||
const utils = require ('../lib/test.utils');
|
||||
|
||||
module.exports = function() {
|
||||
let server = process.server;
|
||||
|
@ -22,7 +15,7 @@ module.exports = function() {
|
|||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: JSON.parse(readfile('fixtures/scoped.json')),
|
||||
json: require('./scoped.json'),
|
||||
}).status(201);
|
||||
});
|
||||
|
||||
|
@ -33,7 +26,7 @@ module.exports = function() {
|
|||
.status(200)
|
||||
.then(function(body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
||||
assert.strictEqual(utils.generateSha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -42,7 +35,7 @@ module.exports = function() {
|
|||
.status(200)
|
||||
.then(function(body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
||||
assert.strictEqual(utils.generateSha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
||||
});
|
||||
});
|
||||
|
57
test/functional/readme/pkg-readme.json
Normal file
57
test/functional/readme/pkg-readme.json
Normal file
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
"_id": "readme-test",
|
||||
"name": "readme-test",
|
||||
"description": "",
|
||||
"dist-tags": {
|
||||
"foo": "0.0.0",
|
||||
"latest": "0.0.0"
|
||||
},
|
||||
"versions": {
|
||||
"0.0.0": {
|
||||
"name": "test-readme",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": ""
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"_id": "test-readme@0.0.0",
|
||||
"dist": {
|
||||
"shasum": "8ee7331cbc641581b1a8cecd9d38d744a8feb863",
|
||||
"tarball": "http:\/\/localhost:1234\/test-readme\/-\/test-readme-0.0.0.tgz"
|
||||
},
|
||||
"_from": ".",
|
||||
"_npmVersion": "1.3.1",
|
||||
"_npmUser": {
|
||||
"name": "alex",
|
||||
"email": "alex@kocharin.ru"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "juan",
|
||||
"email": "juanpicado19@gmail.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"readme": "this is a readme",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "juan",
|
||||
"email": "juanpicado19@gmail.com"
|
||||
}
|
||||
],
|
||||
"_attachments": {
|
||||
"test-readme-0.0.0.tgz": {
|
||||
"content_type": "application\/octet-stream",
|
||||
"data": "H4sIAAAAAAAAA+2TsW7CMBCGM\/spTh6YKHUSIJLXqkPnrixWcIMLsS3btCDEu\/fs0Ba1SFVVVISUP8Odzqf\/zlY+K+qlaOSt7eLo2RudnVmMsel4DBjzasKOY1JZlJDlRVkU5aSspnnG8pIVOZ6fe5FTWvsgHK7yV5\/uLvARr0Q7qkUrKadB+mCXzY2Wr9q2TjZ0SF+k88poPGUj\/LAyl752yoauioVWqJgpPZcb\/Hmw0jV4ynfJEw9lvTAwo\/fOGcdBG4h18FbW6knJ+YzCYAByowLkdD+kTlrjVTBumzy2Nq7XqIDea7eKY7FJrMPCuG6Hlaql9rHr4fGO7i\/9pFcl+4X\/rWhX557xA\/9FVZ3gv+j5\/w9F+jl8g58c0OeQyCdH3HOglETsObxTTw7McwLJClt+wzz5JD45IPEcEHjMEfg0r8M9pQfaOSDs5NLP16tXr15XqzeJD6m5AAwAAA==",
|
||||
"length": 352
|
||||
}
|
||||
}
|
||||
}
|
46
test/functional/readme/readme.spec.js
Normal file
46
test/functional/readme/readme.spec.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Created by jpicado on 7/24/17.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
module.exports = function() {
|
||||
let server = process.server;
|
||||
let server2 = process.server2;
|
||||
|
||||
describe('should test readme', () => {
|
||||
|
||||
before(function() {
|
||||
return server.request({
|
||||
uri: '/readme-test',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: require('./pkg-readme.json'),
|
||||
}).status(201);
|
||||
});
|
||||
|
||||
it('add pkg', function() {});
|
||||
|
||||
describe('should check readme file', () => {
|
||||
const matchReadme = (server) => {
|
||||
return server.request({
|
||||
uri: '/-/verdaccio/package/readme/readme-test'
|
||||
}).status(200).then(function(body) {
|
||||
assert.equal(body, '<p>this is a readme</p>\n');
|
||||
});
|
||||
};
|
||||
|
||||
it('server1 - readme', function() {
|
||||
return matchReadme(server);
|
||||
});
|
||||
|
||||
it('server2 - readme', function() {
|
||||
return matchReadme(server2);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
};
|
|
@ -47,6 +47,11 @@ packages:
|
|||
allow_publish: test anonymous
|
||||
proxy_access: server1
|
||||
|
||||
'readme-*':
|
||||
allow_access: test anonymous
|
||||
allow_publish: test anonymous
|
||||
proxy_access: server1
|
||||
|
||||
'test-nullstorage*':
|
||||
allow_access: all
|
||||
allow_publish: all
|
||||
|
|
113
test/functional/tags/preserve_tags.js
Normal file
113
test/functional/tags/preserve_tags.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const utils = require ('../lib/test.utils');
|
||||
|
||||
module.exports = function() {
|
||||
let server = process.server;
|
||||
let server2 = process.server2;
|
||||
let express = process.express;
|
||||
|
||||
describe('should test preserve tags when publishing something', () => {
|
||||
|
||||
before(function() {
|
||||
return server.request({
|
||||
uri: '/testpkg-preserve',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: require('./preserve_tags.json'),
|
||||
}).status(201);
|
||||
});
|
||||
|
||||
it('add pkg', function() {});
|
||||
|
||||
describe('should check sha integrity', () => {
|
||||
|
||||
const matchTarBallSha = (server) => {
|
||||
return server.getTarball('testpkg-preserve', 'testpkg-preserve-0.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function(body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(utils.generateSha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
|
||||
});
|
||||
};
|
||||
|
||||
it('server1 should match with sha key from published package', () => {
|
||||
return matchTarBallSha(server);
|
||||
});
|
||||
|
||||
it('server2 should match with sha key from published packagel', () => {
|
||||
matchTarBallSha(server2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should match dist-tags', () => {
|
||||
const matchDisTags = (server, port) => {
|
||||
return server.getPackage('testpkg-preserve')
|
||||
.status(200)
|
||||
.then(function(body) {
|
||||
assert.equal(body.name, 'testpkg-preserve');
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-preserve');
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, `http://localhost:${port}/testpkg-preserve/-/testpkg-preserve-0.0.0.tgz`);
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'});
|
||||
});
|
||||
};
|
||||
|
||||
it('server1 should be able to match latest dist-tags correctly', () => {
|
||||
return matchDisTags(server, '55551');
|
||||
});
|
||||
|
||||
it('server2 should be able to match latest dist-tags correctly', function() {
|
||||
return matchDisTags(server2, '55552');
|
||||
});
|
||||
});
|
||||
|
||||
describe('should test search', function() {
|
||||
const check = (obj) => {
|
||||
obj['testpkg-preserve'].time.modified = '2014-10-02T07:07:51.000Z';
|
||||
assert.deepEqual(obj['testpkg-preserve'],
|
||||
{
|
||||
'name': 'testpkg-preserve',
|
||||
'description': '',
|
||||
'author': '',
|
||||
'license': 'ISC',
|
||||
'dist-tags': {
|
||||
latest: '0.0.0'
|
||||
},
|
||||
'maintainers': [{
|
||||
name: 'alex',
|
||||
email: 'alex@kocharin.ru'
|
||||
}],
|
||||
'readmeFilename': '',
|
||||
'time': {
|
||||
modified: '2014-10-02T07:07:51.000Z'
|
||||
},
|
||||
'versions': {},
|
||||
'repository': {
|
||||
type: 'git', url: ''}
|
||||
});
|
||||
};
|
||||
|
||||
before(function() {
|
||||
express.get('/-/all', (req, res) => {
|
||||
res.send({});
|
||||
});
|
||||
});
|
||||
|
||||
it('server1 - search', () => {
|
||||
return server.request({uri: '/-/all'})
|
||||
.status(200)
|
||||
.then(check);
|
||||
});
|
||||
|
||||
it('server2 - search', () => {
|
||||
return server2.request({uri: '/-/all'})
|
||||
.status(200)
|
||||
.then(check);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"_id": "testpkg-newnpmreg",
|
||||
"name": "testpkg-newnpmreg",
|
||||
"_id": "testpkg-preserve",
|
||||
"name": "testpkg-preserve",
|
||||
"description": "",
|
||||
"dist-tags": {
|
||||
"foo": "0.0.0",
|
||||
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"versions": {
|
||||
"0.0.0": {
|
||||
"name": "testpkg-newnpmreg",
|
||||
"name": "testpkg-preserve",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
|
@ -21,10 +21,10 @@
|
|||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"_id": "testpkg-newnpmreg@0.0.0",
|
||||
"_id": "testpkg-preserve@0.0.0",
|
||||
"dist": {
|
||||
"shasum": "8ee7331cbc641581b1a8cecd9d38d744a8feb863",
|
||||
"tarball": "http:\/\/localhost:1234\/testpkg-newnpmreg\/-\/testpkg-newnpmreg-0.0.0.tgz"
|
||||
"tarball": "http:\/\/localhost:1234\/testpkg-preserve\/-\/testpkg-preserve-0.0.0.tgz"
|
||||
},
|
||||
"_from": ".",
|
||||
"_npmVersion": "1.3.1",
|
||||
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
],
|
||||
"_attachments": {
|
||||
"testpkg-newnpmreg-0.0.0.tgz": {
|
||||
"testpkg-preserve-0.0.0.tgz": {
|
||||
"content_type": "application\/octet-stream",
|
||||
"data": "H4sIAAAAAAAAA+2TsW7CMBCGM\/spTh6YKHUSIJLXqkPnrixWcIMLsS3btCDEu\/fs0Ba1SFVVVISUP8Odzqf\/zlY+K+qlaOSt7eLo2RudnVmMsel4DBjzasKOY1JZlJDlRVkU5aSspnnG8pIVOZ6fe5FTWvsgHK7yV5\/uLvARr0Q7qkUrKadB+mCXzY2Wr9q2TjZ0SF+k88poPGUj\/LAyl752yoauioVWqJgpPZcb\/Hmw0jV4ynfJEw9lvTAwo\/fOGcdBG4h18FbW6knJ+YzCYAByowLkdD+kTlrjVTBumzy2Nq7XqIDea7eKY7FJrMPCuG6Hlaql9rHr4fGO7i\/9pFcl+4X\/rWhX557xA\/9FVZ3gv+j5\/w9F+jl8g58c0OeQyCdH3HOglETsObxTTw7McwLJClt+wzz5JD45IPEcEHjMEfg0r8M9pQfaOSDs5NLP16tXr15XqzeJD6m5AAwAAA==",
|
||||
"length": 352
|
Loading…
Reference in a new issue