Skip to content

Commit

Permalink
explicitly export mock types. not to rely on global ones
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Oct 22, 2020
1 parent 17e1578 commit d8760f0
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/core/public/apm_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

jest.mock('@elastic/apm-rum');
import { init, apm } from '@elastic/apm-rum';
import type { DeeplyMockedKeys } from '../types';
import { ApmSystem } from './apm_system';

const initMock = init as jest.Mocked<typeof init>;
Expand Down
1 change: 1 addition & 0 deletions src/core/public/chrome/chrome_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { BehaviorSubject } from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';
import type { DeeplyMockedKeys } from '../../types';
import { ChromeBadge, ChromeBrand, ChromeBreadcrumb, ChromeService, InternalChromeStart } from './';

const createStartContractMock = () => {
Expand Down
4 changes: 3 additions & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import {
export { PackageInfo, EnvironmentMode } from '../server/types';
export { CoreContext, CoreSystem } from './core_system';
export { DEFAULT_APP_CATEGORIES } from '../utils';
export {
export type {
AppCategory,
UiSettingsParams,
UserProvidedValues,
Expand All @@ -89,6 +89,8 @@ export {
StringValidation,
StringValidationRegex,
StringValidationRegexString,
DeeplyMockedKeys,
MockedKeys,
} from '../types';

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import type { MockedKeys } from '../../types';
import {
NotificationsService,
NotificationsSetup,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/overlays/overlay_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import type { DeeplyMockedKeys } from '../../types';
import { OverlayService, OverlayStart } from './overlay_service';
import { overlayBannersServiceMock } from './banners/banners_service.mock';
import { overlayFlyoutServiceMock } from './flyout/flyout_service.mock';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/core_context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { REPO_ROOT } from '@kbn/dev-utils';
import type { DeeplyMockedKeys } from '../types';
import { CoreContext } from './core_context';
import { Env, IConfigService } from './config';
import { configServiceMock, getEnvOptions } from './config/mocks';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/elasticsearch/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { Client, ApiResponse } from '@elastic/elasticsearch';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { ElasticsearchClient } from './types';
import type { DeeplyMockedKeys } from '../../../types';
import { ICustomClusterClient } from './cluster_client';

const createInternalClientMock = (): DeeplyMockedKeys<Client> => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export {
MetricsServiceStart,
} from './metrics';

export { AppCategory } from '../types';
export type { AppCategory, DeeplyMockedKeys, MockedKeys } from '../types';
export { DEFAULT_APP_CATEGORIES } from '../utils';

export {
Expand Down
8 changes: 7 additions & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
import { of } from 'rxjs';
import { duration } from 'moment';
import { ByteSizeValue } from '@kbn/config-schema';
import { PluginInitializerContext, CoreSetup, CoreStart, StartServicesAccessor } from '.';
import type {
PluginInitializerContext,
CoreSetup,
CoreStart,
StartServicesAccessor,
MockedKeys,
} from '.';
import { loggingSystemMock } from './logging/logging_system.mock';
import { loggingServiceMock } from './logging/logging_service.mock';
import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock';
Expand Down
1 change: 1 addition & 0 deletions src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from './app_category';
export * from './ui_settings';
export * from './saved_objects';
export * from './serializable';
export * from './mocks';
4 changes: 2 additions & 2 deletions src/core/typings.ts → src/core/types/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

type DeeplyMockedKeys<T> = {
export type DeeplyMockedKeys<T> = {
[P in keyof T]: T[P] extends (...args: any[]) => any
? jest.MockInstance<ReturnType<T[P]>, Parameters<T[P]>>
: DeeplyMockedKeys<T[P]>;
} &
T;

type MockedKeys<T> = { [P in keyof T]: jest.Mocked<T[P]> };
export type MockedKeys<T> = { [P in keyof T]: jest.Mocked<T[P]> };

0 comments on commit d8760f0

Please sign in to comment.