0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

refactor: get rid of jest warnings

This commit is contained in:
Juan Picado @jotadeveloper 2018-06-27 08:52:52 +02:00
parent 87c16547e8
commit ccb73404a8
No known key found for this signature in database
GPG key ID: 18AC54485952D158
9 changed files with 138 additions and 47 deletions

View file

@ -4,21 +4,40 @@ module.exports = {
name: 'verdaccio-unit-jest',
verbose: true,
collectCoverage: true,
coveragePathIgnorePatterns: [
'node_modules',
'fixtures'
],
testEnvironment: 'jest-environment-jsdom-global',
testRegex: '(test/unit.*\\.spec|test/unit/webui/.*\\.spec)\\.js',
setupFiles: [
'./test/unit/setup.js'
],
// Some unit tests rely on data folders that look like packages. This confuses jest-hast-map
// when it tries to scan for package.json files.
modulePathIgnorePatterns: [
'setup.js'
'<rootDir>/test/unit/partials/mock-store/.*/package.json',
'<rootDir>/test/functional/store/.*/package.json',
'<rootDir>/test/unit/partials/store/.*/package.json',
'<rootDir>/coverage',
'<rootDir>/docs',
'<rootDir>/debug',
'<rootDir>/scripts',
'<rootDir>/.circleci',
'<rootDir>/tools',
'<rootDir>/wiki',
'<rootDir>/systemd',
'<rootDir>/flow-typed',
'<rootDir>test/unit/partials/mock-store/.*/package.json',
'<rootDir>/test/functional/store/.*/package.json',
'<rootDir>/build',
'<rootDir>/.vscode/',
],
testPathIgnorePatterns: [
'__snapshots__'
'__snapshots__',
'build'
],
coveragePathIgnorePatterns: [
'node_modules',
'fixtures'
],
// moduleFileExtensions: ["js"],
moduleNameMapper: {
'\\.(scss)$': '<rootDir>/node_modules/identity-obj-proxy',
'github-markdown-css': '<rootDir>/node_modules/identity-obj-proxy',

View file

@ -64,6 +64,7 @@ export const API_ERROR = {
MAX_USERS_REACHED: 'maximum amount of users reached',
VERSION_NOT_EXIST: 'this version doesn\'t exist',
FILE_NOT_FOUND: 'File not found',
BAD_STATUS_CODE: 'bad status code',
WEB_DISABLED: 'Web interface is disabled in the config file',
};

View file

@ -411,7 +411,7 @@ class ProxyStorage implements IProxy {
return callback( ErrorCode.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK));
}
if (!(res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)) {
const error = ErrorCode.getInternalError(`bad status code: ${res.statusCode}`);
const error = ErrorCode.getInternalError(`${API_ERROR.BAD_STATUS_CODE}: ${res.statusCode}`);
// $FlowFixMe
error.remoteStatus = res.statusCode;
return callback(error);

View file

@ -7,5 +7,23 @@ module.exports = {
globalSetup: './e2e/pre-setup.js',
globalTeardown: './e2e/teardown.js',
testEnvironment: './e2e/puppeteer_environment.js',
testRegex: '(/e2e.*\\.spec)\\.js'
testRegex: '(/e2e.*\\.spec)\\.js',
modulePathIgnorePatterns: [
'<rootDir>/unit/partials/mock-store/.*/package.json',
'<rootDir>/functional/store/.*/package.json',
'<rootDir>/unit/partials/store/.*/package.json',
'<rootDir>/../coverage',
'<rootDir>/../docs',
'<rootDir>/../debug',
'<rootDir>/../scripts',
'<rootDir>/../.circleci',
'<rootDir>/../tools',
'<rootDir>/../wiki',
'<rootDir>/../systemd',
'<rootDir>/../flow-typed',
'<rootDir>unit/partials/mock-store/.*/package.json',
'<rootDir>functional/store/.*/package.json',
'<rootDir>/../build',
'<rootDir>/../.vscode/',
]
};

View file

@ -6,5 +6,25 @@ module.exports = {
globalSetup: './functional/pre-setup.js',
globalTeardown: './functional/teardown.js',
testEnvironment: './functional/test-environment.js',
// Some unit tests rely on data folders that look like packages. This confuses jest-hast-map
// when it tries to scan for package.json files.
modulePathIgnorePatterns: [
'<rootDir>/unit/partials/mock-store/.*/package.json',
'<rootDir>/functional/store/.*/package.json',
'<rootDir>/unit/partials/store/.*/package.json',
'<rootDir>/../coverage',
'<rootDir>/../docs',
'<rootDir>/../debug',
'<rootDir>/../scripts',
'<rootDir>/../.circleci',
'<rootDir>/../tools',
'<rootDir>/../wiki',
'<rootDir>/../systemd',
'<rootDir>/../flow-typed',
'<rootDir>unit/partials/mock-store/.*/package.json',
'<rootDir>functional/store/.*/package.json',
'<rootDir>/../build',
'<rootDir>/../.vscode/',
],
collectCoverage: false
};

View file

@ -9,15 +9,15 @@ import {setup} from '../../../src/lib/logger';
import type {Config} from '@verdaccio/types';
import type {IStorageHandler} from '../../../types/index';
import {API_ERROR} from '../../../src/lib/constants';
import {API_ERROR, HTTP_STATUS} from '../../../src/lib/constants';
import {mockServer} from './mock';
import {DOMAIN_SERVERS} from '../../functional/config.functional';
setup(configExample.logs);
const mockServerPort: number = 55548;
const generateStorage = async function(port = mockServerPort) {
const storageConfig = _.clone(configExample);
const generateStorage = async function(port = mockServerPort, configDefault = configExample) {
const storageConfig = _.clone(configDefault);
const storage = `./unit/partials/store/test-storage-store.spec`;
storageConfig.self_path = __dirname;
storageConfig.storage = storage;
@ -51,7 +51,8 @@ describe('StorageTest', () => {
expect(storage).toBeDefined();
});
test('should fetch from uplink jquery metadata from nmpjs', async (done) => {
describe('test _syncUplinksMetadata', () => {
test('should fetch from uplink jquery metadata from registry', async (done) => {
const storage: IStorageHandler = await generateStorage();
// $FlowFixMe
@ -63,16 +64,31 @@ describe('StorageTest', () => {
});
});
test('should fails on fetch from uplink metadata from nmpjs', async (done) => {
test('should fails on fetch from uplink non existing from registry', async (done) => {
const storage: IStorageHandler = await generateStorage();
// $FlowFixMe
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
expect(err).not.toBeNull();
expect(errors).toBeInstanceOf(Array);
expect(errors[0][0].statusCode).toBe(404);
console.log(errors);
expect(errors[0][0].statusCode).toBe(HTTP_STATUS.NOT_FOUND);
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
done();
});
});
test('should fails on fetch from uplink corrupted pkg from registry', async (done) => {
const storage: IStorageHandler = await generateStorage();
// $FlowFixMe
storage._syncUplinksMetadata('corrupted-package', null, {}, (err, metadata, errors) => {
expect(err).not.toBeNull();
expect(errors).toBeInstanceOf(Array);
expect(errors[0][0].statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
expect(errors[0][0].message).toMatch(API_ERROR.BAD_STATUS_CODE);
done();
});
});
});
});

View file

@ -1,7 +1,7 @@
storage: ./mock-store
web:
enable: true
enable: false
title: verdaccio-server-unit-test
auth:
@ -18,7 +18,6 @@ packages:
'@*/*':
access: $all
publish: none
'**':
access: $all
publish: none

View file

@ -5,48 +5,54 @@ const config = {
storage: path.join(__dirname, '../store/test-storage'),
uplinks: {
'npmjs': {
'url': 'https://registry.npmjs.org/'
'url': 'http://localhost:4873/'
}
},
packages: {
'@*/*': {
allow_access: '$all',
allow_publish: '$all',
access: '$all',
publish: '$all',
proxy: 'npmjs'
},
'forbidden-place': {
allow_access: 'nobody',
allow_publish: '$all'
access: 'nobody',
publish: '$all'
},
'react': {
allow_access: '$all',
allow_publish: '$all',
access: '$all',
publish: '$all',
proxy: 'npmjs'
},
'corrupted-package': {
access: '$all',
publish: '$all',
proxy: 'npmjs'
},
'jquery': {
allow_access: '$all',
allow_publish: '$all',
access: '$all',
publish: '$all',
proxy: 'npmjs'
},
'auth-package': {
allow_access: '$authenticated',
allow_publish: '$authenticated'
access: '$authenticated',
publish: '$authenticated'
},
'vue': {
allow_access: '$authenticated',
allow_publish: '$authenticated',
access: '$authenticated',
publish: '$authenticated',
proxy: 'npmjs'
},
'*': {
allow_access: '$all',
allow_publish: '$all'
access: '$all',
publish: '$all'
},
},
logs: [
{type: 'stdout', format: 'pretty', level: 'fatal'},
{type: 'stdout', format: 'pretty', level: 'info'},
],
};

View file

@ -0,0 +1,12 @@
{
"name": "corrupted-package"
"version": {},
"dist-tags": {},
"_distfiles": {},
"_attachments": {},
"_uplinks": {},
"time": {},
"_rev": "0-0000000000000000",
"readme": "",
"versions": {}
}