0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

(test): Refactor hash method

This commit is contained in:
Juan Picado @jotadeveloper 2017-06-30 23:10:30 +02:00
parent 582285a37f
commit e41dad708e
No known key found for this signature in database
GPG key ID: 18AC54485952D158

View file

@ -5,8 +5,12 @@ require('./lib/startup');
const assert = require('assert'); const assert = require('assert');
const crypto = require('crypto'); const crypto = require('crypto');
function readfile(x) { function readfile(folderPath) {
return require('fs').readFileSync(__dirname + '/' + x); return require('fs').readFileSync(__dirname + '/' + folderPath);
}
function createHash() {
return crypto.createHash('sha1');
} }
module.exports = function() { module.exports = function() {
@ -18,6 +22,7 @@ module.exports = function() {
}); });
describe('testpkg', function() { describe('testpkg', function() {
before(function() { before(function() {
return server.addPackage('testpkg'); return server.addPackage('testpkg');
}); });
@ -51,7 +56,7 @@ module.exports = function() {
it('uploading new package version (bad sha)', function() { it('uploading new package version (bad sha)', function() {
let pkg = require('./lib/package')('testpkg'); let pkg = require('./lib/package')('testpkg');
pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex'); pkg.dist.shasum = createHash().update('fake').digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg) return server.putVersion('testpkg', '0.0.1', pkg)
.status(400) .status(400)
@ -60,8 +65,8 @@ module.exports = function() {
describe('version', function() { describe('version', function() {
before(function() { before(function() {
let pkg = require('./lib/package')('testpkg'); const pkg = require('./lib/package')('testpkg');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex'); pkg.dist.shasum = createHash().update(readfile('fixtures/binary')).digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg) return server.putVersion('testpkg', '0.0.1', pkg)
.status(201) .status(201)
.body_ok(/published/); .body_ok(/published/);