mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
refactor: rename unit test clean up
This commit is contained in:
parent
644c0981db
commit
d53ce9750b
8 changed files with 46 additions and 34 deletions
|
@ -1,9 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
describe('config.yaml', function() {
|
||||
it('should be parseable', function() {
|
||||
let source = require('fs').readFileSync(__dirname + '/../../conf/default.yaml', 'utf8');
|
||||
require('js-yaml').safeLoad(source);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const parse = require('../../src/lib/utils').parse_address;
|
||||
|
||||
describe('Parse address', function() {
|
||||
describe('Parse listen address', function() {
|
||||
function addTest(what, proto, host, port) {
|
||||
it(what, function() {
|
||||
if (proto === null) {
|
||||
if (_.isNull(proto)) {
|
||||
assert.strictEqual(parse(what), null);
|
||||
} else if (port) {
|
||||
assert.deepEqual(parse(what), {
|
|
@ -6,55 +6,67 @@ let merge = require('../../src/lib/storage')._merge_versions;
|
|||
|
||||
require('../../src/lib/logger').setup([]);
|
||||
|
||||
describe('Merge', function() {
|
||||
describe('merge versions', function() {
|
||||
|
||||
it('simple', function() {
|
||||
let x = {
|
||||
let pkg = {
|
||||
'versions': {a: 1, b: 1, c: 1},
|
||||
'dist-tags': {},
|
||||
};
|
||||
merge(x, {versions: {a: 2, q: 2}});
|
||||
assert.deepEqual(x, {
|
||||
|
||||
merge(pkg, {versions: {a: 2, q: 2}});
|
||||
|
||||
assert.deepEqual(pkg, {
|
||||
'versions': {a: 1, b: 1, c: 1, q: 2},
|
||||
'dist-tags': {},
|
||||
});
|
||||
});
|
||||
|
||||
it('dist-tags - compat', function() {
|
||||
let x = {
|
||||
let pkg = {
|
||||
'versions': {},
|
||||
'dist-tags': {q: '1.1.1', w: '2.2.2'},
|
||||
};
|
||||
merge(x, {'dist-tags': {q: '2.2.2', w: '3.3.3', t: '4.4.4'}});
|
||||
assert.deepEqual(x, {
|
||||
|
||||
merge(pkg, {'dist-tags': {q: '2.2.2', w: '3.3.3', t: '4.4.4'}});
|
||||
|
||||
assert.deepEqual(pkg, {
|
||||
'versions': {},
|
||||
'dist-tags': {q: '2.2.2', w: '3.3.3', t: '4.4.4'},
|
||||
});
|
||||
});
|
||||
|
||||
it('dist-tags - staging', function() {
|
||||
let x = {
|
||||
|
||||
let pkg = {
|
||||
versions: {},
|
||||
// we've been locally publishing 1.1.x in preparation for the next
|
||||
// public release
|
||||
'dist-tags': {q:'1.1.10',w:'2.2.2'},
|
||||
}
|
||||
};
|
||||
// 1.1.2 is the latest public release, but we want to continue testing
|
||||
// against our local 1.1.10, which may end up published as 1.1.3 in the
|
||||
// future
|
||||
merge(x, {'dist-tags':{q:'1.1.2',w:'3.3.3',t:'4.4.4'}})
|
||||
assert.deepEqual(x, {
|
||||
|
||||
merge(pkg, {'dist-tags':{q:'1.1.2',w:'3.3.3',t:'4.4.4'}})
|
||||
|
||||
assert.deepEqual(pkg, {
|
||||
versions: {},
|
||||
'dist-tags': {q:'1.1.10',w:'3.3.3',t:'4.4.4'},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('semver_sort', function() {
|
||||
|
||||
assert.deepEqual(semver_sort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b']),
|
||||
['1.2.3a',
|
||||
'1.2.3-b',
|
||||
'1.2.3c',
|
||||
'1.2.3']
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -7,19 +7,19 @@ require('../../src/lib/logger').setup([]);
|
|||
|
||||
describe('tag_version', function() {
|
||||
it('add new one', function() {
|
||||
let x = {
|
||||
let pkg = {
|
||||
'versions': {},
|
||||
'dist-tags': {},
|
||||
};
|
||||
assert(tag_version(x, '1.1.1', 'foo', {}));
|
||||
assert.deepEqual(x, {
|
||||
assert(tag_version(pkg, '1.1.1', 'foo', {}));
|
||||
assert.deepEqual(pkg, {
|
||||
'versions': {},
|
||||
'dist-tags': {foo: '1.1.1'},
|
||||
});
|
||||
});
|
||||
|
||||
it('add (compat)', function() {
|
||||
let x = {
|
||||
const x = {
|
||||
'versions': {},
|
||||
'dist-tags': {foo: '1.1.0'},
|
||||
};
|
|
@ -5,9 +5,16 @@
|
|||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
|
||||
describe('index.js app', test('index.js'));
|
||||
describe('index.js app', test('../endpoint/index.js'));
|
||||
describe('index.js app', test('index.js'));
|
||||
/**
|
||||
* Validate.
|
||||
app.param('package', validate_pkg);
|
||||
app.param('filename', validate_name);
|
||||
app.param('tag', validate_name);
|
||||
app.param('version', validate_name);
|
||||
app.param('revision', validate_name);
|
||||
app.param('token', validate_name);
|
||||
*/
|
||||
describe('api endpoint app.param()', test('../endpoint/index.js'));
|
||||
|
||||
function test(file) {
|
||||
return function() {
|
||||
|
@ -17,8 +24,9 @@ function test(file) {
|
|||
|
||||
let very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
|
||||
let m;
|
||||
let params = {};
|
||||
let appParams = {};
|
||||
|
||||
// look up for matches in the source code
|
||||
while ((m = very_scary_regexp.exec(source)) != null) {
|
||||
if (m[1] === 'set') continue;
|
||||
|
||||
|
@ -28,16 +36,16 @@ function test(file) {
|
|||
inner.split('/').forEach(function(x) {
|
||||
t = x.match(/^:([^?:]*)\??$/);
|
||||
if (m[1] === 'param') {
|
||||
params[x] = 'ok';
|
||||
appParams[x] = 'ok';
|
||||
} else if (t) {
|
||||
params[t[1]] = params[t[1]] || m[0].trim();
|
||||
appParams[t[1]] = appParams[t[1]] || m[0].trim();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Object.keys(params).forEach(function(param) {
|
||||
Object.keys(appParams).forEach(function(param) {
|
||||
it('should validate ":'+param+'"', function() {
|
||||
assert.equal(params[param], 'ok');
|
||||
assert.equal(appParams[param], 'ok');
|
||||
});
|
||||
});
|
||||
};
|
Loading…
Add table
Reference in a new issue