diff --git a/src/lib/cli/utils.ts b/src/lib/cli/utils.ts index dd6742f9d..0e38675e3 100644 --- a/src/lib/cli/utils.ts +++ b/src/lib/cli/utils.ts @@ -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) { diff --git a/test/functional/lib/environment.ts b/test/functional/lib/environment.ts index d0cc5fa8e..f347f997a 100644 --- a/test/functional/lib/environment.ts +++ b/test/functional/lib/environment.ts @@ -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); } } diff --git a/test/functional/notifications/notify.ts b/test/functional/notifications/notify.ts index 0c2a9e112..10e3ecb4b 100644 --- a/test/functional/notifications/notify.ts +++ b/test/functional/notifications/notify.ts @@ -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); diff --git a/test/lib/utils-test.ts b/test/lib/utils-test.ts index f86b59159..1345087c7 100644 --- a/test/lib/utils-test.ts +++ b/test/lib/utils-test.ts @@ -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==", diff --git a/test/types/index.ts b/test/types/index.ts index ff79a41a0..030ec2b71 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -25,7 +25,7 @@ export interface IServerProcess { } declare class PromiseAssert extends Promise { - constructor(options: any): IRequestPromise; + public constructor(options: any); } export interface IServerBridge { diff --git a/test/unit/functionalLibs/request.spec.ts b/test/unit/functionalLibs/request.spec.ts index 1ce72d9d8..95330c079 100644 --- a/test/unit/functionalLibs/request.spec.ts +++ b/test/unit/functionalLibs/request.spec.ts @@ -2,7 +2,8 @@ import _ from 'lodash'; import smartRequest, {PromiseAssert} from '../../lib/request'; import {mockServer} from '../__helper/mock'; import {HTTP_STATUS} from '../../../src/lib/constants'; -import {IRequestPromise} from '../../types'; +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(); }) diff --git a/test/unit/modules/cli/cli.spec.ts b/test/unit/modules/cli/cli.spec.ts index cdb039db5..d21f3a6ce 100644 --- a/test/unit/modules/cli/cli.spec.ts +++ b/test/unit/modules/cli/cli.spec.ts @@ -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); }); diff --git a/test/unit/modules/cli/parseAddress.spec.ts b/test/unit/modules/cli/parseAddress.spec.ts index 8b049cc56..78649fc49 100644 --- a/test/unit/modules/cli/parseAddress.spec.ts +++ b/test/unit/modules/cli/parseAddress.spec.ts @@ -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]); } diff --git a/test/unit/modules/config/config.spec.ts b/test/unit/modules/config/config.spec.ts index 3fb6d6891..66010fdc5 100644 --- a/test/unit/modules/config/config.spec.ts +++ b/test/unit/modules/config/config.spec.ts @@ -66,7 +66,7 @@ const checkDefaultConfPackages = (config) => { describe('Config file', () => { beforeAll(function() { - + // @ts-ignore this.config = new Config(parseConfigFile(resolveConf('default'))); }); diff --git a/test/unit/modules/notifications/notify.spec.ts b/test/unit/modules/notifications/notify.spec.ts index f26f25d8b..eb503624b 100644 --- a/test/unit/modules/notifications/notify.spec.ts +++ b/test/unit/modules/notifications/notify.spec.ts @@ -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); diff --git a/test/unit/modules/plugin/plugin_loader.spec.ts b/test/unit/modules/plugin/plugin_loader.spec.ts index cbddd04f2..72da9d200 100644 --- a/test/unit/modules/plugin/plugin_loader.spec.ts +++ b/test/unit/modules/plugin/plugin_loader.spec.ts @@ -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; }); diff --git a/test/unit/modules/search/search.spec.ts b/test/unit/modules/search/search.spec.ts index 2cfd2cff2..affd08e1d 100644 --- a/test/unit/modules/search/search.spec.ts +++ b/test/unit/modules/search/search.spec.ts @@ -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); diff --git a/test/unit/modules/storage/local-storage.spec.ts b/test/unit/modules/storage/local-storage.spec.ts index 72a6e8ec8..2fd9690c2 100644 --- a/test/unit/modules/storage/local-storage.spec.ts +++ b/test/unit/modules/storage/local-storage.spec.ts @@ -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 => { 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); diff --git a/test/unit/modules/storage/store.spec.ts b/test/unit/modules/storage/store.spec.ts index 1db6765b1..3743f3cde 100644 --- a/test/unit/modules/storage/store.spec.ts +++ b/test/unit/modules/storage/store.spec.ts @@ -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(); }); diff --git a/test/unit/modules/uplinks/headers.auth.spec.ts b/test/unit/modules/uplinks/headers.auth.spec.ts index 9050b97d4..6ae91a171 100644 --- a/test/unit/modules/uplinks/headers.auth.spec.ts +++ b/test/unit/modules/uplinks/headers.auth.spec.ts @@ -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 diff --git a/test/unit/modules/uplinks/up-storage.spec.ts b/test/unit/modules/uplinks/up-storage.spec.ts index a684ce472..1497968f8 100644 --- a/test/unit/modules/uplinks/up-storage.spec.ts +++ b/test/unit/modules/uplinks/up-storage.spec.ts @@ -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); diff --git a/test/unit/modules/utils/config-utils.spec.ts b/test/unit/modules/utils/config-utils.spec.ts index 5e82db423..9a05205dd 100644 --- a/test/unit/modules/utils/config-utils.spec.ts +++ b/test/unit/modules/utils/config-utils.spec.ts @@ -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(); diff --git a/test/unit/modules/utils/utils.spec.ts b/test/unit/modules/utils/utils.spec.ts index 2e040e1bb..b2c3e941f 100644 --- a/test/unit/modules/utils/utils.spec.ts +++ b/test/unit/modules/utils/utils.spec.ts @@ -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(); }); diff --git a/tsconfig.json b/tsconfig.json index 90751aabd..da919fb00 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ ], "include": [ "src/**/*.ts", - "test/**/.ts", + "test/**/*.ts", "types/*.d.ts" ] }