-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reporting] fix unsupported platform crash (#120659)
* [Reporting] fix unsupported platform crash * revert test code * improve types and add test * Apply suggestions from code review Co-authored-by: Michael Dokolin <[email protected]> * updates per feedback - remove the error class member * add stack trace of error * revert change to guard a type Co-authored-by: Michael Dokolin <[email protected]>
- Loading branch information
Showing
2 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
jest.mock('./browsers/install'); | ||
|
||
import type { CoreSetup, CoreStart, PluginInitializerContext } from 'kibana/server'; | ||
import { coreMock } from 'src/core/server/mocks'; | ||
import type { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/server'; | ||
import { install } from './browsers/install'; | ||
import { ScreenshottingPlugin } from './plugin'; | ||
|
||
describe('ScreenshottingPlugin', () => { | ||
let initContext: PluginInitializerContext; | ||
let coreSetup: CoreSetup; | ||
let coreStart: CoreStart; | ||
let setupDeps: Parameters<ScreenshottingPlugin['setup']>[1]; | ||
let plugin: ScreenshottingPlugin; | ||
|
||
beforeEach(() => { | ||
const configSchema = { | ||
browser: { chromium: { disableSandbox: false } }, | ||
}; | ||
initContext = coreMock.createPluginInitializerContext(configSchema); | ||
coreSetup = coreMock.createSetup({}); | ||
coreStart = coreMock.createStart(); | ||
setupDeps = { | ||
screenshotMode: {} as ScreenshotModePluginSetup, | ||
}; | ||
plugin = new ScreenshottingPlugin(initContext); | ||
}); | ||
|
||
describe('setup', () => { | ||
test('returns a setup contract', async () => { | ||
const setupContract = plugin.setup(coreSetup, setupDeps); | ||
expect(setupContract).toEqual({}); | ||
}); | ||
|
||
test('handles setup issues', async () => { | ||
(install as jest.Mock).mockRejectedValue(`Unsupported platform!!!`); | ||
|
||
const setupContract = plugin.setup(coreSetup, setupDeps); | ||
expect(setupContract).toEqual({}); | ||
|
||
await coreSetup.getStartServices(); | ||
|
||
const startContract = plugin.start(coreStart); | ||
expect(startContract).toEqual( | ||
expect.objectContaining({ | ||
diagnose: expect.any(Function), | ||
getScreenshots: expect.any(Function), | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('start', () => { | ||
beforeEach(async () => { | ||
plugin.setup(coreSetup, setupDeps); | ||
await coreSetup.getStartServices(); | ||
}); | ||
|
||
test('returns a start contract', async () => { | ||
const startContract = plugin.start(coreStart); | ||
expect(startContract).toEqual( | ||
expect.objectContaining({ | ||
diagnose: expect.any(Function), | ||
getScreenshots: expect.any(Function), | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters