Skip to content

Commit

Permalink
Fix jest tests for np migration
Browse files Browse the repository at this point in the history
  • Loading branch information
joelgriffith committed Jun 2, 2020
1 parent 1ba7ddd commit f8269ae
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 71 deletions.
10 changes: 7 additions & 3 deletions x-pack/plugins/reporting/server/config/create_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ const makeMockCoreSetup = (serverInfo: KibanaServer): CoreSetup =>
describe('Reporting server createConfig$', () => {
let mockCoreSetup: CoreSetup;
let mockInitContext: PluginInitializerContext;
let mockConfig$: any;
let mockLogger: LevelLogger;

beforeEach(() => {
mockCoreSetup = makeMockCoreSetup({ host: 'kibanaHost', port: 5601, protocol: 'http' });
mockInitContext = makeMockInitContext({
kibanaServer: {},
});
mockConfig$ = mockInitContext.config.create();
mockLogger = ({ warn: jest.fn(), debug: jest.fn() } as unknown) as LevelLogger;
});

Expand All @@ -55,6 +53,7 @@ describe('Reporting server createConfig$', () => {
});

it('creates random encryption key and default config using host, protocol, and port from server info', async () => {
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.encryptionKey).toMatch(/\S{32,}/); // random 32 characters
Expand All @@ -76,8 +75,8 @@ describe('Reporting server createConfig$', () => {
encryptionKey: 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii',
kibanaServer: {},
});
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.encryptionKey).toMatch('iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii');
expect((mockLogger.warn as any).mock.calls.length).toBe(0);
});
Expand All @@ -91,6 +90,7 @@ describe('Reporting server createConfig$', () => {
protocol: 'httpsa',
},
});
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -118,6 +118,7 @@ describe('Reporting server createConfig$', () => {
encryptionKey: 'aaaaaaaaaaaaabbbbbbbbbbbbaaaaaaaaa',
kibanaServer: { hostname: '0' },
});
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.kibanaServer).toMatchInlineSnapshot(`
Expand All @@ -139,6 +140,7 @@ describe('Reporting server createConfig$', () => {
encryptionKey: '888888888888888888888888888888888',
capture: { browser: { chromium: { disableSandbox: false } } },
} as ReportingConfigType);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: false });
Expand All @@ -150,6 +152,7 @@ describe('Reporting server createConfig$', () => {
encryptionKey: '888888888888888888888888888888888',
capture: { browser: { chromium: { disableSandbox: true } } },
} as ReportingConfigType);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: true });
Expand All @@ -160,6 +163,7 @@ describe('Reporting server createConfig$', () => {
mockInitContext = makeMockInitContext({
encryptionKey: '888888888888888888888888888888888',
} as ReportingConfigType);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: expect.any(Boolean) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('../../../../server/browsers/chromium/puppeteer', () => ({
jest.mock('../../../../../server/browsers/chromium/puppeteer', () => ({
puppeteerLaunch: () => ({
// Fixme needs event emitters
newPage: () => ({
Expand Down
Loading

0 comments on commit f8269ae

Please sign in to comment.