|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +'use strict'; |
| 4 | +import * as typemoq from 'typemoq'; |
| 5 | +import { IApplicationShell } from '../../client/common/application/types'; |
| 6 | +import { IInstallationChannelManager, IModuleInstaller } from '../../client/common/installer/types'; |
| 7 | +import { ILogger } from '../../client/common/types'; |
| 8 | +import * as localize from '../../client/common/utils/localize'; |
| 9 | +import { DataScienceErrorHandler } from '../../client/datascience/errorHandler/errorHandler'; |
| 10 | +import { JupyterInstallError } from '../../client/datascience/jupyter/jupyterInstallError'; |
| 11 | +import { JupyterSelfCertsError } from '../../client/datascience/jupyter/jupyterSelfCertsError'; |
| 12 | + |
| 13 | +suite('DataScience Error Handler Unit Tests', () => { |
| 14 | + let applicationShell: typemoq.IMock<IApplicationShell>; |
| 15 | + let logger: typemoq.IMock<ILogger>; |
| 16 | + let channels: typemoq.IMock<IInstallationChannelManager>; |
| 17 | + let dataScienceErrorHandler: DataScienceErrorHandler; |
| 18 | + |
| 19 | + setup(() => { |
| 20 | + applicationShell = typemoq.Mock.ofType<IApplicationShell>(); |
| 21 | + logger = typemoq.Mock.ofType<ILogger>(); |
| 22 | + channels = typemoq.Mock.ofType<IInstallationChannelManager>(); |
| 23 | + |
| 24 | + dataScienceErrorHandler = new DataScienceErrorHandler(applicationShell.object, logger.object, channels.object); |
| 25 | + }); |
| 26 | + const message = 'Test error message.'; |
| 27 | + |
| 28 | + test('Default error', async () => { |
| 29 | + applicationShell.setup(app => app.showErrorMessage(typemoq.It.isAny())) |
| 30 | + .returns(() => Promise.resolve(message)) |
| 31 | + .verifiable(typemoq.Times.once()); |
| 32 | + |
| 33 | + logger.setup(log => log.logError(typemoq.It.isAny())) |
| 34 | + .verifiable(typemoq.Times.once()); |
| 35 | + |
| 36 | + const err = new Error(message); |
| 37 | + await dataScienceErrorHandler.handleError(err); |
| 38 | + |
| 39 | + applicationShell.verifyAll(); |
| 40 | + logger.verifyAll(); |
| 41 | + }); |
| 42 | + |
| 43 | + test('Jupyter Self Certificates Error', async () => { |
| 44 | + logger.setup(log => log.logError(typemoq.It.isAny())) |
| 45 | + .verifiable(typemoq.Times.once()); |
| 46 | + |
| 47 | + const err = new JupyterSelfCertsError(message); |
| 48 | + await dataScienceErrorHandler.handleError(err); |
| 49 | + |
| 50 | + logger.verifyAll(); |
| 51 | + }); |
| 52 | + |
| 53 | + test('Jupyter Install Error', async () => { |
| 54 | + applicationShell.setup(app => app.showInformationMessage(typemoq.It.isAny(), |
| 55 | + typemoq.It.isValue(localize.DataScience.jupyterInstall()), |
| 56 | + typemoq.It.isValue(localize.DataScience.notebookCheckForImportNo()))) |
| 57 | + .returns(() => Promise.resolve(localize.DataScience.jupyterInstall())) |
| 58 | + .verifiable(typemoq.Times.once()); |
| 59 | + |
| 60 | + logger.setup(log => log.logError(typemoq.It.isAny())) |
| 61 | + .verifiable(typemoq.Times.once()); |
| 62 | + |
| 63 | + const installers: IModuleInstaller[] = [ |
| 64 | + { |
| 65 | + name: 'Pip', |
| 66 | + displayName: 'Pip', |
| 67 | + priority: 0, |
| 68 | + isSupported: () => Promise.resolve(true), |
| 69 | + installModule: () => Promise.resolve() |
| 70 | + }, |
| 71 | + { |
| 72 | + name: 'Conda', |
| 73 | + displayName: 'Conda', |
| 74 | + priority: 0, |
| 75 | + isSupported: () => Promise.resolve(true), |
| 76 | + installModule: () => Promise.resolve() |
| 77 | + } |
| 78 | + ]; |
| 79 | + |
| 80 | + channels.setup(ch => ch.getInstallationChannels()) |
| 81 | + .returns(() => Promise.resolve(installers)) |
| 82 | + .verifiable(typemoq.Times.once()); |
| 83 | + |
| 84 | + const err = new JupyterInstallError(message, 'test.com'); |
| 85 | + await dataScienceErrorHandler.handleError(err); |
| 86 | + |
| 87 | + applicationShell.verifyAll(); |
| 88 | + logger.verifyAll(); |
| 89 | + channels.verifyAll(); |
| 90 | + }); |
| 91 | +}); |
0 commit comments