mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
refactor: replace flow comments by ts-ignore
ts-ignore is not harmfull in specs files, since we try to force to test with values are not allowed by the types
This commit is contained in:
parent
8b03637b63
commit
7fa23577ae
19 changed files with 75 additions and 47 deletions
|
@ -25,7 +25,7 @@ export const resolveConfigPath = function(storageLocation: string, file: string)
|
|||
- localhost:5557
|
||||
@return {Array}
|
||||
*/
|
||||
export function getListListenAddresses(argListen: string, configListen: any) {
|
||||
export function getListListenAddresses(argListen: string, configListen: any): any {
|
||||
// command line || config file || default
|
||||
let addresses;
|
||||
if (argListen) {
|
||||
|
@ -38,7 +38,7 @@ export function getListListenAddresses(argListen: string, configListen: any) {
|
|||
addresses = [DEFAULT_PORT];
|
||||
}
|
||||
addresses = addresses
|
||||
.map(function(addr) {
|
||||
.map(function(addr): string {
|
||||
const parsedAddr = parseAddress(addr);
|
||||
|
||||
if (!parsedAddr) {
|
||||
|
|
|
@ -28,8 +28,8 @@ class FunctionalEnvironment extends NodeEnvironment {
|
|||
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
|
||||
// @ts-ignore
|
||||
const DEBUG_INJECT: boolean = process.env.VERDACCIO_DEBUG_INJECT ? process.env.VERDACCIO_DEBUG_INJECT : false;
|
||||
const forkList = [];
|
||||
const serverList = [];
|
||||
const forkList: any[] = [];
|
||||
const serverList: IServerBridge[] = [];
|
||||
const pathStore = path.join(__dirname, '../store');
|
||||
const listServers = [
|
||||
{
|
||||
|
@ -51,6 +51,7 @@ class FunctionalEnvironment extends NodeEnvironment {
|
|||
console.log(green('Setup Verdaccio Servers'));
|
||||
|
||||
const app = await this.startWeb();
|
||||
// @ts-ignore
|
||||
this.global.__WEB_SERVER__ = app;
|
||||
|
||||
for (let config of listServers) {
|
||||
|
@ -68,26 +69,33 @@ class FunctionalEnvironment extends NodeEnvironment {
|
|||
forkList.push(fork);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
this.global.__SERVERS_PROCESS__ = forkList;
|
||||
// @ts-ignore
|
||||
this.global.__SERVERS__ = serverList;
|
||||
}
|
||||
|
||||
public async teardown() {
|
||||
await super.teardown();
|
||||
console.log(yellow('Teardown Test Environment.'));
|
||||
// @ts-ignore
|
||||
if (!this.global.__SERVERS_PROCESS__) {
|
||||
throw new Error("There are no servers to stop");
|
||||
}
|
||||
|
||||
// shutdown verdaccio
|
||||
// @ts-ignore
|
||||
for (let server of this.global.__SERVERS_PROCESS__) {
|
||||
server[0].stop();
|
||||
}
|
||||
// close web server
|
||||
// @ts-ignore
|
||||
this.global.__WEB_SERVER__.server.close();
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
public runScript(script: string) {
|
||||
// @ts-ignore
|
||||
return super.runScript(script);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ export default function(express) {
|
|||
name: "pkg-test"
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
notify(metadata, config, publisherInfo, 'foo').then(function (body) {
|
||||
const jsonBody = parseBody(body);
|
||||
expect(
|
||||
|
@ -64,9 +65,11 @@ export default function(express) {
|
|||
|
||||
const configMultipleHeader = _.cloneDeep(config);
|
||||
configMultipleHeader.notify.headers = {
|
||||
// @ts-ignore
|
||||
'Content-Type': HEADERS.JSON
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
notify(metadata, configMultipleHeader, publisherInfo).then(function (body) {
|
||||
const jsonBody = parseBody(body);
|
||||
expect(`New package published: * ${metadata.name}*. Publisher name: * ${publisherInfo.name} *.`).toBe(jsonBody.message);
|
||||
|
@ -90,11 +93,14 @@ export default function(express) {
|
|||
for (let i = 0; i < 10; i++) {
|
||||
const notificationSettings = _.cloneDeep(config.notify);
|
||||
// basically we allow al notifications
|
||||
// @ts-ignore
|
||||
notificationSettings.packagePattern = /^pkg-test$/;
|
||||
// notificationSettings.packagePatternFlags = 'i';
|
||||
// @ts-ignore
|
||||
multipleNotificationsEndpoint.notify.push(notificationSettings);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
notify(metadata, multipleNotificationsEndpoint, publisherInfo).then(function (body) {
|
||||
console.log("--->body", body);
|
||||
body.forEach(function(notification) {
|
||||
|
@ -115,6 +121,7 @@ export default function(express) {
|
|||
const configFail = _.cloneDeep(config);
|
||||
configFail.notify.endpoint = `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/api/notify/bad`;
|
||||
|
||||
// @ts-ignore
|
||||
notify(metadata, configFail, publisherInfo).then(function () {
|
||||
expect(false).toBe('This service should fails with status code 400');
|
||||
done();
|
||||
|
@ -132,6 +139,7 @@ export default function(express) {
|
|||
}
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
notify(metadata, config, publisherInfo).then(
|
||||
function(body) {
|
||||
const jsonBody = parseBody(body);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// @flow
|
||||
|
||||
import { Version } from "@verdaccio/types";
|
||||
|
||||
export function generateNewVersion(
|
||||
|
@ -20,9 +18,8 @@ export function generateNewVersion(
|
|||
"readme": "ERROR: No README data found!",
|
||||
"_id": `${pkgName}@${version}`,
|
||||
"_npmVersion": "5.5.1",
|
||||
"_nodeVersion": "9.3.0",
|
||||
"_npmUser": {
|
||||
|
||||
"name": "Foo"
|
||||
},
|
||||
"dist": {
|
||||
"integrity": "sha512-zVEqt1JUCOPsash9q4wMkJEDPD+QCx95TRhQII+JnoS31uBUKoZxhzvvUJCcLVy2CQG4QdwXARU7dYWPnrwhGg==",
|
||||
|
|
|
@ -25,7 +25,7 @@ export interface IServerProcess {
|
|||
}
|
||||
|
||||
declare class PromiseAssert<IRequestPromise> extends Promise<any> {
|
||||
constructor(options: any): IRequestPromise;
|
||||
public constructor(options: any);
|
||||
}
|
||||
|
||||
export interface IServerBridge {
|
||||
|
|
|
@ -3,6 +3,7 @@ import smartRequest, {PromiseAssert} from '../../lib/request';
|
|||
import {mockServer} from '../__helper/mock';
|
||||
import {HTTP_STATUS} from '../../../src/lib/constants';
|
||||
import { IRequestPromise } from '../../types';
|
||||
import { VerdaccioError } from '@verdaccio/commons-api';
|
||||
|
||||
describe('Request Functional', () => {
|
||||
const mockServerPort = 55547;
|
||||
|
@ -15,10 +16,10 @@ describe('Request Functional', () => {
|
|||
});
|
||||
|
||||
test('basic resolve', (done) => {
|
||||
const requestPromise: IRequestPromise = new PromiseAssert((resolve, reject) => {
|
||||
const requestPromise: IRequestPromise = new PromiseAssert(resolve => {
|
||||
resolve(1);
|
||||
});
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
requestPromise.then((result) => {
|
||||
expect(result).toBe(1);
|
||||
done();
|
||||
|
@ -55,7 +56,7 @@ describe('Request Functional', () => {
|
|||
url: restTest,
|
||||
method: 'GET'
|
||||
};
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
smartRequest(options).status(HTTP_STATUS.OK).then((result)=> {
|
||||
expect(JSON.parse(result).name).toBe('jquery');
|
||||
done();
|
||||
|
@ -67,10 +68,10 @@ describe('Request Functional', () => {
|
|||
url: 'http://www.google.fake',
|
||||
method: 'GET'
|
||||
};
|
||||
// $FlowFixMe
|
||||
smartRequest(options).status(HTTP_STATUS.NOT_FOUND).then((result)=> {
|
||||
// this never is resolved
|
||||
}, function(error) {
|
||||
// @ts-ignore
|
||||
smartRequest(options).status(HTTP_STATUS.NOT_FOUND).then(() => {
|
||||
// we do not intent to resolve this
|
||||
}, (error: VerdaccioError) => {
|
||||
expect(error.code).toBe('ENOTFOUND');
|
||||
done();
|
||||
})
|
||||
|
|
|
@ -171,6 +171,7 @@ describe('startServer via API', () => {
|
|||
});
|
||||
|
||||
test('should return a list of 1 address provided', () => {
|
||||
// @ts-ignore
|
||||
const addrs = getListListenAddresses(null, '1000');
|
||||
|
||||
expect(_.isArray(addrs)).toBeTruthy();
|
||||
|
@ -178,6 +179,7 @@ describe('startServer via API', () => {
|
|||
});
|
||||
|
||||
test('should return a list of 2 address provided', () => {
|
||||
// @ts-ignore
|
||||
const addrs = getListListenAddresses(null, ['1000', '2000']);
|
||||
|
||||
expect(_.isArray(addrs)).toBeTruthy();
|
||||
|
@ -188,17 +190,24 @@ describe('startServer via API', () => {
|
|||
// @ts-ignore
|
||||
const [addrs] = getListListenAddresses();
|
||||
|
||||
// @ts-ignore
|
||||
expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
|
||||
// @ts-ignore
|
||||
expect(addrs.host).toBe(DEFAULT_DOMAIN);
|
||||
// @ts-ignore
|
||||
expect(addrs.port).toBe(DEFAULT_PORT);
|
||||
});
|
||||
|
||||
test('should return default proto, host and custom port', () => {
|
||||
const initPort = '1000';
|
||||
// @ts-ignore
|
||||
const [addrs] = getListListenAddresses(null, initPort);
|
||||
|
||||
// @ts-ignore
|
||||
expect(addrs.proto).toEqual(DEFAULT_PROTOCOL);
|
||||
// @ts-ignore
|
||||
expect(addrs.host).toEqual(DEFAULT_DOMAIN);
|
||||
// @ts-ignore
|
||||
expect(addrs.port).toEqual(initPort);
|
||||
});
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ import {parseAddress as parse} from '../../../../src/lib/utils';
|
|||
import {DEFAULT_DOMAIN, DEFAULT_PORT} from '../../../../src/lib/constants';
|
||||
|
||||
describe('Parse listen address', () => {
|
||||
const useCases = [];
|
||||
const useCases: any[] = [];
|
||||
|
||||
function addTest(uri, proto, host?, port?) {
|
||||
function addTest(uri: string, proto: string | null, host?: string, port?: string) {
|
||||
useCases.push([uri, proto, host, port]);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ const checkDefaultConfPackages = (config) => {
|
|||
|
||||
describe('Config file', () => {
|
||||
beforeAll(function() {
|
||||
|
||||
// @ts-ignore
|
||||
this.config = new Config(parseConfigFile(resolveConf('default')));
|
||||
});
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ describe('Notifications:: Notify', () => {
|
|||
describe('packagePatternFlags', () => {
|
||||
test("should send single notification with packagePatternFlags", async () => {
|
||||
const name = 'package';
|
||||
// @ts-ignore
|
||||
await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar');
|
||||
|
||||
|
||||
|
@ -75,6 +76,7 @@ describe('Notifications:: Notify', () => {
|
|||
|
||||
test("should not match on send single notification with packagePatternFlags", async () => {
|
||||
const name = 'no-mach-name';
|
||||
// @ts-ignore
|
||||
await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar');
|
||||
|
||||
expect(notifyRequest).toHaveBeenCalledTimes(0);
|
||||
|
|
|
@ -19,6 +19,7 @@ describe('plugin loader', () => {
|
|||
describe('auth plugins', () => {
|
||||
test('testing auth valid plugin loader', () => {
|
||||
const _config = buildConf('verdaccio-plugin');
|
||||
// @ts-ignore
|
||||
const plugins = loadPlugin(_config, _config.auth, {}, function (plugin) {
|
||||
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
||||
});
|
||||
|
@ -28,6 +29,7 @@ describe('plugin loader', () => {
|
|||
|
||||
test('testing storage valid plugin loader', () => {
|
||||
const _config = buildConf('verdaccio-es6-plugin');
|
||||
// @ts-ignore
|
||||
const plugins = loadPlugin(_config, _config.auth, {}, function (p) {
|
||||
return p.getPackageStorage;
|
||||
});
|
||||
|
|
|
@ -33,9 +33,9 @@ let packages = [
|
|||
describe('search', () => {
|
||||
beforeAll(async function() {
|
||||
let config = new Config(buildConfig());
|
||||
this.storage = new Storage(config);
|
||||
await this.storage.init(config);
|
||||
Search.configureStorage(this.storage);
|
||||
const storage = new Storage(config);
|
||||
await storage.init(config);
|
||||
Search.configureStorage(storage);
|
||||
packages.map(function(item) {
|
||||
// @ts-ignore
|
||||
Search.add(item);
|
||||
|
|
|
@ -12,7 +12,7 @@ import {generateNewVersion} from '../../../lib/utils-test';
|
|||
|
||||
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`).toString();
|
||||
|
||||
import {Config, MergeTags} from '@verdaccio/types';
|
||||
import {Config, MergeTags, Package} from '@verdaccio/types';
|
||||
import {IStorage} from '../../../../types';
|
||||
import { API_ERROR, HTTP_STATUS, DIST_TAGS} from '../../../../src/lib/constants';
|
||||
import { VerdaccioError } from '@verdaccio/commons-api';
|
||||
|
@ -34,7 +34,7 @@ describe('LocalStorage', () => {
|
|||
return new LocalStorageClass(config, logger);
|
||||
}
|
||||
|
||||
const getPackageMetadataFromStore = (pkgName: string) => {
|
||||
const getPackageMetadataFromStore = (pkgName: string): Promise<Package> => {
|
||||
return new Promise((resolve) => {
|
||||
storage.getPackageMetadata(pkgName, (err, data ) => {
|
||||
resolve(data);
|
||||
|
@ -150,7 +150,7 @@ describe('LocalStorage', () => {
|
|||
storage.mergeTags(pkgName, tags, async (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
const metadata = await getPackageMetadataFromStore(pkgName);
|
||||
const metadata: Package = await getPackageMetadataFromStore(pkgName);
|
||||
expect(metadata[DIST_TAGS]).toBeDefined();
|
||||
expect(metadata[DIST_TAGS]['beta']).toBeDefined();
|
||||
expect(metadata[DIST_TAGS]['beta']).toBe('3.0.0');
|
||||
|
@ -170,7 +170,7 @@ describe('LocalStorage', () => {
|
|||
beta: '9999.0.0'
|
||||
};
|
||||
|
||||
storage.mergeTags(pkgName, tags, async (err, data) => {
|
||||
storage.mergeTags(pkgName, tags, async (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND);
|
||||
expect(err.message).toMatch(API_ERROR.VERSION_NOT_EXIST);
|
||||
|
|
|
@ -59,7 +59,7 @@ describe('StorageTest', () => {
|
|||
test('should fetch from uplink jquery metadata from registry', async (done) => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('jquery', null, {}, (err, metadata, errors) => {
|
||||
expect(err).toBeNull();
|
||||
expect(metadata).toBeDefined();
|
||||
|
@ -71,7 +71,7 @@ describe('StorageTest', () => {
|
|||
test('should fails on fetch from uplink non existing from registry', async (done) => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
|
@ -84,7 +84,7 @@ describe('StorageTest', () => {
|
|||
test('should fails on fetch from uplink corrupted pkg from registry', async (done) => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('corrupted-package', null, {}, (err, metadata, errors) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
|
@ -95,18 +95,19 @@ describe('StorageTest', () => {
|
|||
});
|
||||
|
||||
test('should not touch if the package exists and has no uplinks', async (done) => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
const storage: IStorageHandler = await generateStorage() as IStorageHandler;
|
||||
const metadataSource = path.join(__dirname, '../../partials/metadata');
|
||||
const metadataPath = path.join(storagePath, 'npm_test/package.json');
|
||||
|
||||
fs.mkdirSync(path.join(storagePath, 'npm_test'));
|
||||
fs.writeFileSync(metadataPath, fs.readFileSync(metadataSource));
|
||||
const metadata = JSON.parse(fs.readFileSync(metadataPath).toString());
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
storage.localStorage.updateVersions = jest.fn(storage.localStorage.updateVersions);
|
||||
expect(metadata).toBeDefined();
|
||||
storage._syncUplinksMetadata('npm_test', metadata, {}, (err) => {
|
||||
expect(err).toBeNull();
|
||||
// @ts-ignore
|
||||
expect(storage.localStorage.updateVersions).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -10,12 +10,11 @@ function createUplink(config) {
|
|||
url: DEFAULT_REGISTRY
|
||||
};
|
||||
let mergeConfig = Object.assign({}, defaultConfig, config);
|
||||
// @ts-ignore
|
||||
return new ProxyStorage(mergeConfig, {});
|
||||
}
|
||||
|
||||
function setHeaders(config, headers) {
|
||||
config = config || {};
|
||||
headers = headers || {};
|
||||
function setHeaders(config: unknown = {}, headers: unknown = {}) {
|
||||
const uplink = createUplink(config);
|
||||
return uplink._setHeaders({
|
||||
headers
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// @flow
|
||||
import _ from 'lodash';
|
||||
import ProxyStorage from '../../../../src/lib/up-storage';
|
||||
import AppConfig from '../../../../src/lib/config';
|
||||
// $FlowFixMe
|
||||
import configExample from '../../partials/config';
|
||||
import {setup} from '../../../../src/lib/logger';
|
||||
|
||||
|
@ -11,6 +9,7 @@ import {IProxy} from '../../../../types';
|
|||
import {API_ERROR, HTTP_STATUS} from "../../../../src/lib/constants";
|
||||
import {mockServer} from '../../__helper/mock';
|
||||
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
|
||||
import { VerdaccioError } from '@verdaccio/commons-api';
|
||||
|
||||
setup([]);
|
||||
|
||||
|
@ -100,7 +99,7 @@ describe('UpStorge', () => {
|
|||
const tarball = `http://${DOMAIN_SERVERS}:${mockServerPort}/jquery/-/no-exist-1.5.1.tgz`;
|
||||
const stream = proxy.fetchTarball(tarball);
|
||||
|
||||
stream.on('error', function(err) {
|
||||
stream.on('error', function(err: VerdaccioError) {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toBe(HTTP_STATUS.NOT_FOUND);
|
||||
expect(err.message).toMatch(API_ERROR.NOT_FILE_UPLINK);
|
||||
|
@ -139,7 +138,7 @@ describe('UpStorge', () => {
|
|||
// expect(err.statusCode).toBe(404);
|
||||
expect(proxy.failed_requests).toBe(2);
|
||||
const streamThirdTry = proxy.fetchTarball(tarball);
|
||||
streamThirdTry.on('error', function(err) {
|
||||
streamThirdTry.on('error', function(err: VerdaccioError) {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
|
||||
expect(proxy.failed_requests).toBe(2);
|
||||
|
@ -157,7 +156,7 @@ describe('UpStorge', () => {
|
|||
describe('valid use cases', () => {
|
||||
const validateUpLink = (
|
||||
url: string,
|
||||
tarBallUrl?: string = `${url}/artifactory/api/npm/npm/pk1-juan/-/pk1-juan-1.0.7.tgz`) => {
|
||||
tarBallUrl: string = `${url}/artifactory/api/npm/npm/pk1-juan/-/pk1-juan-1.0.7.tgz`) => {
|
||||
const uplinkConf = { url };
|
||||
const proxy: IProxy = generateProxy(uplinkConf);
|
||||
|
||||
|
|
|
@ -136,13 +136,15 @@ describe('Config Utilities', () => {
|
|||
|
||||
expect(react).toBeDefined();
|
||||
expect(react.access).toBeDefined();
|
||||
// $FlowFixMe
|
||||
|
||||
// Intended checks, Typescript shoold catch this, we test the runtime part
|
||||
// @ts-ignore
|
||||
expect(react.access[0]).toBe(ROLES.$ALL);
|
||||
expect(react.publish).toBeDefined();
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
expect(react.publish[0]).toBe('admin');
|
||||
expect(react.proxy).toBeDefined();
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
expect(react.proxy[0]).toBe('uplink2');
|
||||
expect(react.storage).toBeDefined();
|
||||
|
||||
|
|
|
@ -235,10 +235,10 @@ describe('Utilities', () => {
|
|||
|
||||
describe('validateName', () => {
|
||||
test('should fails with no string', () => {
|
||||
// intended to fail with flow, do not remove
|
||||
// $FlowFixMe
|
||||
// intended to fail with Typescript, do not remove
|
||||
// @ts-ignore
|
||||
expect(validateName(null)).toBeFalsy();
|
||||
// $FlowFixMe
|
||||
// @ts-ignore
|
||||
expect(validateName(undefined)).toBeFalsy();
|
||||
});
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
],
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"test/**/.ts",
|
||||
"test/**/*.ts",
|
||||
"types/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue