From 84afc1354bbb0ee24ef3c2fc8964674aa4de2005 Mon Sep 17 00:00:00 2001 From: vitalics Date: Wed, 6 Feb 2019 13:52:21 +0300 Subject: [PATCH 1/6] remove typings --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 98352d3f2c4d4..c33851d0d097f 100644 --- a/package.json +++ b/package.json @@ -286,6 +286,7 @@ "@types/listr": "^0.13.0", "@types/lodash": "^3.10.1", "@types/minimatch": "^2.0.29", + "@types/mocha": "^5.2.5", "@types/moment-timezone": "^0.5.8", "@types/mustache": "^0.8.31", "@types/node": "^10.12.12", From 52d4d1044f3429f176f725ef81ff18766575829d Mon Sep 17 00:00:00 2001 From: vitalics Date: Wed, 6 Feb 2019 15:36:23 +0300 Subject: [PATCH 2/6] add jest types for removing mocha collision --- packages/kbn-config-schema/tsconfig.json | 38 +++++++++++++----------- packages/kbn-i18n/tsconfig.json | 36 ++++++++++++---------- packages/kbn-pm/tsconfig.json | 26 +++++++++------- tsconfig.types.json | 30 +++++++++++-------- 4 files changed, 74 insertions(+), 56 deletions(-) diff --git a/packages/kbn-config-schema/tsconfig.json b/packages/kbn-config-schema/tsconfig.json index 7a250509cf435..3b1982520da06 100644 --- a/packages/kbn-config-schema/tsconfig.json +++ b/packages/kbn-config-schema/tsconfig.json @@ -1,17 +1,21 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "declaration": true, - "declarationDir": "./target/types", - "outDir": "./target/out", - "stripInternal": true, - "declarationMap": true - }, - "include": [ - "./types/joi.d.ts", - "./src/**/*.ts" - ], - "exclude": [ - "target" - ] -} +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationDir": "./target/types", + "outDir": "./target/out", + "stripInternal": true, + "declarationMap": true, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "./types/joi.d.ts", + "./src/**/*.ts" + ], + "exclude": [ + "target" + ] +} diff --git a/packages/kbn-i18n/tsconfig.json b/packages/kbn-i18n/tsconfig.json index c6d1da43b893f..3b757d1240bdc 100644 --- a/packages/kbn-i18n/tsconfig.json +++ b/packages/kbn-i18n/tsconfig.json @@ -1,16 +1,20 @@ -{ - "extends": "../../tsconfig.json", - "include": [ - "src/**/*.ts", - "src/**/*.tsx", - "types/intl_format_cache.d.ts", - "types/intl_relativeformat.d.ts" - ], - "exclude": [ - "target" - ], - "compilerOptions": { - "declaration": true, - "declarationDir": "./target/types", - } -} +{ + "extends": "../../tsconfig.json", + "include": [ + "src/**/*.ts", + "src/**/*.tsx", + "types/intl_format_cache.d.ts", + "types/intl_relativeformat.d.ts" + ], + "exclude": [ + "target" + ], + "compilerOptions": { + "declaration": true, + "declarationDir": "./target/types", + "types": [ + "jest", + "node" + ] + } +} diff --git a/packages/kbn-pm/tsconfig.json b/packages/kbn-pm/tsconfig.json index 5985d8f42843c..c9c3344a1df3a 100644 --- a/packages/kbn-pm/tsconfig.json +++ b/packages/kbn-pm/tsconfig.json @@ -1,10 +1,16 @@ -{ - "extends": "../../tsconfig.json", - "exclude": [ - "dist" - ], - "include": [ - "./src/**/*.ts", - "./types/index.d.ts" - ] -} +{ + "extends": "../../tsconfig.json", + "exclude": [ + "dist" + ], + "include": [ + "./src/**/*.ts", + "./types/index.d.ts" + ], + "compilerOptions": { + "types": [ + "jest", + "node" + ] + } +} diff --git a/tsconfig.types.json b/tsconfig.types.json index 91029bdae57a6..c50629931ddcb 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -1,13 +1,17 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "declaration": true, - "declarationDir": "./target/types", - "stripInternal": true, - "emitDeclarationOnly": true, - "declarationMap": true - }, - "include": [ - "./src/type_exports.ts" - ] -} +{ + "extends": "./tsconfig", + "compilerOptions": { + "declaration": true, + "declarationDir": "./target/types", + "stripInternal": true, + "emitDeclarationOnly": true, + "declarationMap": true, + "types": [ + "node", + "jest" + ] + }, + "include": [ + "./src/type_exports.ts" + ] +} From 67b9fc4723e2bd3c424faf9e8af6567dfe594b5f Mon Sep 17 00:00:00 2001 From: vitalics Date: Wed, 6 Feb 2019 17:12:22 +0300 Subject: [PATCH 3/6] add typings for global tsconfig try to fix ci --- tsconfig.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 5062e0093a483..bfa49a3bec769 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -46,7 +46,13 @@ // Provide full support for iterables in for..of, spread and destructuring when targeting ES5 or ES3. "downlevelIteration": true, // import tslib helpers rather than inlining helpers for iteration or spreading, for instance - "importHelpers": true + "importHelpers": true, + // adding global typings + "types": [ + "node", + "jest", + "react" + ] }, "include": [ "kibana.d.ts", From ce62ec513840706bf232bb3bb0758fe6b97ea9d0 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 7 Feb 2019 18:28:38 -0800 Subject: [PATCH 4/6] fix line-endings --- packages/kbn-config-schema/tsconfig.json | 42 ++++++++++++------------ packages/kbn-i18n/tsconfig.json | 40 +++++++++++----------- packages/kbn-pm/tsconfig.json | 32 +++++++++--------- tsconfig.types.json | 34 +++++++++---------- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/packages/kbn-config-schema/tsconfig.json b/packages/kbn-config-schema/tsconfig.json index 3b1982520da06..f6c61268da17c 100644 --- a/packages/kbn-config-schema/tsconfig.json +++ b/packages/kbn-config-schema/tsconfig.json @@ -1,21 +1,21 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "declaration": true, - "declarationDir": "./target/types", - "outDir": "./target/out", - "stripInternal": true, - "declarationMap": true, - "types": [ - "jest", - "node" - ] - }, - "include": [ - "./types/joi.d.ts", - "./src/**/*.ts" - ], - "exclude": [ - "target" - ] -} +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationDir": "./target/types", + "outDir": "./target/out", + "stripInternal": true, + "declarationMap": true, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "./types/joi.d.ts", + "./src/**/*.ts" + ], + "exclude": [ + "target" + ] +} diff --git a/packages/kbn-i18n/tsconfig.json b/packages/kbn-i18n/tsconfig.json index 3b757d1240bdc..d3dae3078c1d7 100644 --- a/packages/kbn-i18n/tsconfig.json +++ b/packages/kbn-i18n/tsconfig.json @@ -1,20 +1,20 @@ -{ - "extends": "../../tsconfig.json", - "include": [ - "src/**/*.ts", - "src/**/*.tsx", - "types/intl_format_cache.d.ts", - "types/intl_relativeformat.d.ts" - ], - "exclude": [ - "target" - ], - "compilerOptions": { - "declaration": true, - "declarationDir": "./target/types", - "types": [ - "jest", - "node" - ] - } -} +{ + "extends": "../../tsconfig.json", + "include": [ + "src/**/*.ts", + "src/**/*.tsx", + "types/intl_format_cache.d.ts", + "types/intl_relativeformat.d.ts" + ], + "exclude": [ + "target" + ], + "compilerOptions": { + "declaration": true, + "declarationDir": "./target/types", + "types": [ + "jest", + "node" + ] + } +} diff --git a/packages/kbn-pm/tsconfig.json b/packages/kbn-pm/tsconfig.json index c9c3344a1df3a..b05dd70f9d5c8 100644 --- a/packages/kbn-pm/tsconfig.json +++ b/packages/kbn-pm/tsconfig.json @@ -1,16 +1,16 @@ -{ - "extends": "../../tsconfig.json", - "exclude": [ - "dist" - ], - "include": [ - "./src/**/*.ts", - "./types/index.d.ts" - ], - "compilerOptions": { - "types": [ - "jest", - "node" - ] - } -} +{ + "extends": "../../tsconfig.json", + "exclude": [ + "dist" + ], + "include": [ + "./src/**/*.ts", + "./types/index.d.ts" + ], + "compilerOptions": { + "types": [ + "jest", + "node" + ] + } +} diff --git a/tsconfig.types.json b/tsconfig.types.json index c50629931ddcb..ce11da4e4100b 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -1,17 +1,17 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "declaration": true, - "declarationDir": "./target/types", - "stripInternal": true, - "emitDeclarationOnly": true, - "declarationMap": true, - "types": [ - "node", - "jest" - ] - }, - "include": [ - "./src/type_exports.ts" - ] -} +{ + "extends": "./tsconfig", + "compilerOptions": { + "declaration": true, + "declarationDir": "./target/types", + "stripInternal": true, + "emitDeclarationOnly": true, + "declarationMap": true, + "types": [ + "node", + "jest" + ] + }, + "include": [ + "./src/type_exports.ts" + ] +} From d292d64212ec991933d0d6094284584be5a9e60f Mon Sep 17 00:00:00 2001 From: spalger Date: Fri, 15 Feb 2019 10:25:31 -0800 Subject: [PATCH 5/6] [ftr] add ts support and use in console tests --- package.json | 1 + src/dev/typescript/projects.ts | 1 + src/es_archiver/es_archiver.d.ts | 32 +++++++++ src/es_archiver/index.d.ts | 20 ++++++ .../apps/console/{_console.js => _console.ts} | 16 +++-- .../apps/console/{index.js => index.ts} | 9 ++- test/tsconfig.json | 14 ++++ test/types/ftr_provider_contetxt.d.ts | 66 +++++++++++++++++++ test/types/index.d.ts | 21 ++++++ test/types/mocha_decorations.d.ts | 30 +++++++++ x-pack/test/tsconfig.json | 2 +- x-pack/test/types/providers.ts | 9 +-- 12 files changed, 202 insertions(+), 19 deletions(-) create mode 100644 src/es_archiver/es_archiver.d.ts create mode 100644 src/es_archiver/index.d.ts rename test/functional/apps/console/{_console.js => _console.ts} (85%) rename test/functional/apps/console/{index.js => index.ts} (80%) create mode 100644 test/tsconfig.json create mode 100644 test/types/ftr_provider_contetxt.d.ts create mode 100644 test/types/index.d.ts create mode 100644 test/types/mocha_decorations.d.ts diff --git a/package.json b/package.json index 77e930e166f1b..6080849f10f2d 100644 --- a/package.json +++ b/package.json @@ -273,6 +273,7 @@ "@types/enzyme": "^3.1.12", "@types/eslint": "^4.16.2", "@types/execa": "^0.9.0", + "@types/expect.js": "^0.3.29", "@types/fetch-mock": "7.2.1", "@types/json5": "^0.0.30", "@types/getopts": "^2.0.0", diff --git a/src/dev/typescript/projects.ts b/src/dev/typescript/projects.ts index b93d3a0ac5371..540441ab6b8de 100644 --- a/src/dev/typescript/projects.ts +++ b/src/dev/typescript/projects.ts @@ -25,6 +25,7 @@ import { Project } from './project'; export const PROJECTS = [ new Project(resolve(REPO_ROOT, 'tsconfig.json')), + new Project(resolve(REPO_ROOT, 'test/tsconfig.json'), 'kibana/test'), new Project(resolve(REPO_ROOT, 'x-pack/tsconfig.json')), new Project(resolve(REPO_ROOT, 'x-pack/test/tsconfig.json'), 'x-pack/test'), diff --git a/src/es_archiver/es_archiver.d.ts b/src/es_archiver/es_archiver.d.ts new file mode 100644 index 0000000000000..0b6fada05a358 --- /dev/null +++ b/src/es_archiver/es_archiver.d.ts @@ -0,0 +1,32 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { ToolingLog } from '@kbn/dev-utils'; +import { Client } from 'elasticsearch'; + +export class EsArchiver { + constructor(options: { client: Client; dataDir: string; log: ToolingLog; kibanaUrl: string }); + public save(name: string, indices: string | string[], options?: { raw?: boolean }): Promise; + public load(name: string, options?: { skipExisting?: boolean }): Promise; + public unload(name: string): Promise; + public rebuildAll(): Promise; + public edit(prefix: string, handler: () => Promise): Promise; + public loadIfNeeded(name: string): Promise; + public emptyKibanaIndex(): Promise; +} diff --git a/src/es_archiver/index.d.ts b/src/es_archiver/index.d.ts new file mode 100644 index 0000000000000..f7a579a98a42d --- /dev/null +++ b/src/es_archiver/index.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { EsArchiver } from './es_archiver'; diff --git a/test/functional/apps/console/_console.js b/test/functional/apps/console/_console.ts similarity index 85% rename from test/functional/apps/console/_console.js rename to test/functional/apps/console/_console.ts index 8ed8edede0344..148cbe98feacd 100644 --- a/test/functional/apps/console/_console.js +++ b/test/functional/apps/console/_console.ts @@ -18,6 +18,7 @@ */ import expect from 'expect.js'; +import { FtrProviderContext } from '../../../types'; const DEFAULT_REQUEST = ` @@ -30,38 +31,39 @@ GET _search `.trim(); -export default function ({ getService, getPageObjects }) { +// tslint:disable-next-line no-default-export +export default function({ getService, getPageObjects }: FtrProviderContext) { const retry = getService('retry'); const log = getService('log'); const PageObjects = getPageObjects(['common', 'console']); describe('console app', function describeIndexTests() { - before(async function () { + before(async () => { log.debug('navigateTo console'); await PageObjects.common.navigateToApp('console'); }); - it('should show the default request', async function () { + it('should show the default request', async () => { // collapse the help pane because we only get the VISIBLE TEXT, not the part that is scrolled await PageObjects.console.collapseHelp(); - await retry.try(async function () { + await retry.try(async () => { const actualRequest = await PageObjects.console.getRequest(); log.debug(actualRequest); expect(actualRequest.trim()).to.eql(DEFAULT_REQUEST); }); }); - it('default request response should include `"timed_out" : false`', async function () { + it('default request response should include `"timed_out" : false`', async () => { const expectedResponseContains = '"timed_out" : false,'; await PageObjects.console.clickPlay(); - await retry.try(async function () { + await retry.try(async () => { const actualResponse = await PageObjects.console.getResponse(); log.debug(actualResponse); expect(actualResponse).to.contain(expectedResponseContains); }); }); - it('settings should allow changing the text size', async function () { + it('settings should allow changing the text size', async () => { await PageObjects.console.setFontSizeSetting(20); await retry.try(async () => { // the settings are not applied synchronously, so we retry for a time diff --git a/test/functional/apps/console/index.js b/test/functional/apps/console/index.ts similarity index 80% rename from test/functional/apps/console/index.js rename to test/functional/apps/console/index.ts index 9e568c0ebbef0..51867d5f5d9f8 100644 --- a/test/functional/apps/console/index.js +++ b/test/functional/apps/console/index.ts @@ -17,13 +17,16 @@ * under the License. */ -export default function ({ getService, loadTestFile }) { +import { FtrProviderContext } from '../../../types'; + +// tslint:disable-next-line no-default-export +export default function({ getService, loadTestFile }: FtrProviderContext) { const browser = getService('browser'); - describe('console app', function () { + describe('console app', function() { this.tags('ciGroup1'); - before(async function () { + before(async () => { await browser.setWindowSize(1300, 1100); }); diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000000000..ce7389eda37a8 --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "types": [ + "expect.js", + "mocha", + "node" + ] + }, + "include": [ + "**/*", + ], + "exclude": [], +} diff --git a/test/types/ftr_provider_contetxt.d.ts b/test/types/ftr_provider_contetxt.d.ts new file mode 100644 index 0000000000000..77779db0abee8 --- /dev/null +++ b/test/types/ftr_provider_contetxt.d.ts @@ -0,0 +1,66 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { ToolingLog } from '@kbn/dev-utils'; +import { EsArchiver } from '../../src/es_archiver'; + +/** + * Intersect this with any type that is loaded async to give it the `init()` function + */ +interface AsyncService { + /** + * Services that are initialized async are not ready before the tests execute, so you might need + * to call `init()` and await the promise it returns before interacting with the service + */ + init(): Promise; +} + +/** + * place Service-specific types here + */ +interface ServiceTypes { + esArchiver: EsArchiver & AsyncService; + log: ToolingLog; + + // TODO: type these services + browser: any; + retry: any; +} + +/** + * place PageObject-specific types here + */ +interface PageObjectTypes { + // TODO: type these page objects + common: any; + console: any; +} + +// helper to extract value type in array of strings +type ValuesOf = T extends Array ? X : unknown; + +export interface FtrProviderContext { + getService(serviceName: T): ServiceTypes[T]; + + getPageObjects>( + pageObjectNames: T + ): { [K in ValuesOf]: PageObjectTypes[K] }; + + loadTestFile(path: string): void; +} diff --git a/test/types/index.d.ts b/test/types/index.d.ts new file mode 100644 index 0000000000000..6800391f3b15d --- /dev/null +++ b/test/types/index.d.ts @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './ftr_provider_contetxt'; +export * from './mocha_decorations'; diff --git a/test/types/mocha_decorations.d.ts b/test/types/mocha_decorations.d.ts new file mode 100644 index 0000000000000..3bf0090034081 --- /dev/null +++ b/test/types/mocha_decorations.d.ts @@ -0,0 +1,30 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Suite } from 'mocha'; + +// tslint:disable-next-line:no-namespace We need to use the namespace here to match the Mocha definition +declare module 'mocha' { + interface Suite { + /** + * Assign tags to the test suite to determine in which CI job it should be run. + */ + tags(tags: string[] | string): void; + } +} diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 87e34dc754cdc..ce7389eda37a8 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -8,7 +8,7 @@ ] }, "include": [ - "**/*", + "**/*", ], "exclude": [], } diff --git a/x-pack/test/types/providers.ts b/x-pack/test/types/providers.ts index 6865fece8605a..9699775428a5c 100644 --- a/x-pack/test/types/providers.ts +++ b/x-pack/test/types/providers.ts @@ -4,14 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export interface EsArchiverOptions { - skipExisting?: boolean; -} - -export interface EsArchiver { - load(archiveName: string, options?: EsArchiverOptions): Promise; - unload(archiveName: string): Promise; -} +import { EsArchiver } from '../../../src/es_archiver'; export interface KibanaFunctionalTestDefaultProviders { getService(serviceName: 'esArchiver'): EsArchiver; From 07780c91250effd19a5bf75fa8b774e273985b18 Mon Sep 17 00:00:00 2001 From: spalger Date: Fri, 15 Feb 2019 13:04:02 -0800 Subject: [PATCH 6/6] [types] move expect.js types into repo, remove global type --- package.json | 1 - packages/kbn-test/tsconfig.json | 6 + packages/kbn-test/types/expect.js.d.ts | 225 ++++++++++++++++++ .../ui/public/utils/__tests__/cidr_mask.ts | 2 +- test/tsconfig.json | 2 +- tsconfig.json | 3 +- x-pack/package.json | 1 - x-pack/test/tsconfig.json | 2 +- x-pack/tsconfig.json | 3 +- yarn.lock | 5 - 10 files changed, 238 insertions(+), 12 deletions(-) create mode 100644 packages/kbn-test/tsconfig.json create mode 100644 packages/kbn-test/types/expect.js.d.ts diff --git a/package.json b/package.json index 6080849f10f2d..77e930e166f1b 100644 --- a/package.json +++ b/package.json @@ -273,7 +273,6 @@ "@types/enzyme": "^3.1.12", "@types/eslint": "^4.16.2", "@types/execa": "^0.9.0", - "@types/expect.js": "^0.3.29", "@types/fetch-mock": "7.2.1", "@types/json5": "^0.0.30", "@types/getopts": "^2.0.0", diff --git a/packages/kbn-test/tsconfig.json b/packages/kbn-test/tsconfig.json new file mode 100644 index 0000000000000..8d42818502289 --- /dev/null +++ b/packages/kbn-test/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "types/**/*" + ] +} diff --git a/packages/kbn-test/types/expect.js.d.ts b/packages/kbn-test/types/expect.js.d.ts new file mode 100644 index 0000000000000..fd3cbd852f967 --- /dev/null +++ b/packages/kbn-test/types/expect.js.d.ts @@ -0,0 +1,225 @@ +// tslint:disable + +// Type definitions for expect.js 0.3.1 +// Project: https://github.com/Automattic/expect.js +// Definitions by: Teppei Sato +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// License: MIT + +declare module 'expect.js' { + function expect(target?: any): Root; + + interface Assertion { + /** + * Assert typeof / instanceof. + */ + an: An; + /** + * Check if the value is truthy + */ + ok(): void; + + /** + * Creates an anonymous function which calls fn with arguments. + */ + withArgs(...args: any[]): Root; + + /** + * Assert that the function throws. + * + * @param fn callback to match error string against + */ + throwError(fn?: (exception: any) => void): void; + + /** + * Assert that the function throws. + * + * @param fn callback to match error string against + */ + throwException(fn?: (exception: any) => void): void; + + /** + * Assert that the function throws. + * + * @param regexp regexp to match error string against + */ + throwError(regexp: RegExp): void; + + /** + * Assert that the function throws. + * + * @param fn callback to match error string against + */ + throwException(regexp: RegExp): void; + + /** + * Checks if the array is empty. + */ + empty(): Assertion; + + /** + * Checks if the obj exactly equals another. + */ + equal(obj: any): Assertion; + + /** + * Checks if the obj sortof equals another. + */ + eql(obj: any): Assertion; + + /** + * Assert within start to finish (inclusive). + * + * @param start + * @param finish + */ + within(start: number, finish: number): Assertion; + + /** + * Assert typeof. + */ + a(type: string): Assertion; + + /** + * Assert instanceof. + */ + a(type: Function): Assertion; + + /** + * Assert numeric value above n. + */ + greaterThan(n: number): Assertion; + + /** + * Assert numeric value above n. + */ + above(n: number): Assertion; + + /** + * Assert numeric value below n. + */ + lessThan(n: number): Assertion; + + /** + * Assert numeric value below n. + */ + below(n: number): Assertion; + + /** + * Assert string value matches regexp. + * + * @param regexp + */ + match(regexp: RegExp): Assertion; + + /** + * Assert property "length" exists and has value of n. + * + * @param n + */ + length(n: number): Assertion; + + /** + * Assert property name exists, with optional val. + * + * @param name + * @param val + */ + property(name: string, val?: any): Assertion; + + /** + * Assert that string contains str. + */ + contain(str: string): Assertion; + string(str: string): Assertion; + + /** + * Assert that the array contains obj. + */ + contain(obj: any): Assertion; + string(obj: any): Assertion; + + /** + * Assert exact keys or inclusion of keys by using the `.own` modifier. + */ + key(keys: string[]): Assertion; + /** + * Assert exact keys or inclusion of keys by using the `.own` modifier. + */ + key(...keys: string[]): Assertion; + /** + * Assert exact keys or inclusion of keys by using the `.own` modifier. + */ + keys(keys: string[]): Assertion; + /** + * Assert exact keys or inclusion of keys by using the `.own` modifier. + */ + keys(...keys: string[]): Assertion; + + /** + * Assert a failure. + */ + fail(message?: string): Assertion; + } + + interface Root extends Assertion { + not: Not; + to: To; + only: Only; + have: Have; + be: Be; + } + + interface Be extends Assertion { + /** + * Checks if the obj exactly equals another. + */ + (obj: any): Assertion; + + an: An; + } + + interface An extends Assertion { + /** + * Assert typeof. + */ + (type: string): Assertion; + + /** + * Assert instanceof. + */ + (type: Function): Assertion; + } + + interface Not extends NotBase { + to: ToBase; + } + + interface NotBase extends Assertion { + be: Be; + have: Have; + include: Assertion; + only: Only; + } + + interface To extends ToBase { + not: NotBase; + } + + interface ToBase extends Assertion { + be: Be; + have: Have; + include: Assertion; + only: Only; + } + + interface Only extends Assertion { + have: Have; + } + + interface Have extends Assertion { + own: Assertion; + } + + export default expect; +} diff --git a/src/legacy/ui/public/utils/__tests__/cidr_mask.ts b/src/legacy/ui/public/utils/__tests__/cidr_mask.ts index 5375552d0ad05..8624bb1b6e0b2 100644 --- a/src/legacy/ui/public/utils/__tests__/cidr_mask.ts +++ b/src/legacy/ui/public/utils/__tests__/cidr_mask.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -// @ts-ignore + import expect from 'expect.js'; import { CidrMask } from '../cidr_mask'; diff --git a/test/tsconfig.json b/test/tsconfig.json index ce7389eda37a8..4f19009b23f49 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -2,7 +2,7 @@ "extends": "../tsconfig.json", "compilerOptions": { "types": [ - "expect.js", + "@kbn/test/types/expect.js", "mocha", "node" ] diff --git a/tsconfig.json b/tsconfig.json index ef46c9d73cf76..d6306ee8ea710 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -51,7 +51,8 @@ "types": [ "node", "jest", - "react" + "react", + "@kbn/test/types/expect.js" ] }, "include": [ diff --git a/x-pack/package.json b/x-pack/package.json index 9314a7c3a4dad..d9dc087945730 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -44,7 +44,6 @@ "@types/d3-time": "^1.0.7", "@types/d3-time-format": "^2.1.0", "@types/elasticsearch": "^5.0.30", - "@types/expect.js": "^0.3.29", "@types/graphql": "^0.13.1", "@types/history": "^4.6.2", "@types/jest": "^23.3.1", diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index ce7389eda37a8..4f19009b23f49 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -2,7 +2,7 @@ "extends": "../tsconfig.json", "compilerOptions": { "types": [ - "expect.js", + "@kbn/test/types/expect.js", "mocha", "node" ] diff --git a/x-pack/tsconfig.json b/x-pack/tsconfig.json index a724e008f3c29..584212385a46f 100644 --- a/x-pack/tsconfig.json +++ b/x-pack/tsconfig.json @@ -31,7 +31,8 @@ }, "types": [ "node", - "jest" + "jest", + "@kbn/test/types/expect.js" ] } } diff --git a/yarn.lock b/yarn.lock index 4d249531a07c7..a3e0712356f9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1892,11 +1892,6 @@ dependencies: "@types/node" "*" -"@types/expect.js@^0.3.29": - version "0.3.29" - resolved "https://registry.yarnpkg.com/@types/expect.js/-/expect.js-0.3.29.tgz#28dd359155b84b8ecb094afc3f4b74c3222dca3b" - integrity sha1-KN01kVW4S47LCUr8P0t0wyItyjs= - "@types/fetch-mock@7.2.1": version "7.2.1" resolved "https://registry.yarnpkg.com/@types/fetch-mock/-/fetch-mock-7.2.1.tgz#5630999aa75532e00af42a54cbe05e1651f4a080"