diff --git a/jest.config.js b/jest.config.js index 766821435..e6b3da7e6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,13 +9,12 @@ module.exports = { 'fixtures' ], testEnvironment: 'jest-environment-jsdom-global', - testRegex: '(/test/unit.*\\.spec|test/functional.*\\.func|/test/webui/.*\\.spec)\\.js', - // 'testRegex': '(test/functional.*\\.func)\\.js' + testRegex: '(/test/unit.*\\.spec|test/functional.*\\.func|/test/unit/webui/.*\\.spec)\\.js', setupFiles: [ - './test/webui/global.js' + './test/unit/setup-webui.js' ], modulePathIgnorePatterns: [ - 'global.js' + 'setup-webui.js' ], testPathIgnorePatterns: [ '__snapshots__' diff --git a/src/lib/plugin-loader.js b/src/lib/plugin-loader.js index a6e5101e2..6db23b78f 100644 --- a/src/lib/plugin-loader.js +++ b/src/lib/plugin-loader.js @@ -49,7 +49,7 @@ function loadPlugin(config: Config, pluginConfigs: any, params: any, sanityCheck let plugin; // try local plugins first - plugin = tryLoad(Path.resolve(__dirname + '/..//plugins', pluginId)); + plugin = tryLoad(Path.resolve(__dirname + '/../plugins', pluginId)); // npm package if (plugin === null && pluginId.match(/^[^\.\/]/)) { diff --git a/test/e2e/puppeteer_environment.js b/test/e2e/puppeteer_environment.js index 82857b7d9..c07d39802 100644 --- a/test/e2e/puppeteer_environment.js +++ b/test/e2e/puppeteer_environment.js @@ -4,9 +4,9 @@ const puppeteer = require('puppeteer'); const fs = require('fs'); const os = require('os'); const path = require('path'); -const {VerdaccioConfig} = require("../src/verdaccio-server"); -const VerdaccioProcess = require("../src/server_process"); -const Server = require("../src/server"); +const {VerdaccioConfig} = require("../lib/verdaccio-server"); +const VerdaccioProcess = require("../lib/server_process"); +const Server = require("../lib/server"); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); diff --git a/test/functional/index.func.js b/test/functional/index.func.js index 0c3c870a6..c7969da22 100644 --- a/test/functional/index.func.js +++ b/test/functional/index.func.js @@ -6,11 +6,11 @@ import path from 'path'; import {setup} from '../../src/lib/logger'; setup(); -import {VerdaccioConfig} from '../src/verdaccio-server'; -import VerdaccioProcess from '../src/server_process'; +import {VerdaccioConfig} from '../lib/verdaccio-server'; +import VerdaccioProcess from '../lib/server_process'; import ExpressServer from './lib/simple_server'; -import Server from '../src/server'; -import type {IServerProcess, IServerBridge} from '../flow/types'; +import Server from '../lib/server'; +import type {IServerProcess, IServerBridge} from '../types'; import basic from './basic/basic.spec'; import packageAccess from './package/access.spec'; diff --git a/test/helper/register.js b/test/lib/helper/register.js similarity index 76% rename from test/helper/register.js rename to test/lib/helper/register.js index d98b70e0c..ed1f73f29 100644 --- a/test/helper/register.js +++ b/test/lib/helper/register.js @@ -2,5 +2,5 @@ require("babel-polyfill"); require('babel-core/register')({ ignore: /node_modules\/(?!ProjectB)/, sourceMap: 'inline', -}); -require('../../src/lib/cli'); \ No newline at end of file +}); +require('../../../src/lib/cli'); diff --git a/test/helper/verdaccio-test b/test/lib/helper/verdaccio-test similarity index 58% rename from test/helper/verdaccio-test rename to test/lib/helper/verdaccio-test index 47b5c88bd..551a762ae 100755 --- a/test/helper/verdaccio-test +++ b/test/lib/helper/verdaccio-test @@ -1,3 +1,3 @@ #!/usr/bin/env node require("babel-register"); -require('../../src/lib/cli'); +require('../../../src/lib/cli'); diff --git a/test/src/request.js b/test/lib/request.js similarity index 98% rename from test/src/request.js rename to test/lib/request.js index 30d6d708a..81f90aa60 100644 --- a/test/src/request.js +++ b/test/lib/request.js @@ -3,7 +3,7 @@ import assert from 'assert'; import request from 'request'; import _ from 'lodash'; -import type {IRequestPromise} from '../flow/types'; +import type {IRequestPromise} from '../types'; const requestData = Symbol('smart_request_data'); diff --git a/test/src/server.js b/test/lib/server.js similarity index 99% rename from test/src/server.js rename to test/lib/server.js index 5a119b587..7822bda31 100644 --- a/test/src/server.js +++ b/test/lib/server.js @@ -3,7 +3,7 @@ import _ from 'lodash'; import assert from 'assert'; import smartRequest from './request'; -import type {IServerBridge} from '../flow/types'; +import type {IServerBridge} from '../types'; import {HEADERS} from '../../src/lib/constants'; const buildAuthHeader = (user, pass): string => { diff --git a/test/src/server_process.js b/test/lib/server_process.js similarity index 98% rename from test/src/server_process.js rename to test/lib/server_process.js index 3422bb472..38cabbcd6 100644 --- a/test/src/server_process.js +++ b/test/lib/server_process.js @@ -3,7 +3,7 @@ import _ from 'lodash'; import rimRaf from 'rimraf'; import path from 'path'; import {fork} from 'child_process'; -import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../flow/types'; +import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../types'; export default class VerdaccioProcess implements IServerProcess { diff --git a/test/src/verdaccio-server.js b/test/lib/verdaccio-server.js similarity index 87% rename from test/src/verdaccio-server.js rename to test/lib/verdaccio-server.js index fd2a44d77..5ecc35886 100644 --- a/test/src/verdaccio-server.js +++ b/test/lib/verdaccio-server.js @@ -1,5 +1,5 @@ // @flow -import type {IVerdaccioConfig} from '../flow/types'; +import type {IVerdaccioConfig} from '../types'; export class VerdaccioConfig implements IVerdaccioConfig { diff --git a/test/flow/types.js b/test/types/index.js similarity index 100% rename from test/flow/types.js rename to test/types/index.js diff --git a/test/unit/api.pkg.access.spec.js b/test/unit/api/api.pkg.access.spec.js similarity index 87% rename from test/unit/api.pkg.access.spec.js rename to test/unit/api/api.pkg.access.spec.js index 2da04c45a..60f630265 100644 --- a/test/unit/api.pkg.access.spec.js +++ b/test/unit/api/api.pkg.access.spec.js @@ -3,12 +3,12 @@ import _ from 'lodash'; import path from 'path'; import rimraf from 'rimraf'; -import {HEADERS} from '../../src/lib/constants'; -import configDefault from './partials/config/access'; -import Config from '../../src/lib/config'; -import endPointAPI from '../../src/api/index'; +import {HEADERS} from '../../../src/lib/constants'; +import configDefault from '../partials/config/access'; +import Config from '../../../src/lib/config'; +import endPointAPI from '../../../src/api/index'; -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); describe('api with no limited access configuration', () => { let config; diff --git a/test/unit/api.spec.js b/test/unit/api/api.spec.js similarity index 97% rename from test/unit/api.spec.js rename to test/unit/api/api.spec.js index bd5091f6d..d7103ce9c 100644 --- a/test/unit/api.spec.js +++ b/test/unit/api/api.spec.js @@ -3,14 +3,14 @@ import _ from 'lodash'; import path from 'path'; import rimraf from 'rimraf'; -import configDefault from './partials/config'; -import publishMetadata from './partials/publish-api'; -import forbiddenPlace from './partials/forbidden-place'; -import Config from '../../src/lib/config'; -import endPointAPI from '../../src/api/index'; -import {HEADERS} from '../../src/lib/constants'; +import configDefault from '../partials/config/index'; +import publishMetadata from '../partials/publish-api'; +import forbiddenPlace from '../partials/forbidden-place'; +import Config from '../../../src/lib/config'; +import endPointAPI from '../../../src/api/index'; +import {HEADERS} from '../../../src/lib/constants'; -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); const credentials = { name: 'Jota', password: 'secretPass' }; describe('endpoint unit test', () => { @@ -19,7 +19,7 @@ describe('endpoint unit test', () => { jest.setTimeout(10000); beforeAll(function(done) { - const store = path.join(__dirname, './partials/store/test-storage'); + const store = path.join(__dirname, '../partials/store/test-storage'); rimraf(store, async () => { const configForTest = _.clone(configDefault); configForTest.auth = { diff --git a/test/unit/auth.spec.js b/test/unit/api/auth.spec.js similarity index 90% rename from test/unit/auth.spec.js rename to test/unit/api/auth.spec.js index 829ef257a..cdc68d896 100644 --- a/test/unit/auth.spec.js +++ b/test/unit/api/auth.spec.js @@ -1,14 +1,14 @@ // @flow -import Auth from '../../src/lib/auth'; +import Auth from '../../../src/lib/auth'; // $FlowFixMe -import configExample from './partials/config'; +import configExample from '../partials/config/index'; // $FlowFixMe -import configPlugins from './partials/config/plugin'; -import AppConfig from '../../src/lib/config'; -import {setup} from '../../src/lib/logger'; +import configPlugins from '../partials/config/plugin'; +import AppConfig from '../../../src/lib/config'; +import {setup} from '../../../src/lib/logger'; -import type {IAuth} from '../../types'; +import type {IAuth} from '../../../types/index'; import type {Config} from '@verdaccio/types'; setup(configExample.logs); diff --git a/test/unit/basic_system.spec.js b/test/unit/api/basic_system.spec.js similarity index 91% rename from test/unit/basic_system.spec.js rename to test/unit/api/basic_system.spec.js index 00d56cb54..2f1f2a0f9 100644 --- a/test/unit/basic_system.spec.js +++ b/test/unit/api/basic_system.spec.js @@ -1,11 +1,11 @@ -import endPointAPI from '../../src/api/index'; +import endPointAPI from '../../../src/api/index'; const assert = require('assert'); const express = require('express'); const request = require('request'); const rimraf = require('rimraf'); -const config = require('./partials/config'); +const config = require('../partials/config/index'); const app = express(); const server = require('http').createServer(app); diff --git a/test/unit/cli.spec.js b/test/unit/api/cli.spec.js similarity index 89% rename from test/unit/cli.spec.js rename to test/unit/api/cli.spec.js index 8a4dc5e1a..c39a3c7b5 100644 --- a/test/unit/cli.spec.js +++ b/test/unit/api/cli.spec.js @@ -1,10 +1,10 @@ -import startServer from '../../src'; -import {getListListenAddresses} from '../../src/lib/bootstrap'; -import config from './partials/config'; +import startServer from '../../../src/index'; +import {getListListenAddresses} from '../../../src/lib/bootstrap'; +import config from '../partials/config/index'; import path from 'path'; import _ from 'lodash'; -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); describe('startServer via API', () => { diff --git a/test/unit/config.spec.js b/test/unit/api/config.spec.js similarity index 91% rename from test/unit/config.spec.js rename to test/unit/api/config.spec.js index 6814896e3..7e176404b 100644 --- a/test/unit/config.spec.js +++ b/test/unit/api/config.spec.js @@ -1,10 +1,10 @@ const assert = require('assert'); -const Utils = require('../../src/lib/utils'); -const Config = require('../../src/lib/config'); +const Utils = require('../../../src/lib/utils'); +const Config = require('../../../src/lib/config'); const path = require('path'); const _ = require('lodash'); -const resolveConf = (conf) => path.join(__dirname, `../../conf/${conf}.yaml`); +const resolveConf = (conf) => path.join(__dirname, `../../../conf/${conf}.yaml`); const checkUplink = (config) => { assert.equal(_.isObject(config.uplinks['npmjs']), true); diff --git a/test/unit/listen_addr.spec.js b/test/unit/api/listen_addr.spec.js similarity index 95% rename from test/unit/listen_addr.spec.js rename to test/unit/api/listen_addr.spec.js index c2bd9db47..392e0da31 100644 --- a/test/unit/listen_addr.spec.js +++ b/test/unit/api/listen_addr.spec.js @@ -1,6 +1,6 @@ const assert = require('assert'); const _ = require('lodash'); -const parse = require('../../src/lib/utils').parse_address; +const parse = require('../../../src/lib/utils').parse_address; describe('Parse listen address', () => { function addTest(what, proto, host, port) { diff --git a/test/unit/local-storage.spec.js b/test/unit/api/local-storage.spec.js similarity index 97% rename from test/unit/local-storage.spec.js rename to test/unit/api/local-storage.spec.js index c54f340d0..71275a990 100644 --- a/test/unit/local-storage.spec.js +++ b/test/unit/api/local-storage.spec.js @@ -2,17 +2,17 @@ import rimRaf from 'rimraf'; import path from 'path'; -import LocalStorage from '../../src/lib/local-storage'; -import AppConfig from '../../src/lib/config'; +import LocalStorage from '../../../src/lib/local-storage'; +import AppConfig from '../../../src/lib/config'; // $FlowFixMe -import configExample from './partials/config'; -import Logger, {setup} from '../../src/lib/logger'; -import {readFile} from '../functional/lib/test.utils'; +import configExample from '../partials/config/index'; +import Logger, {setup} from '../../../src/lib/logger'; +import {readFile} from '../../functional/lib/test.utils'; const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`); import type {Config} from '@verdaccio/types'; -import type {IStorage} from '../../types'; +import type {IStorage} from '../../../types/index'; setup([]); diff --git a/test/unit/no_proxy.spec.js b/test/unit/api/no_proxy.spec.js similarity index 97% rename from test/unit/no_proxy.spec.js rename to test/unit/api/no_proxy.spec.js index 0e288fe6f..f8e9327d0 100644 --- a/test/unit/no_proxy.spec.js +++ b/test/unit/api/no_proxy.spec.js @@ -1,7 +1,7 @@ import assert from 'assert'; -import Storage from '../../src/lib/up-storage'; +import Storage from '../../../src/lib/up-storage'; -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); function setupProxy(host, config, mainconfig) { config.url = host; diff --git a/test/unit/parse_interval.spec.js b/test/unit/api/parse_interval.spec.js similarity index 92% rename from test/unit/parse_interval.spec.js rename to test/unit/api/parse_interval.spec.js index 402575a14..82056e6da 100644 --- a/test/unit/parse_interval.spec.js +++ b/test/unit/api/parse_interval.spec.js @@ -1,5 +1,5 @@ let assert = require('assert'); -let parseInterval = require('../../src/lib/utils').parseInterval; +let parseInterval = require('../../../src/lib/utils').parseInterval; describe('Parse interval', () => { function add_test(str, res) { diff --git a/test/unit/api/plugin_loader.spec.js b/test/unit/api/plugin_loader.spec.js new file mode 100644 index 000000000..906146239 --- /dev/null +++ b/test/unit/api/plugin_loader.spec.js @@ -0,0 +1,79 @@ +import path from 'path'; +import {loadPlugin} from '../../../src/lib/plugin-loader'; +import logger from '../../../src/lib/logger'; + +logger.setup([]); + +describe('plugin loader', () => { + + const relativePath = './partials/test-plugin-storage'; + const buildConf = name => { + return { + self_path: path.join(__dirname, './'), + max_users: 0, + auth: { + [`${relativePath}/${name}`]: {} + } + }; + }; + + describe('auth plugins', () => { + test('testing auth valid plugin loader', () => { + const _config = buildConf('verdaccio-plugin'); + const plugins = loadPlugin(_config, _config.auth, {}, function (plugin) { + return plugin.authenticate || plugin.allow_access || plugin.allow_publish; + }); + + expect(plugins).toHaveLength(1); + }); + + test('testing storage valid plugin loader', () => { + const _config = buildConf('verdaccio-es6-plugin'); + const plugins = loadPlugin(_config, _config.auth, {}, function (p) { + return p.getPackageStorage; + }); + + expect(plugins).toHaveLength(1); + }); + + test('testing auth plugin invalid plugin', () => { + const _config = buildConf('invalid-plugin'); + try { + loadPlugin(_config, _config.auth, {}, function (p) { + return p.authenticate || p.allow_access || p.allow_publish; + }); + } catch(e) { + expect(e.message).toEqual(`"${relativePath}/invalid-plugin" doesn\'t look like a valid plugin`); + } + }); + + test('testing auth plugin invalid plugin sanityCheck', () => { + const _config = buildConf('invalid-plugin-sanity'); + try { + loadPlugin(_config, _config.auth, {}, function (plugin) { + return plugin.authenticate || plugin.allow_access || plugin.allow_publish; + }); + } catch(err) { + expect(err.message).toEqual(`"${relativePath}/invalid-plugin-sanity" doesn\'t look like a valid plugin`); + } + }); + + test('testing auth plugin no plugins', () => { + const _config = buildConf('invalid-package'); + try { + loadPlugin(_config, _config.auth, {}, function (plugin) { + return plugin.authenticate || plugin.allow_access || plugin.allow_publish; + }); + } catch(e) { + expect(e.message).toMatch('plugin not found'); + expect(e.message).toMatch('/partials/test-plugin-storage/invalid-package'); + } + }); + + // FUTURE: the following groups should be here + // middleware plugins + // storage plugins + + }); + +}); diff --git a/test/unit/search.spec.js b/test/unit/api/search.spec.js similarity index 81% rename from test/unit/search.spec.js rename to test/unit/api/search.spec.js index 3c960f63e..34e66a199 100644 --- a/test/unit/search.spec.js +++ b/test/unit/api/search.spec.js @@ -1,12 +1,12 @@ import assert from 'assert'; -import Search from '../../src/lib/search'; -import Storage from '../../src/lib/storage'; -let config_hash = require('./partials/config'); -let Config = require('../../src/lib/config'); +import Search from '../../../src/lib/search'; +import Storage from '../../../src/lib/storage'; +let config_hash = require('../partials/config/index'); +let Config = require('../../../src/lib/config'); -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); let packages = [ { diff --git a/test/unit/st_merge.spec.js b/test/unit/api/st_merge.spec.js similarity index 89% rename from test/unit/st_merge.spec.js rename to test/unit/api/st_merge.spec.js index 086a48be7..2dbbf9bd1 100644 --- a/test/unit/st_merge.spec.js +++ b/test/unit/api/st_merge.spec.js @@ -1,8 +1,8 @@ let assert = require('assert'); -let semverSort = require('../../src/lib/utils').semverSort; -import {mergeVersions} from '../../src/lib/metadata-utils'; +let semverSort = require('../../../src/lib/utils').semverSort; +import {mergeVersions} from '../../../src/lib/metadata-utils'; -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); describe('Storage._merge_versions versions', () => { diff --git a/test/unit/storage-utils.spec.js b/test/unit/api/storage-utils.spec.js similarity index 95% rename from test/unit/storage-utils.spec.js rename to test/unit/api/storage-utils.spec.js index 61c1e182b..65bf19c69 100644 --- a/test/unit/storage-utils.spec.js +++ b/test/unit/api/storage-utils.spec.js @@ -1,8 +1,8 @@ // @flow -import {DEFAULT_REVISION, normalizePackage, mergeUplinkTimeIntoLocal} from "../../src/lib/storage-utils"; -import {DIST_TAGS} from "../../src/lib/utils"; -import {readFile} from "../functional/lib/test.utils"; +import {DEFAULT_REVISION, normalizePackage, mergeUplinkTimeIntoLocal} from "../../../src/lib/storage-utils"; +import {DIST_TAGS} from "../../../src/lib/utils"; +import {readFile} from "../../functional/lib/test.utils"; import type {Package} from '@verdaccio/types'; diff --git a/test/unit/store.spec.js b/test/unit/api/store.spec.js similarity index 88% rename from test/unit/store.spec.js rename to test/unit/api/store.spec.js index 960ae5a23..b2ff2afca 100644 --- a/test/unit/store.spec.js +++ b/test/unit/api/store.spec.js @@ -3,13 +3,13 @@ import _ from 'lodash'; import httpMocks from 'node-mocks-http'; // $FlowFixMe -import configExample from './partials/config'; -import AppConfig from '../../src/lib/config'; -import Storage from '../../src/lib/storage'; -import {setup} from '../../src/lib/logger'; +import configExample from '../partials/config/index'; +import AppConfig from '../../../src/lib/config'; +import Storage from '../../../src/lib/storage'; +import {setup} from '../../../src/lib/logger'; import type {Config} from '@verdaccio/types'; -import type {IStorageHandler} from '../../types'; +import type {IStorageHandler} from '../../../types/index'; setup(configExample.logs); diff --git a/test/unit/tag_version.spec.js b/test/unit/api/tag_version.spec.js similarity index 88% rename from test/unit/tag_version.spec.js rename to test/unit/api/tag_version.spec.js index 1d684fbc3..9a9058a29 100644 --- a/test/unit/tag_version.spec.js +++ b/test/unit/api/tag_version.spec.js @@ -1,7 +1,7 @@ let assert = require('assert'); -let tag_version = require('../../src/lib/utils').tagVersion; +let tag_version = require('../../../src/lib/utils').tagVersion; -require('../../src/lib/logger').setup([]); +require('../../../src/lib/logger').setup([]); describe('tag_version', () => { test('add new one', () => { diff --git a/test/unit/up-storage.spec.js b/test/unit/api/up-storage.spec.js similarity index 96% rename from test/unit/up-storage.spec.js rename to test/unit/api/up-storage.spec.js index 388fcf184..e8984ca0f 100644 --- a/test/unit/up-storage.spec.js +++ b/test/unit/api/up-storage.spec.js @@ -1,13 +1,13 @@ // @flow import _ from 'lodash'; -import ProxyStorage, {DEFAULT_REGISTRY} from '../../src/lib/up-storage'; -import AppConfig from '../../src/lib/config'; +import ProxyStorage, {DEFAULT_REGISTRY} from '../../../src/lib/up-storage'; +import AppConfig from '../../../src/lib/config'; // $FlowFixMe -import configExample from './partials/config'; -import {setup} from '../../src/lib/logger'; +import configExample from '../partials/config/index'; +import {setup} from '../../../src/lib/logger'; import type {Config, UpLinkConf} from '@verdaccio/types'; -import type {IProxy} from '../../types'; +import type {IProxy} from '../../../types/index'; setup([]); diff --git a/test/unit/utils.spec.js b/test/unit/api/utils.spec.js similarity index 92% rename from test/unit/utils.spec.js rename to test/unit/api/utils.spec.js index 9db5313aa..2a6fdc65e 100644 --- a/test/unit/utils.spec.js +++ b/test/unit/api/utils.spec.js @@ -1,11 +1,11 @@ // @flow import assert from 'assert'; -import {validateName as validate, convertDistRemoteToLocalTarballUrls, parseReadme} from '../../src/lib/utils'; -import {generateGravatarUrl, GRAVATAR_DEFAULT} from '../../src/utils/user'; -import {spliceURL} from '../../src/utils/string'; -import Package from '../../src/webui/src/components/Package'; -import Logger, {setup} from '../../src/lib/logger'; -import { readFile } from '../functional/lib/test.utils'; +import {generateGravatarUrl, GRAVATAR_DEFAULT} from '../../../src/utils/user'; +import {spliceURL} from '../../../src/utils/string'; +import Package from "../../../src/webui/src/components/Package/index"; +import {validateName as validate, convertDistRemoteToLocalTarballUrls, parseReadme} from '../../../src/lib/utils'; +import Logger, {setup} from '../../../src/lib/logger'; +import { readFile } from '../../functional/lib/test.utils'; const readmeFile = (fileName: string = 'markdown.md') => readFile(`../../unit/partials/readme/${fileName}`); @@ -133,7 +133,7 @@ describe('Utilities', () => { const randomText = '%%%%%**##=='; const randomTextNonAscii = 'simple text \n = ascii'; const randomTextMarkdown = 'simple text \n # markdown'; - + expect(parseReadme('testPackage', randomText)).toEqual('
%%%%%**##==
\n'); expect(parseReadme('testPackage', simpleText)).toEqual('simple text
\n'); expect(parseReadme('testPackage', randomTextNonAscii)) diff --git a/test/unit/validate_all.spec.js b/test/unit/api/validate_all.spec.js similarity index 65% rename from test/unit/validate_all.spec.js rename to test/unit/api/validate_all.spec.js index b49b35a8f..6d012e428 100644 --- a/test/unit/validate_all.spec.js +++ b/test/unit/api/validate_all.spec.js @@ -1,5 +1,4 @@ // ensure that all arguments are validated -const assert = require('assert'); const path = require('path'); /** @@ -16,12 +15,11 @@ describe('api endpoint app.param()', runTest('../endpoint/index.js')); function runTest(file) { return function() { - let requirePath = path.normalize(path.join(__dirname + '/../../src/api/web/', file)); - let source = require('fs').readFileSync(requirePath, 'utf8'); - - let very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g; let m; - let appParams = {}; + const requirePath = path.normalize(path.join(__dirname + '/../../../src/api/web/', file)); + const source = require('fs').readFileSync(requirePath, 'utf8'); + const very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g; + const appParams = {}; // look up for matches in the source code while ((m = very_scary_regexp.exec(source)) != null) { @@ -40,12 +38,11 @@ function runTest(file) { }); } - - Object.keys(appParams).forEach(function(param) { - test('should validate ":'+param+'"', () => { - assert.equal(appParams[param], 'ok'); - }); - }); + Object.keys(appParams).forEach(function(param) { + test('should validate ":'+param+'"', () => { + expect(appParams[param]).toEqual('ok'); + }); + }); }; } diff --git a/test/unit/functionalLibs/request.spec.js b/test/unit/functionalLibs/request.spec.js index 587b2874a..13cb2d84b 100644 --- a/test/unit/functionalLibs/request.spec.js +++ b/test/unit/functionalLibs/request.spec.js @@ -1,8 +1,8 @@ // @flow import _ from 'lodash'; -import smartRequest, {PromiseAssert} from '../../src/request'; -import type {IRequestPromise} from '../../flow/types'; +import smartRequest, {PromiseAssert} from '../../lib/request'; +import type {IRequestPromise} from '../../types'; describe('Request Functional', () => { diff --git a/test/unit/plugin_loader.spec.js b/test/unit/plugin_loader.spec.js deleted file mode 100644 index 220213eae..000000000 --- a/test/unit/plugin_loader.spec.js +++ /dev/null @@ -1,86 +0,0 @@ - -import {loadPlugin} from '../../src/lib/plugin-loader'; -import assert from 'assert'; -import path from 'path'; - -require('../../src/lib/logger').setup([]); - -describe('plugin loader', () => { - - test('testing auth valid plugin loader', () => { - let _config = { - self_path: path.join(__dirname, './'), - max_users: 0, - auth: { - './unit/partials/test-plugin-storage/verdaccio-plugin': {} - } - } - let plugins = loadPlugin(_config, _config.auth, {}, function (p) { - return p.authenticate || p.allow_access || p.allow_publish; - }); - assert(plugins.length === 1); - }); - - test('testing storage valid plugin loader', () => { - let _config = { - self_path: path.join(__dirname, './'), - max_users: 0, - auth: { - './unit/partials/test-plugin-storage/verdaccio-es6-plugin': {} - } - } - let plugins = loadPlugin(_config, _config.auth, {}, function (p) { - return p.getPackageStorage; - }); - assert(plugins.length === 1); - }); - - test('testing auth plugin invalid plugin', () => { - let _config = { - self_path: path.join(__dirname, './'), - auth: { - './unit/partials/test-plugin-storage/invalid-plugin': {} - } - } - try { - loadPlugin(_config, _config.auth, {}, function (p) { - return p.authenticate || p.allow_access || p.allow_publish; - }); - } catch(e) { - assert(e.message === '"./unit/partials/test-plugin-storage/invalid-plugin" doesn\'t look like a valid plugin'); - } - }); - - test('testing auth plugin invalid plugin sanityCheck', () => { - let _config = { - self_path: path.join(__dirname, './'), - auth: { - './unit/partials/test-plugin-storage/invalid-plugin-sanity': {} - } - } - try { - loadPlugin(_config, _config.auth, {}, function (plugin) { - return plugin.authenticate || plugin.allow_access || plugin.allow_publish; - }); - } catch(err) { - assert(err.message === '"./unit/partials/test-plugin-storage/invalid-plugin-sanity" doesn\'t look like a valid plugin'); - } - }); - - test('testing auth plugin no plugins', () => { - let _config = { - self_path: path.join(__dirname, './'), - auth: { - './unit/partials/test-plugin-storage/invalid-package': {} - } - } - try { - loadPlugin(_config, _config.auth, {}, function (plugin) { - return plugin.authenticate || plugin.allow_access || plugin.allow_publish; - }); - } catch(e) { - assert(e.message === `"./unit/partials/test-plugin-storage/invalid-package" plugin not found\ntry "npm install verdaccio-./unit/partials/test-plugin-storage/invalid-package"`); - } - }); - -}); diff --git a/test/webui/global.js b/test/unit/setup-webui.js similarity index 100% rename from test/webui/global.js rename to test/unit/setup-webui.js diff --git a/test/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap diff --git a/test/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap similarity index 100% rename from test/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap rename to test/unit/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap diff --git a/test/webui/components/PackageSidebar/dependencies.spec.js b/test/unit/webui/components/PackageSidebar/dependencies.spec.js similarity index 93% rename from test/webui/components/PackageSidebar/dependencies.spec.js rename to test/unit/webui/components/PackageSidebar/dependencies.spec.js index 805203d1a..7405ef4d6 100644 --- a/test/webui/components/PackageSidebar/dependencies.spec.js +++ b/test/unit/webui/components/PackageSidebar/dependencies.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; -import Dependencies from '../../../../src/webui/src/components/PackageSidebar/modules/Dependencies/'; +import Dependencies from '../../../../../src/webui/src/components/PackageSidebar/modules/Dependencies/index'; import { packageMeta } from '../store/packageMeta'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/infos.spec.js b/test/unit/webui/components/PackageSidebar/infos.spec.js similarity index 89% rename from test/webui/components/PackageSidebar/infos.spec.js rename to test/unit/webui/components/PackageSidebar/infos.spec.js index 13778f556..c1efb528d 100644 --- a/test/webui/components/PackageSidebar/infos.spec.js +++ b/test/unit/webui/components/PackageSidebar/infos.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; -import Infos from '../../../../src/webui/src/components/PackageSidebar/modules/Infos'; +import Infos from '../../../../../src/webui/src/components/PackageSidebar/modules/Infos/index'; import { packageMeta } from '../store/packageMeta'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/lastsync.spec.js b/test/unit/webui/components/PackageSidebar/lastsync.spec.js similarity index 90% rename from test/webui/components/PackageSidebar/lastsync.spec.js rename to test/unit/webui/components/PackageSidebar/lastsync.spec.js index 98160c536..a51230b6a 100644 --- a/test/webui/components/PackageSidebar/lastsync.spec.js +++ b/test/unit/webui/components/PackageSidebar/lastsync.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; -import LastSync from '../../../../src/webui/src/components/PackageSidebar/modules/LastSync'; +import LastSync from '../../../../../src/webui/src/components/PackageSidebar/modules/LastSync/index'; import { packageMeta } from '../store/packageMeta'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/maintainerInfo.spec.js b/test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js similarity index 86% rename from test/webui/components/PackageSidebar/maintainerInfo.spec.js rename to test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js index 7a2ac7bfb..56658eea3 100644 --- a/test/webui/components/PackageSidebar/maintainerInfo.spec.js +++ b/test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -import MaintainerInfo from '../../../../src/webui/src/components/PackageSidebar/modules/Maintainers/MaintainerInfo'; +import MaintainerInfo from '../../../../../src/webui/src/components/PackageSidebar/modules/Maintainers/MaintainerInfo/index'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/maintainers.spec.js b/test/unit/webui/components/PackageSidebar/maintainers.spec.js similarity index 95% rename from test/webui/components/PackageSidebar/maintainers.spec.js rename to test/unit/webui/components/PackageSidebar/maintainers.spec.js index 138143dee..ec64b1b52 100644 --- a/test/webui/components/PackageSidebar/maintainers.spec.js +++ b/test/unit/webui/components/PackageSidebar/maintainers.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import Maintainers from '../../../../src/webui/src/components/PackageSidebar/modules/Maintainers'; +import Maintainers from '../../../../../src/webui/src/components/PackageSidebar/modules/Maintainers/index'; import { packageMeta } from '../store/packageMeta'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/module.spec.js b/test/unit/webui/components/PackageSidebar/module.spec.js similarity index 87% rename from test/webui/components/PackageSidebar/module.spec.js rename to test/unit/webui/components/PackageSidebar/module.spec.js index d82fdd85c..251ffa11b 100644 --- a/test/webui/components/PackageSidebar/module.spec.js +++ b/test/unit/webui/components/PackageSidebar/module.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -import Module from '../../../../src/webui/src/components/PackageSidebar/Module'; +import Module from '../../../../../src/webui/src/components/PackageSidebar/Module/index'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js b/test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js similarity index 81% rename from test/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js rename to test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js index d7c5a2913..d3839bedb 100644 --- a/test/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js +++ b/test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -import ModuleContentPlaceholder from '../../../../src/webui/src/components/PackageSidebar/ModuleContentPlaceholder'; +import ModuleContentPlaceholder from '../../../../../src/webui/src/components/PackageSidebar/ModuleContentPlaceholder/index'; console.error = jest.fn(); diff --git a/test/webui/components/PackageSidebar/packageSidebar.spec.js b/test/unit/webui/components/PackageSidebar/packageSidebar.spec.js similarity index 86% rename from test/webui/components/PackageSidebar/packageSidebar.spec.js rename to test/unit/webui/components/PackageSidebar/packageSidebar.spec.js index e64059511..6831fbcd6 100644 --- a/test/webui/components/PackageSidebar/packageSidebar.spec.js +++ b/test/unit/webui/components/PackageSidebar/packageSidebar.spec.js @@ -4,10 +4,10 @@ import React from 'react'; import { mount } from 'enzyme'; -import PackageSidebar from '../../../../src/webui/src/components/PackageSidebar'; +import PackageSidebar from '../../../../../src/webui/src/components/PackageSidebar/index'; import { packageMeta } from '../store/packageMeta'; -jest.mock('../../../../src/webui/utils/api', () => ({ +jest.mock('../../../../../src/webui/utils/api', () => ({ request: require('../__mocks__/api').default.request, })); diff --git a/test/webui/components/__mocks__/api.js b/test/unit/webui/components/__mocks__/api.js similarity index 100% rename from test/webui/components/__mocks__/api.js rename to test/unit/webui/components/__mocks__/api.js diff --git a/test/webui/components/__snapshots__/header.spec.js.snap b/test/unit/webui/components/__snapshots__/header.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/header.spec.js.snap rename to test/unit/webui/components/__snapshots__/header.spec.js.snap diff --git a/test/webui/components/__snapshots__/help.spec.js.snap b/test/unit/webui/components/__snapshots__/help.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/help.spec.js.snap rename to test/unit/webui/components/__snapshots__/help.spec.js.snap diff --git a/test/webui/components/__snapshots__/noitems.spec.js.snap b/test/unit/webui/components/__snapshots__/noitems.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/noitems.spec.js.snap rename to test/unit/webui/components/__snapshots__/noitems.spec.js.snap diff --git a/test/webui/components/__snapshots__/notfound.spec.js.snap b/test/unit/webui/components/__snapshots__/notfound.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/notfound.spec.js.snap rename to test/unit/webui/components/__snapshots__/notfound.spec.js.snap diff --git a/test/webui/components/__snapshots__/package.spec.js.snap b/test/unit/webui/components/__snapshots__/package.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/package.spec.js.snap rename to test/unit/webui/components/__snapshots__/package.spec.js.snap diff --git a/test/webui/components/__snapshots__/packagedetail.spec.js.snap b/test/unit/webui/components/__snapshots__/packagedetail.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/packagedetail.spec.js.snap rename to test/unit/webui/components/__snapshots__/packagedetail.spec.js.snap diff --git a/test/webui/components/__snapshots__/packagelist.spec.js.snap b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/packagelist.spec.js.snap rename to test/unit/webui/components/__snapshots__/packagelist.spec.js.snap diff --git a/test/webui/components/__snapshots__/readme.spec.js.snap b/test/unit/webui/components/__snapshots__/readme.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/readme.spec.js.snap rename to test/unit/webui/components/__snapshots__/readme.spec.js.snap diff --git a/test/webui/components/__snapshots__/search.spec.js.snap b/test/unit/webui/components/__snapshots__/search.spec.js.snap similarity index 100% rename from test/webui/components/__snapshots__/search.spec.js.snap rename to test/unit/webui/components/__snapshots__/search.spec.js.snap diff --git a/test/webui/components/header.spec.js b/test/unit/webui/components/header.spec.js similarity index 95% rename from test/webui/components/header.spec.js rename to test/unit/webui/components/header.spec.js index ee0f64ff5..2bb42f3ae 100644 --- a/test/webui/components/header.spec.js +++ b/test/unit/webui/components/header.spec.js @@ -3,11 +3,11 @@ */ import React from 'react'; import { shallow, mount } from 'enzyme'; -import Header from '../../../src/webui/src/components/Header'; +import Header from '../../../../src/webui/src/components/Header'; import { BrowserRouter } from 'react-router-dom'; -import storage from '../../../src/webui/utils/storage'; +import storage from '../../../../src/webui/utils/storage'; -jest.mock('../../../src/webui/utils/api', () => ({ +jest.mock('../../../../src/webui/utils/api', () => ({ request: require('./__mocks__/api').default.request, })); diff --git a/test/webui/components/help.spec.js b/test/unit/webui/components/help.spec.js similarity index 93% rename from test/webui/components/help.spec.js rename to test/unit/webui/components/help.spec.js index 704c61132..344d43568 100644 --- a/test/webui/components/help.spec.js +++ b/test/unit/webui/components/help.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import SyntaxHighlighter from 'react-syntax-highlighter/dist/light'; -import Help from '../../../src/webui/src/components/Help'; +import Help from '../../../../src/webui/src/components/Help/index'; describe('