Update jest to v24 (#31825) (#32193)

* udpate jest, jest-cli, @types/jest to v24

* fix type error in kibana-i18n package

* return serivce explicitly to fix typings

* add explicit never

* suppress typings errors

* update jest versions in x-pack

* make tests in x-pack more robust and fix incompatibility

* suppress CallCluster mock typings

Mock interface doesn't match CallCluster. Requires
additional work

* x-pack. resolve other typing conflicts

* remove unused types/jest

* fix snapshots

* restore mocks after jest.spyOn

* remove outdated definitions for jest

* cleanup x-pack package.json and update @types/jest

* fix tests merged from master

* updated yarn.lock and log errors for scripts/type_check

* This commit fixes error in TS, which failed on parsing the file.

* suppress type errors from master

* jest-cli is devDep

Removes sinon from saved objects unit tests. (#32045) (#32151)

* Removes sinon from saved objects unit tests.

* Uses mockResolvedValue for return values as promises.

temp
This commit is contained in:
Mikhail Shustov 2019-02-28 15:57:48 +01:00 committed by GitHub
parent 3046b062f1
commit c2c8f9d878
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 796 additions and 773 deletions

View file

@ -281,7 +281,7 @@
"@types/has-ansi": "^3.0.0",
"@types/hoek": "^4.1.3",
"@types/humps": "^1.1.2",
"@types/jest": "^23.3.1",
"@types/jest": "^24.0.9",
"@types/joi": "^13.4.2",
"@types/jquery": "^3.3.6",
"@types/js-yaml": "^3.11.1",
@ -359,8 +359,8 @@
"intl-messageformat-parser": "^1.4.0",
"is-path-inside": "^2.0.0",
"istanbul-instrumenter-loader": "3.0.1",
"jest": "^23.6.0",
"jest-cli": "^23.6.0",
"jest": "^24.1.0",
"jest-cli": "^24.1.0",
"jest-raw-loader": "^1.0.1",
"jimp": "0.2.28",
"json-stable-stringify": "^1.0.1",

View file

@ -885,7 +885,7 @@ describe('I18n engine', () => {
});
describe('load', () => {
let mockFetch: jest.Mock<unknown>;
let mockFetch: jest.Mock;
beforeEach(() => {
mockFetch = jest.spyOn(global as any, 'fetch').mockImplementation();
});

View file

@ -20,7 +20,6 @@
"@types/globby": "^6.1.0",
"@types/has-ansi": "^3.0.0",
"@types/indent-string": "^3.0.0",
"@types/jest": "^23.3.1",
"@types/lodash.clonedeepwith": "^4.5.3",
"@types/log-symbols": "^2.0.0",
"@types/mkdirp": "^0.5.2",

View file

@ -116,9 +116,7 @@ test('respects both `include` and `exclude` filters if specified at the same tim
});
test('does not run command if all projects are filtered out', async () => {
const mockProcessExit = jest.spyOn(process, 'exit').mockImplementation(() => {
// noop
});
const mockProcessExit = jest.spyOn(process, 'exit').mockReturnValue(undefined as never);
await runCommand(command, {
...config,

View file

@ -1,16 +1,15 @@
{
"extends": "../../tsconfig.json",
"exclude": [
"dist"
],
"include": [
"./src/**/*.ts",
"./types/index.d.ts"
],
"compilerOptions": {
"types": [
"jest",
"node"
]
}
}
{
"extends": "../../tsconfig.json",
"exclude": [
"dist"
],
"include": [
"./src/**/*.ts"
],
"compilerOptions": {
"types": [
"jest",
"node"
]
}
}

View file

@ -1 +0,0 @@
/// <reference path="./jest/index.d.ts" />

View file

@ -1,13 +0,0 @@
///<reference types="jest"/>
// Workaround for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/17605.
declare namespace jest {
interface SpyInstance<T> extends Mock<T> {
mockImplementation(fn: (...args: any[]) => any): SpyInstance<T>;
mockImplementationOnce(fn: (...args: any[]) => any): SpyInstance<T>;
mockReturnThis(): SpyInstance<T>;
mockReturnValue(value: any): SpyInstance<T>;
mockReturnValueOnce(value: any): SpyInstance<T>;
mockName(name: string): SpyInstance<T>;
}
}

View file

@ -60,20 +60,12 @@ describe('start', () => {
const startDeps = defaultStartDeps();
startDeps.injectedMetadata.getCspConfig.mockReturnValue({ warnLegacyBrowsers: true });
service.start(startDeps);
expect(startDeps.notifications.toasts.addWarning).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"Your browser does not meet the security requirements for Kibana.",
],
expect(startDeps.notifications.toasts.addWarning.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"Your browser does not meet the security requirements for Kibana.",
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
}
]
`);
});

View file

@ -27,20 +27,23 @@ import { LegacyPlatformService } from './legacy';
import { NotificationsService } from './notifications';
import { UiSettingsService } from './ui_settings';
const MockLegacyPlatformService = jest.fn<LegacyPlatformService>(
const MockLegacyPlatformService = jest.fn<LegacyPlatformService, any>(
function _MockLegacyPlatformService(this: any) {
this.start = jest.fn();
this.stop = jest.fn();
return this;
}
);
jest.mock('./legacy', () => ({
LegacyPlatformService: MockLegacyPlatformService,
}));
const mockInjectedMetadataStart = {};
const MockInjectedMetadataService = jest.fn<InjectedMetadataService>(
const MockInjectedMetadataService = jest.fn<InjectedMetadataService, any>(
function _MockInjectedMetadataService(this: any) {
this.start = jest.fn().mockReturnValue(mockInjectedMetadataStart);
return this;
}
);
jest.mock('./injected_metadata', () => ({
@ -48,69 +51,81 @@ jest.mock('./injected_metadata', () => ({
}));
const mockFatalErrorsStart = {};
const MockFatalErrorsService = jest.fn<FatalErrorsService>(function _MockFatalErrorsService(
const MockFatalErrorsService = jest.fn<FatalErrorsService, any>(function _MockFatalErrorsService(
this: any
) {
this.start = jest.fn().mockReturnValue(mockFatalErrorsStart);
this.add = jest.fn();
return this;
});
jest.mock('./fatal_errors', () => ({
FatalErrorsService: MockFatalErrorsService,
}));
const mockI18nStart = {};
const MockI18nService = jest.fn<I18nService>(function _MockI18nService(this: any) {
const MockI18nService = jest.fn<I18nService, any>(function _MockI18nService(this: any) {
this.start = jest.fn().mockReturnValue(mockI18nStart);
this.stop = jest.fn();
return this;
});
jest.mock('./i18n', () => ({
I18nService: MockI18nService,
}));
const mockNotificationStart = {};
const MockNotificationsService = jest.fn<NotificationsService>(function _MockNotificationsService(
this: any
) {
this.start = jest.fn().mockReturnValue(mockNotificationStart);
this.add = jest.fn();
this.stop = jest.fn();
});
const MockNotificationsService = jest.fn<NotificationsService, any>(
function _MockNotificationsService(this: any) {
this.start = jest.fn().mockReturnValue(mockNotificationStart);
this.add = jest.fn();
this.stop = jest.fn();
return this;
}
);
jest.mock('./notifications', () => ({
NotificationsService: MockNotificationsService,
}));
const mockHttp = {};
const MockHttpService = jest.fn<HttpService>(function _MockNotificationsService(this: any) {
const MockHttpService = jest.fn<HttpService, any>(function _MockNotificationsService(this: any) {
this.start = jest.fn().mockReturnValue(mockHttp);
this.stop = jest.fn();
return this;
});
jest.mock('./http', () => ({
HttpService: MockHttpService,
}));
const mockBasePathStart = {};
const MockBasePathService = jest.fn<BasePathService>(function _MockNotificationsService(this: any) {
const MockBasePathService = jest.fn<BasePathService, any>(function _MockNotificationsService(
this: any
) {
this.start = jest.fn().mockReturnValue(mockBasePathStart);
return this;
});
jest.mock('./base_path', () => ({
BasePathService: MockBasePathService,
}));
const mockUiSettings = {};
const MockUiSettingsService = jest.fn<UiSettingsService>(function _MockNotificationsService(
const MockUiSettingsService = jest.fn<UiSettingsService, any>(function _MockNotificationsService(
this: any
) {
this.start = jest.fn().mockReturnValue(mockUiSettings);
this.stop = jest.fn();
return this;
});
jest.mock('./ui_settings', () => ({
UiSettingsService: MockUiSettingsService,
}));
const mockChromeStart = {};
const MockChromeService = jest.fn<ChromeService>(function _MockNotificationsService(this: any) {
const MockChromeService = jest.fn<ChromeService, any>(function _MockNotificationsService(
this: any
) {
this.start = jest.fn().mockReturnValue(mockChromeStart);
this.stop = jest.fn();
return this;
});
jest.mock('./chrome', () => ({
ChromeService: MockChromeService,

View file

@ -60,7 +60,7 @@ describe('reloading', () => {
expect(locationReloadSpy).not.toHaveBeenCalled();
const [, handler] = addEventListenerSpy.mock.calls[0];
handler();
(handler as jest.Mock)();
expect(locationReloadSpy).toHaveBeenCalledTimes(1);
});
});

View file

@ -100,9 +100,7 @@ describe('start.add()', () => {
it('exposes a function that passes its two arguments to fatalErrors.add()', () => {
const { fatalErrors, i18n } = setup();
jest.spyOn(fatalErrors, 'add').mockImplementation(() => {
/* noop */
});
jest.spyOn(fatalErrors, 'add').mockImplementation(() => undefined as never);
expect(fatalErrors.add).not.toHaveBeenCalled();
const { add } = fatalErrors.start({ i18n });

View file

@ -12,7 +12,7 @@ exports[`#start constructs UiSettingsClient and UiSettingsApi: UiSettingsApi arg
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],
@ -31,7 +31,7 @@ exports[`#start constructs UiSettingsClient and UiSettingsApi: UiSettingsClient
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": Object {
"loadingCountObservable": true,
},
@ -52,7 +52,7 @@ exports[`#start constructs UiSettingsClient and UiSettingsApi: UiSettingsClient
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],
@ -70,7 +70,7 @@ exports[`#start passes the uiSettings loading count to the loading count api: ht
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],

View file

@ -22,7 +22,7 @@ function mockClass<T>(
Class: { new (...args: any[]): T },
setup: (instance: any, args: any[]) => void
) {
const MockClass = jest.fn<T>(function(this: any, ...args: any[]) {
const MockClass = jest.fn(function(this: any, ...args: any[]) {
setup(this, args);
});

View file

@ -91,8 +91,7 @@ test('throws if [redirectHttpFromPort] is in use', async () => {
} as HttpConfig)
).rejects.toMatchSnapshot();
// Workaround for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/17605.
(mockListen as any).mockRestore();
mockListen.mockRestore();
});
test('forwards http requests to https', async () => {

View file

@ -37,7 +37,7 @@ Array [
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],

View file

@ -46,8 +46,8 @@ test('correctly redirects server events.', () => {
([serverEventName]) => serverEventName === eventName
)!;
serverListener(1, 2, 3, 4);
serverListener(5, 6, 7, 8);
(serverListener as jest.Mock)(1, 2, 3, 4);
(serverListener as jest.Mock)(5, 6, 7, 8);
expect(listener).toHaveBeenCalledTimes(2);
expect(listener).toHaveBeenCalledWith(1, 2, 3, 4);

View file

@ -25,15 +25,18 @@ import { BaseLogger } from './logger';
const context = LoggingConfig.getLoggerContext(['context', 'parent', 'child']);
let appenderMocks: Appender[];
let logger: BaseLogger;
const timestamp = new Date(2012, 1, 1);
jest.spyOn(global, 'Date').mockImplementation(() => timestamp);
beforeEach(() => {
jest.spyOn<any, any>(global, 'Date').mockImplementation(() => timestamp);
appenderMocks = [{ append: jest.fn() }, { append: jest.fn() }];
logger = new BaseLogger(context, LogLevel.All, appenderMocks);
});
afterEach(() => {
jest.restoreAllMocks();
});
test('`trace()` correctly forms `LogRecord` and passes it to all appenders.', () => {
logger.trace('message-1');
for (const appenderMock of appenderMocks) {

View file

@ -24,21 +24,22 @@ jest.mock('fs', () => ({
}));
const timestamp = new Date(Date.UTC(2012, 1, 1));
const mockConsoleLog = jest.spyOn(global.console, 'log').mockImplementation(() => {
// noop
});
jest.spyOn(global, 'Date').mockImplementation(() => timestamp);
let mockConsoleLog: jest.SpyInstance;
import { createWriteStream } from 'fs';
const mockCreateWriteStream = createWriteStream as jest.Mock<typeof createWriteStream>;
const mockCreateWriteStream = (createWriteStream as unknown) as jest.Mock<typeof createWriteStream>;
import { LoggingConfig, LoggingService } from '.';
let service: LoggingService;
beforeEach(() => (service = new LoggingService()));
beforeEach(() => {
mockConsoleLog = jest.spyOn(global.console, 'log').mockReturnValue(undefined);
jest.spyOn<any, any>(global, 'Date').mockImplementation(() => timestamp);
service = new LoggingService();
});
afterEach(() => {
mockConsoleLog.mockClear();
jest.restoreAllMocks();
mockCreateWriteStream.mockClear();
mockStreamWrite.mockClear();
});

View file

@ -40,23 +40,18 @@ import { logger } from '../logging/__mocks__';
const env = new Env('.', getEnvOptions());
const config$ = new BehaviorSubject({} as Config);
const mockProcessExit = jest.spyOn(global.process, 'exit').mockImplementation(() => {
// noop
});
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {
// noop
});
let mockConsoleError: jest.SpyInstance;
beforeEach(() => {
jest.spyOn(global.process, 'exit').mockReturnValue(undefined as never);
mockConsoleError = jest.spyOn(console, 'error').mockReturnValue(undefined);
mockLoggingService.asLoggerFactory.mockReturnValue(logger);
mockConfigService.getConfig$.mockReturnValue(new BehaviorSubject({}));
mockConfigService.atPath.mockReturnValue(new BehaviorSubject({ someValue: 'foo' }));
});
afterEach(() => {
mockProcessExit.mockReset();
mockConsoleError.mockReset();
jest.restoreAllMocks();
mockLoggingService.upgrade.mockReset();
mockLoggingService.stop.mockReset();
@ -178,7 +173,7 @@ test('fails and stops services if initial logger upgrade fails', async () => {
test('stops services if consequent logger upgrade fails', async () => {
const onShutdown = new BehaviorSubject<string | null>(null);
const mockOnShutdown = jest.fn(() => {
const mockOnShutdown = jest.fn<any, any>(() => {
onShutdown.next('completed');
onShutdown.complete();
});

View file

@ -64,7 +64,9 @@ export function execInProjects(
for (const e of error.errors) {
if (e instanceof ProjectFailure) {
log.write('');
log.error(`${e.project.name} failed\n${e.error.stdout}`);
// stdout contains errors from tsc
// stderr conatins tsc crash report
log.error(`${e.project.name} failed\n${e.error.stdout || e.error.stderr}`);
} else {
log.error(e);
}

View file

@ -20,7 +20,7 @@ exports[`SourceFiltersTable should add a filter 1`] = `
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],
@ -114,7 +114,7 @@ exports[`SourceFiltersTable should remove a filter 1`] = `
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],
@ -319,7 +319,7 @@ exports[`SourceFiltersTable should update a filter 1`] = `
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
"value": undefined,
},
],

View file

@ -17,7 +17,10 @@
* under the License.
*/
import { SavedObject } from '../../../../../server/saved_objects/service/saved_objects_client';
import {
SavedObject,
SavedObjectsClient,
} from '../../../../../server/saved_objects/service/saved_objects_client';
import { collectReferencesDeep } from './collect_references_deep';
const data = [
@ -100,7 +103,7 @@ const data = [
];
test('collects dashboard and all dependencies', async () => {
const savedObjectClient = {
const savedObjectClient = ({
errors: {} as any,
create: jest.fn(),
bulkCreate: jest.fn(),
@ -115,7 +118,7 @@ test('collects dashboard and all dependencies', async () => {
),
};
}),
};
} as unknown) as SavedObjectsClient;
const objects = await collectReferencesDeep(savedObjectClient, [{ type: 'dashboard', id: '1' }]);
expect(objects).toMatchInlineSnapshot(`
Array [

View file

@ -32,7 +32,7 @@ describe('ElasticIndex', () => {
return { status: 404 };
});
const info = await Index.fetchInfo(callCluster, '.kibana-test');
const info = await Index.fetchInfo(callCluster as any, '.kibana-test');
expect(info).toEqual({
aliases: {},
exists: false,
@ -51,7 +51,7 @@ describe('ElasticIndex', () => {
};
});
await expect(Index.fetchInfo(callCluster, '.baz')).rejects.toThrow(
await expect(Index.fetchInfo(callCluster as any, '.baz')).rejects.toThrow(
/cannot be automatically migrated/
);
});
@ -105,7 +105,7 @@ describe('ElasticIndex', () => {
expect(index).toEqual('.abcd');
});
await Index.createIndex(callCluster, '.abcd', { foo: 'bar' } as any);
await Index.createIndex(callCluster as any, '.abcd', { foo: 'bar' } as any);
expect(callCluster).toHaveBeenCalled();
});
});
@ -117,7 +117,7 @@ describe('ElasticIndex', () => {
expect(index).toEqual('.lotr');
});
await Index.deleteIndex(callCluster, '.lotr');
await Index.deleteIndex(callCluster as any, '.lotr');
expect(callCluster).toHaveBeenCalled();
});
});
@ -151,7 +151,7 @@ describe('ElasticIndex', () => {
}
});
await Index.claimAlias(callCluster, '.hola-42', '.hola');
await Index.claimAlias(callCluster as any, '.hola-42', '.hola');
assertCalled(callCluster);
});
@ -177,7 +177,7 @@ describe('ElasticIndex', () => {
}
});
await Index.claimAlias(callCluster, '.ze-index', '.muchacha');
await Index.claimAlias(callCluster as any, '.ze-index', '.muchacha');
assertCalled(callCluster);
});
@ -204,7 +204,7 @@ describe('ElasticIndex', () => {
}
});
await Index.claimAlias(callCluster, '.ze-index', '.muchacha', [
await Index.claimAlias(callCluster as any, '.ze-index', '.muchacha', [
{ remove_index: { index: 'awww-snap!' } },
]);
@ -267,7 +267,7 @@ describe('ElasticIndex', () => {
properties: { foo: 'bar' },
},
};
await Index.convertToAlias(callCluster, info, '.muchacha', 10);
await Index.convertToAlias(callCluster as any, info, '.muchacha', 10);
expect(callCluster.mock.calls.map(([path]) => path)).toEqual([
'indices.create',
@ -326,7 +326,7 @@ describe('ElasticIndex', () => {
properties: { foo: 'bar' },
},
};
await expect(Index.convertToAlias(callCluster, info, '.muchacha', 10)).rejects.toThrow(
await expect(Index.convertToAlias(callCluster as any, info, '.muchacha', 10)).rejects.toThrow(
/Re-index failed \[search_phase_execution_exception\] all shards failed/
);
@ -390,7 +390,7 @@ describe('ElasticIndex', () => {
},
];
await expect(Index.write(callCluster, index, docs)).rejects.toThrow(/dern/);
await expect(Index.write(callCluster as any, index, docs)).rejects.toThrow(/dern/);
expect(callCluster).toHaveBeenCalled();
});
});
@ -551,7 +551,7 @@ describe('ElasticIndex', () => {
}
throw new Error(`Unknown command ${path}.`);
});
const hasMigrations = await Index.migrationsUpToDate(callCluster, index, migrations);
const hasMigrations = await Index.migrationsUpToDate(callCluster as any, index, migrations);
return { hasMigrations, callCluster };
}

View file

@ -24,7 +24,7 @@ import { migrateRawDocs } from './migrate_raw_docs';
describe('migrateRawDocs', () => {
test('converts raw docs to saved objects', async () => {
const transform = jest.fn((doc: any) => _.set(doc, 'attributes.name', 'HOI!'));
const transform = jest.fn<any, any>((doc: any) => _.set(doc, 'attributes.name', 'HOI!'));
const result = migrateRawDocs(new SavedObjectsSerializer(new SavedObjectsSchema()), transform, [
{ _id: 'a:b', _source: { type: 'a', a: { name: 'AAA' } } },
{ _id: 'c:d', _source: { type: 'c', c: { name: 'DDD' } } },
@ -45,7 +45,9 @@ describe('migrateRawDocs', () => {
});
test('passes invalid docs through untouched', async () => {
const transform = jest.fn((doc: any) => _.set(_.cloneDeep(doc), 'attributes.name', 'TADA'));
const transform = jest.fn<any, any>((doc: any) =>
_.set(_.cloneDeep(doc), 'attributes.name', 'TADA')
);
const result = migrateRawDocs(new SavedObjectsSerializer(new SavedObjectsSchema()), transform, [
{ _id: 'foo:b', _source: { type: 'a', a: { name: 'AAA' } } },
{ _id: 'c:d', _source: { type: 'c', c: { name: 'DDD' } } },

View file

@ -51,7 +51,7 @@ describe('coordinateMigration', () => {
test('does not poll if the runMigration succeeds', async () => {
const pollInterval = 1;
const runMigration = jest.fn(() => Promise.resolve());
const runMigration = jest.fn<any, any>(() => Promise.resolve());
const isMigrated = jest.fn(() => Promise.resolve(true));
await coordinateMigration({

View file

@ -66,7 +66,7 @@ describe('KibanaMigrator', () => {
it('waits for kbnServer.ready and elasticsearch.ready before attempting migrations', async () => {
const { kbnServer } = mockKbnServer();
const clusterStub = jest.fn(() => {
const clusterStub = jest.fn<any, any>(() => {
throw new Error('Doh!');
});
const waitUntilReady = jest.fn(async () => undefined);

View file

@ -42,43 +42,22 @@ describe('#getInjected()', () => {
chrome.getInjected();
chrome.getInjected('foo');
chrome.getInjected('foo', 'bar');
expect(newPlatformInjectedMetadata).toMatchInlineSnapshot(`
Object {
"getInjectedVar": [MockFunction] {
"calls": Array [
Array [
"foo",
undefined,
],
Array [
"foo",
"bar",
],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
Object {
"isThrow": false,
"value": undefined,
},
],
},
"getInjectedVars": [MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
},
}
expect(newPlatformInjectedMetadata.getInjectedVars.mock.calls).toMatchInlineSnapshot(`
Array [
Array [],
]
`);
expect(newPlatformInjectedMetadata.getInjectedVar.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"foo",
undefined,
],
Array [
"foo",
"bar",
],
]
`);
});

View file

@ -43,7 +43,7 @@ it('subscribes to the passed observable, returns subscription', () => {
const $scope = new Scope();
const unsubSpy = jest.fn();
const subSpy = jest.fn(() => unsubSpy);
const subSpy = jest.fn<any, any>(() => unsubSpy);
const observable = new Rx.Observable(subSpy);
const subscription = subscribeWithScope($scope as any, observable);

View file

@ -41,7 +41,7 @@ describe('EditorConfigProvider', () => {
});
it('should call registered providers with given parameters', () => {
const provider = jest.fn(() => ({}));
const provider = jest.fn<any, any>(() => ({}));
registry.register(provider);
expect(provider).not.toHaveBeenCalled();
const aggType = {};
@ -51,8 +51,8 @@ describe('EditorConfigProvider', () => {
});
it('should call all registered providers with given parameters', () => {
const provider = jest.fn(() => ({}));
const provider2 = jest.fn(() => ({}));
const provider = jest.fn<any, any>(() => ({}));
const provider2 = jest.fn<any, any>(() => ({}));
registry.register(provider);
registry.register(provider2);
expect(provider).not.toHaveBeenCalled();

View file

@ -55,20 +55,12 @@ describe('concatStreamProviders() helper', () => {
await expect(createPromiseFromStreams([dest])).rejects.toThrowErrorMatchingInlineSnapshot(
`"foo"`
);
expect(errorListener).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
[Error: foo],
],
expect(errorListener.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[Error: foo],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
}
]
`);
});
});

View file

@ -39,8 +39,9 @@
"@types/expect.js": "^0.3.29",
"@types/graphql": "^0.13.1",
"@types/history": "^4.6.2",
"@types/jest": "^23.3.1",
"@types/jest": "^24.0.9",
"@types/joi": "^13.4.2",
"@types/json-stable-stringify": "^1.0.32",
"@types/jsonwebtoken": "^7.2.7",
"@types/lodash": "^3.10.1",
"@types/mocha": "^5.2.6",
@ -85,8 +86,8 @@
"gulp-mocha": "2.2.0",
"gulp-multi-process": "^1.3.1",
"hapi": "^17.5.3",
"jest": "^23.6.0",
"jest-cli": "^23.6.0",
"jest": "^24.1.0",
"jest-cli": "^24.1.0",
"jest-styled-components": "^6.2.2",
"jsdom": "^12.0.0",
"mocha": "3.3.0",
@ -129,7 +130,6 @@
"@scant/router": "^0.1.0",
"@slack/client": "^4.8.0",
"@turf/boolean-contains": "6.0.1",
"@types/json-stable-stringify": "^1.0.32",
"angular-resource": "1.4.9",
"angular-sanitize": "1.6.5",
"angular-ui-ace": "0.2.3",

View file

@ -22,7 +22,7 @@ describe('createErrorGroupWatch', () => {
let tmpl: any;
beforeEach(async () => {
chrome.getInjected = jest.fn().mockReturnValue('myIndexPattern');
jest.spyOn(uuid, 'v4').mockReturnValue('mocked-uuid');
jest.spyOn(uuid, 'v4').mockReturnValue(new Buffer('mocked-uuid'));
jest.spyOn(rest, 'createWatch').mockReturnValue(undefined);
createWatchResponse = await createErrorGroupWatch({

View file

@ -132,7 +132,7 @@ describe('PropertiesTable', () => {
it('should render null empty string when no docs are returned', () => {
jest
.spyOn(agentDocs, 'getAgentFeatureDocsUrl')
.mockImplementation(() => null);
.mockImplementation(() => undefined);
expect(
shallow(

View file

@ -17,7 +17,7 @@ describe('transactionGroupsFetcher', () => {
end: 1528977600000,
client: clientSpy,
config: {
get: jest.fn((key: string) => {
get: jest.fn<any, string[]>((key: string) => {
switch (key) {
case 'apm_oss.transactionIndices':
return 'myIndex';

View file

@ -81,21 +81,13 @@ Object {
"id": "123",
}
`);
expect(savedObjectsClient.get).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
"123",
],
expect(savedObjectsClient.get.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
"123",
],
"results": Array [
Object {
"isThrow": false,
"value": Promise {},
},
],
}
]
`);
});
});
@ -121,28 +113,20 @@ Object {
"ok": true,
}
`);
expect(savedObjectsClient.create).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
Object {
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"foo": true,
},
Object {
"id": "workpad-123abc",
},
],
],
"results": Array [
expect(savedObjectsClient.create.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
Object {
"isThrow": false,
"value": Promise {},
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"foo": true,
},
Object {
"id": "workpad-123abc",
},
],
}
]
`);
});
@ -167,28 +151,20 @@ Object {
"ok": true,
}
`);
expect(savedObjectsClient.create).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
Object {
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"foo": true,
},
Object {
"id": "123",
},
],
],
"results": Array [
expect(savedObjectsClient.create.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
Object {
"isThrow": false,
"value": Promise {},
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"foo": true,
},
Object {
"id": "123",
},
],
}
]
`);
});
});
@ -220,45 +196,29 @@ Object {
"ok": true,
}
`);
expect(savedObjectsClient.get).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
"123",
],
expect(savedObjectsClient.get.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
"123",
],
"results": Array [
Object {
"isThrow": false,
"value": Promise {},
},
],
}
]
`);
expect(savedObjectsClient.create).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
Object {
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"foo": true,
},
Object {
"id": "123",
"overwrite": true,
},
],
],
"results": Array [
expect(savedObjectsClient.create.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
Object {
"isThrow": false,
"value": Promise {},
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"foo": true,
},
Object {
"id": "123",
"overwrite": true,
},
],
}
]
`);
});
});
@ -281,21 +241,13 @@ Object {
"ok": true,
}
`);
expect(savedObjectsClient.delete).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
"123",
],
expect(savedObjectsClient.delete.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
"123",
],
"results": Array [
Object {
"isThrow": false,
"value": Promise {},
},
],
}
]
`);
});
});
@ -331,36 +283,28 @@ Object {
],
}
`);
expect(savedObjectsClient.find).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
Object {
"fields": Array [
"id",
"name",
"@created",
"@timestamp",
],
"page": "2",
"perPage": "10",
"search": "abc* | abc",
"searchFields": Array [
"name",
],
"sortField": "@timestamp",
"sortOrder": "desc",
"type": "canvas-workpad",
},
],
],
"results": Array [
expect(savedObjectsClient.find.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"isThrow": false,
"value": Promise {},
"fields": Array [
"id",
"name",
"@created",
"@timestamp",
],
"page": "2",
"perPage": "10",
"search": "abc* | abc",
"searchFields": Array [
"name",
],
"sortField": "@timestamp",
"sortOrder": "desc",
"type": "canvas-workpad",
},
],
}
]
`);
});
@ -403,59 +347,43 @@ Object {
"ok": true,
}
`);
expect(savedObjectsClient.get).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
"123",
],
expect(savedObjectsClient.get.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
"123",
],
"results": Array [
Object {
"isThrow": false,
"value": Promise {},
},
],
}
]
`);
expect(savedObjectsClient.create).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
Object {
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"assets": Object {
"asset-123": Object {
"@created": "2019-02-14T00:00:00.000Z",
"id": "asset-123",
"type": "dataurl",
"value": "mockbase64data",
},
"asset-456": Object {
"@created": "2019-02-15T00:00:00.000Z",
"id": "asset-456",
"type": "dataurl",
"value": "mockbase64data",
},
},
"name": "fake workpad",
},
Object {
"id": "123",
"overwrite": true,
},
],
],
"results": Array [
expect(savedObjectsClient.create.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
Object {
"isThrow": false,
"value": Promise {},
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"assets": Object {
"asset-123": Object {
"@created": "2019-02-14T00:00:00.000Z",
"id": "asset-123",
"type": "dataurl",
"value": "mockbase64data",
},
"asset-456": Object {
"@created": "2019-02-15T00:00:00.000Z",
"id": "asset-456",
"type": "dataurl",
"value": "mockbase64data",
},
},
"name": "fake workpad",
},
Object {
"id": "123",
"overwrite": true,
},
],
}
]
`);
});
});
@ -497,54 +425,38 @@ Object {
"ok": true,
}
`);
expect(savedObjectsClient.get).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
"123",
],
expect(savedObjectsClient.get.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
"123",
],
"results": Array [
Object {
"isThrow": false,
"value": Promise {},
},
],
}
]
`);
expect(savedObjectsClient.create).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"canvas-workpad",
Object {
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"assets": Object {
"asset-123": Object {
"@created": "2019-02-14T00:00:00.000Z",
"id": "asset-123",
"type": "dataurl",
"value": "mockbase64data",
},
},
"css": ".canvasPage { color: LavenderBlush; }",
"name": "renamed workpad",
},
Object {
"id": "123",
"overwrite": true,
},
],
],
"results": Array [
expect(savedObjectsClient.create.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"canvas-workpad",
Object {
"isThrow": false,
"value": Promise {},
"@created": "2019-02-12T21:01:22.479Z",
"@timestamp": "2019-02-12T21:01:22.479Z",
"assets": Object {
"asset-123": Object {
"@created": "2019-02-14T00:00:00.000Z",
"id": "asset-123",
"type": "dataurl",
"value": "mockbase64data",
},
},
"css": ".canvasPage { color: LavenderBlush; }",
"name": "renamed workpad",
},
Object {
"id": "123",
"overwrite": true,
},
],
}
]
`);
});
});

View file

@ -85,7 +85,7 @@ export function createTestHandler(initApiFn: (server: any, preCheckLicenseImpl:
get: (key: string) => config[key],
};
server.decorate('server', 'config', jest.fn(() => mockConfig));
server.decorate('server', 'config', jest.fn<any, any>(() => mockConfig));
initApiFn(server, pre);

View file

@ -6,7 +6,7 @@
import Boom from 'boom';
import moment from 'moment';
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
import {
IndexGroup,
REINDEX_OP_TYPE,
@ -22,7 +22,7 @@ import { LOCK_WINDOW, ReindexActions, reindexActionsFactory } from './reindex_ac
describe('ReindexActions', () => {
let client: jest.Mocked<any>;
let callCluster: jest.Mock<CallCluster>;
let callCluster: jest.Mock;
let actions: ReindexActions;
const unimplemented = (name: string) => () =>

View file

@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
import {
CURRENT_MAJOR_VERSION,
PREV_MAJOR_VERSION,
@ -27,7 +26,7 @@ import {
describe('reindexService', () => {
let actions: jest.Mocked<any>;
let callCluster: jest.Mock<CallCluster>;
let callCluster: jest.Mock;
let xpackInfo: { feature: jest.Mocked<any> };
let service: ReindexService;
@ -65,7 +64,8 @@ describe('reindexService', () => {
},
})),
};
service = reindexServiceFactory(callCluster, xpackInfo as any, actions, ['apm-*']);
service = reindexServiceFactory(callCluster as any, xpackInfo as any, actions, ['apm-*']);
});
describe('hasRequiredPrivileges', () => {
@ -305,7 +305,7 @@ describe('reindexService', () => {
const findSpy = jest.spyOn(service, 'findReindexOperation').mockResolvedValueOnce({
id: '2',
attributes: { indexName: 'myIndex', status: ReindexStatus.inProgress },
});
} as any);
await service.pauseReindexOperation('myIndex');
@ -357,7 +357,7 @@ describe('reindexService', () => {
const findSpy = jest.spyOn(service, 'findReindexOperation').mockResolvedValueOnce({
id: '2',
attributes: { indexName: 'myIndex', status: ReindexStatus.paused },
});
} as any);
await service.resumeReindexOperation('myIndex');
@ -414,7 +414,7 @@ describe('reindexService', () => {
lastCompletedStep: ReindexStep.reindexStarted,
reindexTaskId: '999333',
},
});
} as any);
callCluster.mockResolvedValueOnce(true);
await service.cancelReindexing('myIndex');

874
yarn.lock

File diff suppressed because it is too large Load diff