Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jun 18, 2020
1 parent ade60f1 commit b552cfc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { LevelLogger } from '../lib';

export function createMockLevelLogger() {
// eslint-disable-next-line no-console
const consoleLogger = (tag: string) => (message: unknown) => console.log(tag, message);
const innerLogger = {
get: () => innerLogger,
debug: consoleLogger('debug'),
info: consoleLogger('info'),
warn: consoleLogger('warn'),
trace: consoleLogger('trace'),
error: consoleLogger('error'),
fatal: consoleLogger('fatal'),
log: consoleLogger('log'),
};
return new LevelLogger(innerLogger);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
} from '../browsers';
import { ReportingInternalSetup, ReportingInternalStart } from '../core';
import { ReportingStartDeps } from '../types';
import { ReportingStore, LevelLogger } from '../lib';
import { ReportingStore } from '../lib';
import { createMockLevelLogger } from './create_mock_levellogger';

(initializeBrowserDriverFactory as jest.Mock<
Promise<HeadlessChromiumDriverFactory>
Expand All @@ -38,8 +39,12 @@ const createMockPluginSetup = (setupMock?: any): ReportingInternalSetup => {
};
};

const createMockPluginStart = (startMock?: any): ReportingInternalStart => {
const store = new ReportingStore({} as ReportingCore, {} as LevelLogger);
const createMockPluginStart = (
mockReportingCore: ReportingCore,
startMock?: any
): ReportingInternalStart => {
const logger = createMockLevelLogger();
const store = new ReportingStore(mockReportingCore, logger);
return {
browserDriverFactory: startMock.browserDriverFactory,
enqueueJob: startMock.enqueueJob,
Expand All @@ -63,9 +68,22 @@ export const createMockStartDeps = (startMock?: any): ReportingStartDeps => ({

export const createMockReportingCore = async (
config: ReportingConfig,
setupDepsMock: ReportingInternalSetup | undefined = createMockPluginSetup({}),
startDepsMock: ReportingInternalStart | undefined = createMockPluginStart({})
setupDepsMock: ReportingInternalSetup | undefined = undefined,
startDepsMock: ReportingInternalStart | undefined = undefined
) => {
if (!setupDepsMock) {
setupDepsMock = createMockPluginSetup({});
}

const mockReportingCore = {
getConfig: () => config,
getElasticsearchService: () => setupDepsMock?.elasticsearch,
} as ReportingCore;

if (!startDepsMock) {
startDepsMock = createMockPluginStart(mockReportingCore, {});
}

config = config || {};
const core = new ReportingCore();

Expand Down

0 comments on commit b552cfc

Please sign in to comment.