From cda92ac5ab4105b2e458b7434bb987c87b747dab Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Wed, 2 Aug 2017 20:45:21 +0200 Subject: [PATCH] refactor: relocate unit test --- test/functional/{auth => adduser}/logout.js | 0 test/functional/index.js | 6 +-- test/functional/{ => notifications}/notify.js | 2 +- test/functional/{ => package}/access.js | 2 +- .../{toplevel.js => basic_system.test.js} | 20 ++++----- test/unit/config.js | 17 ------- test/unit/config.spec.js | 45 +++++++++++++++++++ test/unit/listen_addr.js | 4 +- test/unit/{search.js => search.spec.js} | 0 9 files changed, 62 insertions(+), 34 deletions(-) rename test/functional/{auth => adduser}/logout.js (100%) rename test/functional/{ => notifications}/notify.js (98%) rename test/functional/{ => package}/access.js (97%) rename test/unit/{toplevel.js => basic_system.test.js} (62%) delete mode 100644 test/unit/config.js create mode 100644 test/unit/config.spec.js rename test/unit/{search.js => search.spec.js} (100%) diff --git a/test/functional/auth/logout.js b/test/functional/adduser/logout.js similarity index 100% rename from test/functional/auth/logout.js rename to test/functional/adduser/logout.js diff --git a/test/functional/index.js b/test/functional/index.js index a2e7e9f42..d3569230c 100644 --- a/test/functional/index.js +++ b/test/functional/index.js @@ -56,7 +56,7 @@ describe('Create registry servers', function() { /* test for before() */ }); - require('./access')(); + require('./package/access')(); require('./basic')(); require('./gh29')(); require('./tags')(); @@ -71,10 +71,10 @@ describe('Create registry servers', function() { require('./package/scoped.spec')(); require('./security')(); require('./adduser')(); - require('./auth/logout')(); + require('./adduser/logout')(); require('./addtag')(); require('./plugins')(); - require('./notify')(); + require('./notifications/notify')(); // requires packages published to server1/server2 require('./uplink.cache')(); diff --git a/test/functional/notify.js b/test/functional/notifications/notify.js similarity index 98% rename from test/functional/notify.js rename to test/functional/notifications/notify.js index b8d973e3d..f15cc7b86 100644 --- a/test/functional/notify.js +++ b/test/functional/notifications/notify.js @@ -2,7 +2,7 @@ const assert = require('assert'); const _ = require('lodash'); -const notify = require('../../src/lib/notify').notify; +const notify = require('../../../src/lib/notify').notify; module.exports = function() { const express = process.express; diff --git a/test/functional/access.js b/test/functional/package/access.js similarity index 97% rename from test/functional/access.js rename to test/functional/package/access.js index a95a26f50..2dd57fa31 100644 --- a/test/functional/access.js +++ b/test/functional/package/access.js @@ -44,7 +44,7 @@ module.exports = function() { function checkPublish(auth, pkg, ok) { it(`${(ok ? 'allows' : 'forbids')} publish ${auth} to ${pkg}`, function() { server.authstr = auth ? buildToken(auth) : undefined; - const req = server.putPackage(pkg, require('./lib/package')(pkg)); + const req = server.putPackage(pkg, require('../lib/package')(pkg)); if (ok) { return req.status(404).body_error(/this package cannot be added/); } else { diff --git a/test/unit/toplevel.js b/test/unit/basic_system.test.js similarity index 62% rename from test/unit/toplevel.js rename to test/unit/basic_system.test.js index 411a7f4de..424b34525 100644 --- a/test/unit/toplevel.js +++ b/test/unit/basic_system.test.js @@ -1,13 +1,13 @@ 'use strict'; -let assert = require('assert'); -let express = require('express'); -let request = require('request'); -let rimraf = require('rimraf'); -let verdaccio = require('../../'); -let config = require('./partials/config'); +const assert = require('assert'); +const express = require('express'); +const request = require('request'); +const rimraf = require('rimraf'); +const verdaccio = require('../../'); +const config = require('./partials/config'); -describe('toplevel', function() { +describe('basic system test', function() { let port; before(function(done) { @@ -18,14 +18,14 @@ describe('toplevel', function() { let app = express(); app.use(verdaccio(config)); - let server = require('http').createServer(app); + const server = require('http').createServer(app); server.listen(0, function() { port = server.address().port; done(); }); }); - it('should respond on /', function(done) { + it('server should respond on /', function(done) { request({ url: 'http://localhost:' + port + '/', }, function(err, res, body) { @@ -35,7 +35,7 @@ describe('toplevel', function() { }); }); - it('should respond on /whatever', function(done) { + it('server should respond on /whatever', function(done) { request({ url: 'http://localhost:' + port + '/whatever', }, function(err, res, body) { diff --git a/test/unit/config.js b/test/unit/config.js deleted file mode 100644 index ab2e5f229..000000000 --- a/test/unit/config.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const config_hash = require('./partials/config'); -const Config = require('../../src/lib/config'); - - -describe('Config', function() { - before(function() { - this.config = new Config(config_hash); - }); - - it('npmjs uplink should have a default cache option that is true', function() { - assert.equal(this.config.uplinks['npmjs'].cache, true); - }); -}); - diff --git a/test/unit/config.spec.js b/test/unit/config.spec.js new file mode 100644 index 000000000..00bb3ce4d --- /dev/null +++ b/test/unit/config.spec.js @@ -0,0 +1,45 @@ +'use strict'; + +const assert = require('assert'); +const Utils = require('../../src/lib/utils'); +const Config = require('../../src/lib/config'); +const path = require('path'); +const _ = require('lodash'); + +const resolveConf = (conf) => { + const fullConfigPath = path.join(__dirname, `../../conf/${conf}.yaml`); + return fullConfigPath; +}; + +const validateConfigFile = (config) => { + assert.ok(_.isObject(config.uplinks['npmjs'])); +} + +describe('Config file', function() { + before(function() { + + this.config = new Config(Utils.parseConfigFile(resolveConf('full'))); + }); + + describe('Config file', function() { + it('parse full.yaml', function () { + const config = new Config(Utils.parseConfigFile(resolveConf('full'))); + validateConfigFile(config); + }); + + it('parse docker.yaml', function () { + const config = new Config(Utils.parseConfigFile(resolveConf('docker'))); + validateConfigFile(config); + }); + + it('parse default.yaml', function () { + const config = new Config(Utils.parseConfigFile(resolveConf('default'))); + validateConfigFile(config); + }); + }); + + it('npmjs uplink should have a default cache option that is true', () => { + assert.equal(this.config.uplinks['npmjs'].cache, true); + }); +}); + diff --git a/test/unit/listen_addr.js b/test/unit/listen_addr.js index 67da96168..491e09d7f 100644 --- a/test/unit/listen_addr.js +++ b/test/unit/listen_addr.js @@ -1,7 +1,7 @@ 'use strict'; -let assert = require('assert'); -let parse = require('../../src/lib/utils').parse_address; +const assert = require('assert'); +const parse = require('../../src/lib/utils').parse_address; describe('Parse address', function() { function addTest(what, proto, host, port) { diff --git a/test/unit/search.js b/test/unit/search.spec.js similarity index 100% rename from test/unit/search.js rename to test/unit/search.spec.js