0
Fork 0
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:
Juan Picado @jotadeveloper 2019-08-16 21:20:18 +02:00
parent 8b03637b63
commit 7fa23577ae
No known key found for this signature in database
GPG key ID: 15AA875EF3768142
19 changed files with 75 additions and 47 deletions

View file

@ -25,7 +25,7 @@ export const resolveConfigPath = function(storageLocation: string, file: string)
- localhost:5557 - localhost:5557
@return {Array} @return {Array}
*/ */
export function getListListenAddresses(argListen: string, configListen: any) { export function getListListenAddresses(argListen: string, configListen: any): any {
// command line || config file || default // command line || config file || default
let addresses; let addresses;
if (argListen) { if (argListen) {
@ -38,7 +38,7 @@ export function getListListenAddresses(argListen: string, configListen: any) {
addresses = [DEFAULT_PORT]; addresses = [DEFAULT_PORT];
} }
addresses = addresses addresses = addresses
.map(function(addr) { .map(function(addr): string {
const parsedAddr = parseAddress(addr); const parsedAddr = parseAddress(addr);
if (!parsedAddr) { if (!parsedAddr) {

View file

@ -28,8 +28,8 @@ class FunctionalEnvironment extends NodeEnvironment {
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG; const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
// @ts-ignore // @ts-ignore
const DEBUG_INJECT: boolean = process.env.VERDACCIO_DEBUG_INJECT ? process.env.VERDACCIO_DEBUG_INJECT : false; const DEBUG_INJECT: boolean = process.env.VERDACCIO_DEBUG_INJECT ? process.env.VERDACCIO_DEBUG_INJECT : false;
const forkList = []; const forkList: any[] = [];
const serverList = []; const serverList: IServerBridge[] = [];
const pathStore = path.join(__dirname, '../store'); const pathStore = path.join(__dirname, '../store');
const listServers = [ const listServers = [
{ {
@ -51,6 +51,7 @@ class FunctionalEnvironment extends NodeEnvironment {
console.log(green('Setup Verdaccio Servers')); console.log(green('Setup Verdaccio Servers'));
const app = await this.startWeb(); const app = await this.startWeb();
// @ts-ignore
this.global.__WEB_SERVER__ = app; this.global.__WEB_SERVER__ = app;
for (let config of listServers) { for (let config of listServers) {
@ -68,26 +69,33 @@ class FunctionalEnvironment extends NodeEnvironment {
forkList.push(fork); forkList.push(fork);
} }
// @ts-ignore
this.global.__SERVERS_PROCESS__ = forkList; this.global.__SERVERS_PROCESS__ = forkList;
// @ts-ignore
this.global.__SERVERS__ = serverList; this.global.__SERVERS__ = serverList;
} }
public async teardown() { public async teardown() {
await super.teardown(); await super.teardown();
console.log(yellow('Teardown Test Environment.')); console.log(yellow('Teardown Test Environment.'));
// @ts-ignore
if (!this.global.__SERVERS_PROCESS__) { if (!this.global.__SERVERS_PROCESS__) {
throw new Error("There are no servers to stop"); throw new Error("There are no servers to stop");
} }
// shutdown verdaccio // shutdown verdaccio
// @ts-ignore
for (let server of this.global.__SERVERS_PROCESS__) { for (let server of this.global.__SERVERS_PROCESS__) {
server[0].stop(); server[0].stop();
} }
// close web server // close web server
// @ts-ignore
this.global.__WEB_SERVER__.server.close(); this.global.__WEB_SERVER__.server.close();
} }
// @ts-ignore
public runScript(script: string) { public runScript(script: string) {
// @ts-ignore
return super.runScript(script); return super.runScript(script);
} }
} }

View file

@ -46,6 +46,7 @@ export default function(express) {
name: "pkg-test" name: "pkg-test"
}; };
// @ts-ignore
notify(metadata, config, publisherInfo, 'foo').then(function (body) { notify(metadata, config, publisherInfo, 'foo').then(function (body) {
const jsonBody = parseBody(body); const jsonBody = parseBody(body);
expect( expect(
@ -64,9 +65,11 @@ export default function(express) {
const configMultipleHeader = _.cloneDeep(config); const configMultipleHeader = _.cloneDeep(config);
configMultipleHeader.notify.headers = { configMultipleHeader.notify.headers = {
// @ts-ignore
'Content-Type': HEADERS.JSON 'Content-Type': HEADERS.JSON
}; };
// @ts-ignore
notify(metadata, configMultipleHeader, publisherInfo).then(function (body) { notify(metadata, configMultipleHeader, publisherInfo).then(function (body) {
const jsonBody = parseBody(body); const jsonBody = parseBody(body);
expect(`New package published: * ${metadata.name}*. Publisher name: * ${publisherInfo.name} *.`).toBe(jsonBody.message); 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++) { for (let i = 0; i < 10; i++) {
const notificationSettings = _.cloneDeep(config.notify); const notificationSettings = _.cloneDeep(config.notify);
// basically we allow al notifications // basically we allow al notifications
// @ts-ignore
notificationSettings.packagePattern = /^pkg-test$/; notificationSettings.packagePattern = /^pkg-test$/;
// notificationSettings.packagePatternFlags = 'i'; // notificationSettings.packagePatternFlags = 'i';
// @ts-ignore
multipleNotificationsEndpoint.notify.push(notificationSettings); multipleNotificationsEndpoint.notify.push(notificationSettings);
} }
// @ts-ignore
notify(metadata, multipleNotificationsEndpoint, publisherInfo).then(function (body) { notify(metadata, multipleNotificationsEndpoint, publisherInfo).then(function (body) {
console.log("--->body", body); console.log("--->body", body);
body.forEach(function(notification) { body.forEach(function(notification) {
@ -115,6 +121,7 @@ export default function(express) {
const configFail = _.cloneDeep(config); const configFail = _.cloneDeep(config);
configFail.notify.endpoint = `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/api/notify/bad`; configFail.notify.endpoint = `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/api/notify/bad`;
// @ts-ignore
notify(metadata, configFail, publisherInfo).then(function () { notify(metadata, configFail, publisherInfo).then(function () {
expect(false).toBe('This service should fails with status code 400'); expect(false).toBe('This service should fails with status code 400');
done(); done();
@ -132,6 +139,7 @@ export default function(express) {
} }
}; };
// @ts-ignore
notify(metadata, config, publisherInfo).then( notify(metadata, config, publisherInfo).then(
function(body) { function(body) {
const jsonBody = parseBody(body); const jsonBody = parseBody(body);

View file

@ -1,5 +1,3 @@
// @flow
import { Version } from "@verdaccio/types"; import { Version } from "@verdaccio/types";
export function generateNewVersion( export function generateNewVersion(
@ -20,9 +18,8 @@ export function generateNewVersion(
"readme": "ERROR: No README data found!", "readme": "ERROR: No README data found!",
"_id": `${pkgName}@${version}`, "_id": `${pkgName}@${version}`,
"_npmVersion": "5.5.1", "_npmVersion": "5.5.1",
"_nodeVersion": "9.3.0",
"_npmUser": { "_npmUser": {
"name": "Foo"
}, },
"dist": { "dist": {
"integrity": "sha512-zVEqt1JUCOPsash9q4wMkJEDPD+QCx95TRhQII+JnoS31uBUKoZxhzvvUJCcLVy2CQG4QdwXARU7dYWPnrwhGg==", "integrity": "sha512-zVEqt1JUCOPsash9q4wMkJEDPD+QCx95TRhQII+JnoS31uBUKoZxhzvvUJCcLVy2CQG4QdwXARU7dYWPnrwhGg==",

View file

@ -25,7 +25,7 @@ export interface IServerProcess {
} }
declare class PromiseAssert<IRequestPromise> extends Promise<any> { declare class PromiseAssert<IRequestPromise> extends Promise<any> {
constructor(options: any): IRequestPromise; public constructor(options: any);
} }
export interface IServerBridge { export interface IServerBridge {

View file

@ -2,7 +2,8 @@ import _ from 'lodash';
import smartRequest, {PromiseAssert} from '../../lib/request'; import smartRequest, {PromiseAssert} from '../../lib/request';
import {mockServer} from '../__helper/mock'; import {mockServer} from '../__helper/mock';
import {HTTP_STATUS} from '../../../src/lib/constants'; import {HTTP_STATUS} from '../../../src/lib/constants';
import {IRequestPromise} from '../../types'; import { IRequestPromise } from '../../types';
import { VerdaccioError } from '@verdaccio/commons-api';
describe('Request Functional', () => { describe('Request Functional', () => {
const mockServerPort = 55547; const mockServerPort = 55547;
@ -15,10 +16,10 @@ describe('Request Functional', () => {
}); });
test('basic resolve', (done) => { test('basic resolve', (done) => {
const requestPromise: IRequestPromise = new PromiseAssert((resolve, reject) => { const requestPromise: IRequestPromise = new PromiseAssert(resolve => {
resolve(1); resolve(1);
}); });
// $FlowFixMe // @ts-ignore
requestPromise.then((result) => { requestPromise.then((result) => {
expect(result).toBe(1); expect(result).toBe(1);
done(); done();
@ -55,7 +56,7 @@ describe('Request Functional', () => {
url: restTest, url: restTest,
method: 'GET' method: 'GET'
}; };
// $FlowFixMe // @ts-ignore
smartRequest(options).status(HTTP_STATUS.OK).then((result)=> { smartRequest(options).status(HTTP_STATUS.OK).then((result)=> {
expect(JSON.parse(result).name).toBe('jquery'); expect(JSON.parse(result).name).toBe('jquery');
done(); done();
@ -67,10 +68,10 @@ describe('Request Functional', () => {
url: 'http://www.google.fake', url: 'http://www.google.fake',
method: 'GET' method: 'GET'
}; };
// $FlowFixMe // @ts-ignore
smartRequest(options).status(HTTP_STATUS.NOT_FOUND).then((result)=> { smartRequest(options).status(HTTP_STATUS.NOT_FOUND).then(() => {
// this never is resolved // we do not intent to resolve this
}, function(error) { }, (error: VerdaccioError) => {
expect(error.code).toBe('ENOTFOUND'); expect(error.code).toBe('ENOTFOUND');
done(); done();
}) })

View file

@ -171,6 +171,7 @@ describe('startServer via API', () => {
}); });
test('should return a list of 1 address provided', () => { test('should return a list of 1 address provided', () => {
// @ts-ignore
const addrs = getListListenAddresses(null, '1000'); const addrs = getListListenAddresses(null, '1000');
expect(_.isArray(addrs)).toBeTruthy(); expect(_.isArray(addrs)).toBeTruthy();
@ -178,6 +179,7 @@ describe('startServer via API', () => {
}); });
test('should return a list of 2 address provided', () => { test('should return a list of 2 address provided', () => {
// @ts-ignore
const addrs = getListListenAddresses(null, ['1000', '2000']); const addrs = getListListenAddresses(null, ['1000', '2000']);
expect(_.isArray(addrs)).toBeTruthy(); expect(_.isArray(addrs)).toBeTruthy();
@ -188,17 +190,24 @@ describe('startServer via API', () => {
// @ts-ignore // @ts-ignore
const [addrs] = getListListenAddresses(); const [addrs] = getListListenAddresses();
// @ts-ignore
expect(addrs.proto).toBe(DEFAULT_PROTOCOL); expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
// @ts-ignore
expect(addrs.host).toBe(DEFAULT_DOMAIN); expect(addrs.host).toBe(DEFAULT_DOMAIN);
// @ts-ignore
expect(addrs.port).toBe(DEFAULT_PORT); expect(addrs.port).toBe(DEFAULT_PORT);
}); });
test('should return default proto, host and custom port', () => { test('should return default proto, host and custom port', () => {
const initPort = '1000'; const initPort = '1000';
// @ts-ignore
const [addrs] = getListListenAddresses(null, initPort); const [addrs] = getListListenAddresses(null, initPort);
// @ts-ignore
expect(addrs.proto).toEqual(DEFAULT_PROTOCOL); expect(addrs.proto).toEqual(DEFAULT_PROTOCOL);
// @ts-ignore
expect(addrs.host).toEqual(DEFAULT_DOMAIN); expect(addrs.host).toEqual(DEFAULT_DOMAIN);
// @ts-ignore
expect(addrs.port).toEqual(initPort); expect(addrs.port).toEqual(initPort);
}); });

View file

@ -3,9 +3,9 @@ import {parseAddress as parse} from '../../../../src/lib/utils';
import {DEFAULT_DOMAIN, DEFAULT_PORT} from '../../../../src/lib/constants'; import {DEFAULT_DOMAIN, DEFAULT_PORT} from '../../../../src/lib/constants';
describe('Parse listen address', () => { 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]); useCases.push([uri, proto, host, port]);
} }

View file

@ -66,7 +66,7 @@ const checkDefaultConfPackages = (config) => {
describe('Config file', () => { describe('Config file', () => {
beforeAll(function() { beforeAll(function() {
// @ts-ignore
this.config = new Config(parseConfigFile(resolveConf('default'))); this.config = new Config(parseConfigFile(resolveConf('default')));
}); });

View file

@ -67,6 +67,7 @@ describe('Notifications:: Notify', () => {
describe('packagePatternFlags', () => { describe('packagePatternFlags', () => {
test("should send single notification with packagePatternFlags", async () => { test("should send single notification with packagePatternFlags", async () => {
const name = 'package'; const name = 'package';
// @ts-ignore
await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar'); 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 () => { test("should not match on send single notification with packagePatternFlags", async () => {
const name = 'no-mach-name'; const name = 'no-mach-name';
// @ts-ignore
await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar'); await notify({name}, packagePatternNotificationConfig, { name: 'foo'}, 'bar');
expect(notifyRequest).toHaveBeenCalledTimes(0); expect(notifyRequest).toHaveBeenCalledTimes(0);

View file

@ -19,6 +19,7 @@ describe('plugin loader', () => {
describe('auth plugins', () => { describe('auth plugins', () => {
test('testing auth valid plugin loader', () => { test('testing auth valid plugin loader', () => {
const _config = buildConf('verdaccio-plugin'); const _config = buildConf('verdaccio-plugin');
// @ts-ignore
const plugins = loadPlugin(_config, _config.auth, {}, function (plugin) { const plugins = loadPlugin(_config, _config.auth, {}, function (plugin) {
return plugin.authenticate || plugin.allow_access || plugin.allow_publish; return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
}); });
@ -28,6 +29,7 @@ describe('plugin loader', () => {
test('testing storage valid plugin loader', () => { test('testing storage valid plugin loader', () => {
const _config = buildConf('verdaccio-es6-plugin'); const _config = buildConf('verdaccio-es6-plugin');
// @ts-ignore
const plugins = loadPlugin(_config, _config.auth, {}, function (p) { const plugins = loadPlugin(_config, _config.auth, {}, function (p) {
return p.getPackageStorage; return p.getPackageStorage;
}); });

View file

@ -33,9 +33,9 @@ let packages = [
describe('search', () => { describe('search', () => {
beforeAll(async function() { beforeAll(async function() {
let config = new Config(buildConfig()); let config = new Config(buildConfig());
this.storage = new Storage(config); const storage = new Storage(config);
await this.storage.init(config); await storage.init(config);
Search.configureStorage(this.storage); Search.configureStorage(storage);
packages.map(function(item) { packages.map(function(item) {
// @ts-ignore // @ts-ignore
Search.add(item); Search.add(item);

View file

@ -12,7 +12,7 @@ import {generateNewVersion} from '../../../lib/utils-test';
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`).toString(); 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 {IStorage} from '../../../../types';
import { API_ERROR, HTTP_STATUS, DIST_TAGS} from '../../../../src/lib/constants'; import { API_ERROR, HTTP_STATUS, DIST_TAGS} from '../../../../src/lib/constants';
import { VerdaccioError } from '@verdaccio/commons-api'; import { VerdaccioError } from '@verdaccio/commons-api';
@ -34,7 +34,7 @@ describe('LocalStorage', () => {
return new LocalStorageClass(config, logger); return new LocalStorageClass(config, logger);
} }
const getPackageMetadataFromStore = (pkgName: string) => { const getPackageMetadataFromStore = (pkgName: string): Promise<Package> => {
return new Promise((resolve) => { return new Promise((resolve) => {
storage.getPackageMetadata(pkgName, (err, data ) => { storage.getPackageMetadata(pkgName, (err, data ) => {
resolve(data); resolve(data);
@ -150,7 +150,7 @@ describe('LocalStorage', () => {
storage.mergeTags(pkgName, tags, async (err, data) => { storage.mergeTags(pkgName, tags, async (err, data) => {
expect(err).toBeNull(); expect(err).toBeNull();
expect(data).toBeUndefined(); expect(data).toBeUndefined();
const metadata = await getPackageMetadataFromStore(pkgName); const metadata: Package = await getPackageMetadataFromStore(pkgName);
expect(metadata[DIST_TAGS]).toBeDefined(); expect(metadata[DIST_TAGS]).toBeDefined();
expect(metadata[DIST_TAGS]['beta']).toBeDefined(); expect(metadata[DIST_TAGS]['beta']).toBeDefined();
expect(metadata[DIST_TAGS]['beta']).toBe('3.0.0'); expect(metadata[DIST_TAGS]['beta']).toBe('3.0.0');
@ -170,7 +170,7 @@ describe('LocalStorage', () => {
beta: '9999.0.0' beta: '9999.0.0'
}; };
storage.mergeTags(pkgName, tags, async (err, data) => { storage.mergeTags(pkgName, tags, async (err) => {
expect(err).not.toBeNull(); expect(err).not.toBeNull();
expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND); expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND);
expect(err.message).toMatch(API_ERROR.VERSION_NOT_EXIST); expect(err.message).toMatch(API_ERROR.VERSION_NOT_EXIST);

View file

@ -59,7 +59,7 @@ describe('StorageTest', () => {
test('should fetch from uplink jquery metadata from registry', async (done) => { test('should fetch from uplink jquery metadata from registry', async (done) => {
const storage: IStorageHandler = await generateStorage(); const storage: IStorageHandler = await generateStorage();
// $FlowFixMe // @ts-ignore
storage._syncUplinksMetadata('jquery', null, {}, (err, metadata, errors) => { storage._syncUplinksMetadata('jquery', null, {}, (err, metadata, errors) => {
expect(err).toBeNull(); expect(err).toBeNull();
expect(metadata).toBeDefined(); expect(metadata).toBeDefined();
@ -71,7 +71,7 @@ describe('StorageTest', () => {
test('should fails on fetch from uplink non existing from registry', async (done) => { test('should fails on fetch from uplink non existing from registry', async (done) => {
const storage: IStorageHandler = await generateStorage(); const storage: IStorageHandler = await generateStorage();
// $FlowFixMe // @ts-ignore
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => { storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
expect(err).not.toBeNull(); expect(err).not.toBeNull();
expect(errors).toBeInstanceOf(Array); expect(errors).toBeInstanceOf(Array);
@ -84,7 +84,7 @@ describe('StorageTest', () => {
test('should fails on fetch from uplink corrupted pkg from registry', async (done) => { test('should fails on fetch from uplink corrupted pkg from registry', async (done) => {
const storage: IStorageHandler = await generateStorage(); const storage: IStorageHandler = await generateStorage();
// $FlowFixMe // @ts-ignore
storage._syncUplinksMetadata('corrupted-package', null, {}, (err, metadata, errors) => { storage._syncUplinksMetadata('corrupted-package', null, {}, (err, metadata, errors) => {
expect(err).not.toBeNull(); expect(err).not.toBeNull();
expect(errors).toBeInstanceOf(Array); expect(errors).toBeInstanceOf(Array);
@ -95,18 +95,19 @@ describe('StorageTest', () => {
}); });
test('should not touch if the package exists and has no uplinks', async (done) => { 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 metadataSource = path.join(__dirname, '../../partials/metadata');
const metadataPath = path.join(storagePath, 'npm_test/package.json'); const metadataPath = path.join(storagePath, 'npm_test/package.json');
fs.mkdirSync(path.join(storagePath, 'npm_test')); fs.mkdirSync(path.join(storagePath, 'npm_test'));
fs.writeFileSync(metadataPath, fs.readFileSync(metadataSource)); fs.writeFileSync(metadataPath, fs.readFileSync(metadataSource));
const metadata = JSON.parse(fs.readFileSync(metadataPath).toString()); const metadata = JSON.parse(fs.readFileSync(metadataPath).toString());
// $FlowFixMe // @ts-ignore
storage.localStorage.updateVersions = jest.fn(storage.localStorage.updateVersions); storage.localStorage.updateVersions = jest.fn(storage.localStorage.updateVersions);
expect(metadata).toBeDefined(); expect(metadata).toBeDefined();
storage._syncUplinksMetadata('npm_test', metadata, {}, (err) => { storage._syncUplinksMetadata('npm_test', metadata, {}, (err) => {
expect(err).toBeNull(); expect(err).toBeNull();
// @ts-ignore
expect(storage.localStorage.updateVersions).not.toHaveBeenCalled(); expect(storage.localStorage.updateVersions).not.toHaveBeenCalled();
done(); done();
}); });

View file

@ -10,12 +10,11 @@ function createUplink(config) {
url: DEFAULT_REGISTRY url: DEFAULT_REGISTRY
}; };
let mergeConfig = Object.assign({}, defaultConfig, config); let mergeConfig = Object.assign({}, defaultConfig, config);
// @ts-ignore
return new ProxyStorage(mergeConfig, {}); return new ProxyStorage(mergeConfig, {});
} }
function setHeaders(config, headers) { function setHeaders(config: unknown = {}, headers: unknown = {}) {
config = config || {};
headers = headers || {};
const uplink = createUplink(config); const uplink = createUplink(config);
return uplink._setHeaders({ return uplink._setHeaders({
headers headers

View file

@ -1,8 +1,6 @@
// @flow
import _ from 'lodash'; import _ from 'lodash';
import ProxyStorage from '../../../../src/lib/up-storage'; import ProxyStorage from '../../../../src/lib/up-storage';
import AppConfig from '../../../../src/lib/config'; import AppConfig from '../../../../src/lib/config';
// $FlowFixMe
import configExample from '../../partials/config'; import configExample from '../../partials/config';
import {setup} from '../../../../src/lib/logger'; import {setup} from '../../../../src/lib/logger';
@ -11,6 +9,7 @@ import {IProxy} from '../../../../types';
import {API_ERROR, HTTP_STATUS} from "../../../../src/lib/constants"; import {API_ERROR, HTTP_STATUS} from "../../../../src/lib/constants";
import {mockServer} from '../../__helper/mock'; import {mockServer} from '../../__helper/mock';
import {DOMAIN_SERVERS} from '../../../functional/config.functional'; import {DOMAIN_SERVERS} from '../../../functional/config.functional';
import { VerdaccioError } from '@verdaccio/commons-api';
setup([]); setup([]);
@ -100,7 +99,7 @@ describe('UpStorge', () => {
const tarball = `http://${DOMAIN_SERVERS}:${mockServerPort}/jquery/-/no-exist-1.5.1.tgz`; const tarball = `http://${DOMAIN_SERVERS}:${mockServerPort}/jquery/-/no-exist-1.5.1.tgz`;
const stream = proxy.fetchTarball(tarball); const stream = proxy.fetchTarball(tarball);
stream.on('error', function(err) { stream.on('error', function(err: VerdaccioError) {
expect(err).not.toBeNull(); expect(err).not.toBeNull();
expect(err.statusCode).toBe(HTTP_STATUS.NOT_FOUND); expect(err.statusCode).toBe(HTTP_STATUS.NOT_FOUND);
expect(err.message).toMatch(API_ERROR.NOT_FILE_UPLINK); expect(err.message).toMatch(API_ERROR.NOT_FILE_UPLINK);
@ -139,7 +138,7 @@ describe('UpStorge', () => {
// expect(err.statusCode).toBe(404); // expect(err.statusCode).toBe(404);
expect(proxy.failed_requests).toBe(2); expect(proxy.failed_requests).toBe(2);
const streamThirdTry = proxy.fetchTarball(tarball); const streamThirdTry = proxy.fetchTarball(tarball);
streamThirdTry.on('error', function(err) { streamThirdTry.on('error', function(err: VerdaccioError) {
expect(err).not.toBeNull(); expect(err).not.toBeNull();
expect(err.statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR); expect(err.statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
expect(proxy.failed_requests).toBe(2); expect(proxy.failed_requests).toBe(2);
@ -157,7 +156,7 @@ describe('UpStorge', () => {
describe('valid use cases', () => { describe('valid use cases', () => {
const validateUpLink = ( const validateUpLink = (
url: string, 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 uplinkConf = { url };
const proxy: IProxy = generateProxy(uplinkConf); const proxy: IProxy = generateProxy(uplinkConf);

View file

@ -136,13 +136,15 @@ describe('Config Utilities', () => {
expect(react).toBeDefined(); expect(react).toBeDefined();
expect(react.access).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.access[0]).toBe(ROLES.$ALL);
expect(react.publish).toBeDefined(); expect(react.publish).toBeDefined();
// $FlowFixMe // @ts-ignore
expect(react.publish[0]).toBe('admin'); expect(react.publish[0]).toBe('admin');
expect(react.proxy).toBeDefined(); expect(react.proxy).toBeDefined();
// $FlowFixMe // @ts-ignore
expect(react.proxy[0]).toBe('uplink2'); expect(react.proxy[0]).toBe('uplink2');
expect(react.storage).toBeDefined(); expect(react.storage).toBeDefined();

View file

@ -235,10 +235,10 @@ describe('Utilities', () => {
describe('validateName', () => { describe('validateName', () => {
test('should fails with no string', () => { test('should fails with no string', () => {
// intended to fail with flow, do not remove // intended to fail with Typescript, do not remove
// $FlowFixMe // @ts-ignore
expect(validateName(null)).toBeFalsy(); expect(validateName(null)).toBeFalsy();
// $FlowFixMe // @ts-ignore
expect(validateName(undefined)).toBeFalsy(); expect(validateName(undefined)).toBeFalsy();
}); });

View file

@ -20,7 +20,7 @@
], ],
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",
"test/**/.ts", "test/**/*.ts",
"types/*.d.ts" "types/*.d.ts"
] ]
} }