|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +// tslint:disable:no-require-imports no-var-requires |
| 7 | +import { assert } from 'chai'; |
| 8 | +import * as path from 'path'; |
| 9 | +import * as sinon from 'sinon'; |
| 10 | +import * as vscode from 'vscode'; |
| 11 | +import { ICommandManager, IVSCodeNotebook } from '../../../client/common/application/types'; |
| 12 | +import { Commands } from '../../../client/common/constants'; |
| 13 | +import { IDisposable } from '../../../client/common/types'; |
| 14 | +import { INotebookEditorProvider } from '../../../client/datascience/types'; |
| 15 | +import { IExtensionTestApi } from '../../common'; |
| 16 | +import { EXTENSION_ROOT_DIR_FOR_TESTS, initialize } from '../../initialize'; |
| 17 | +import { |
| 18 | + canRunTests, |
| 19 | + closeNotebooksAndCleanUpAfterTests, |
| 20 | + createTemporaryNotebook, |
| 21 | + setLinterToPylint, |
| 22 | + trustAllNotebooks |
| 23 | +} from './helper'; |
| 24 | +// tslint:disable-next-line: no-var-requires no-require-imports |
| 25 | + |
| 26 | +// tslint:disable: no-any no-invalid-this |
| 27 | +suite('DataScience - VSCode Notebook - (linting)', function () { |
| 28 | + this.timeout(15_000); |
| 29 | + const templateIPynb = path.join( |
| 30 | + EXTENSION_ROOT_DIR_FOR_TESTS, |
| 31 | + 'src', |
| 32 | + 'test', |
| 33 | + 'datascience', |
| 34 | + 'notebook', |
| 35 | + 'linterTest.ipynb' |
| 36 | + ); |
| 37 | + let api: IExtensionTestApi; |
| 38 | + const disposables: IDisposable[] = []; |
| 39 | + suiteSetup(async function () { |
| 40 | + this.timeout(15_000); |
| 41 | + api = await initialize(); |
| 42 | + if (!(await canRunTests())) { |
| 43 | + return this.skip(); |
| 44 | + } |
| 45 | + }); |
| 46 | + setup(async () => { |
| 47 | + await trustAllNotebooks(); |
| 48 | + sinon.restore(); |
| 49 | + }); |
| 50 | + teardown(async () => closeNotebooksAndCleanUpAfterTests(disposables)); |
| 51 | + suiteTeardown(closeNotebooksAndCleanUpAfterTests); |
| 52 | + |
| 53 | + test('Linter runs on file', async () => { |
| 54 | + await setLinterToPylint(false); |
| 55 | + const editorProvider = api.serviceContainer.get<INotebookEditorProvider>(INotebookEditorProvider); |
| 56 | + await editorProvider.open(vscode.Uri.file(templateIPynb)); |
| 57 | + |
| 58 | + const document = api.serviceContainer.get<IVSCodeNotebook>(IVSCodeNotebook).activeNotebookEditor!.document; |
| 59 | + |
| 60 | + // Wait for the linter to run |
| 61 | + await api.serviceContainer.get<ICommandManager>(ICommandManager).executeCommand(Commands.Run_Linter); |
| 62 | + |
| 63 | + // Each cell should have its own list of linting errors |
| 64 | + const cell1 = document.cells[0]; |
| 65 | + let diagnostics = vscode.languages.getDiagnostics(cell1.document.uri); |
| 66 | + assert.equal(diagnostics.length, 4, 'No linting on first cell'); |
| 67 | + const cell2 = document.cells[1]; |
| 68 | + diagnostics = vscode.languages.getDiagnostics(cell2.document.uri); |
| 69 | + assert.equal(diagnostics.length, 3, 'No linting on second cell'); |
| 70 | + }); |
| 71 | +}); |
0 commit comments