|  | 
| 6 | 6 | // tslint:disable:max-func-body-length no-invalid-this no-any | 
| 7 | 7 | 
 | 
| 8 | 8 | import * as assert from 'assert'; | 
|  | 9 | +import { expect } from 'chai'; | 
| 9 | 10 | import * as fs from 'fs-extra'; | 
| 10 | 11 | import * as glob from 'glob'; | 
| 11 | 12 | import * as path from 'path'; | 
| 12 | 13 | import * as vscode from 'vscode'; | 
|  | 14 | +import { waitForCondition } from '../common'; | 
| 13 | 15 | import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST, SMOKE_TEST_EXTENSIONS_DIR } from '../constants'; | 
| 14 |  | -import { isWindows, noop } from '../core'; | 
|  | 16 | +import { noop, sleep } from '../core'; | 
| 15 | 17 | import { closeActiveWindows, initialize, initializeTest } from '../initialize'; | 
| 16 | 18 | 
 | 
| 17 |  | -const decoratorsPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'pythonFiles', 'definition', 'navigation'); | 
| 18 |  | -const fileDefinitions = path.join(decoratorsPath, 'definitions.py'); | 
| 19 |  | -const wksPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'pythonFiles', 'exclusions'); | 
| 20 |  | -const fileOne = path.join(wksPath, 'one.py'); | 
|  | 19 | +const fileDefinitions = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'definitions.py'); | 
| 21 | 20 | 
 | 
| 22 | 21 | suite('Smoke Test: Language Server', function () { | 
| 23 | 22 |  // Large value to allow for LS to get downloaded. | 
| @@ -79,54 +78,29 @@ suite('Smoke Test: Language Server', function () { | 
| 79 | 78 |  // In test mode it awaits for the completion before trying | 
| 80 | 79 |  // to fetch data for completion, hover.etc. | 
| 81 | 80 |  await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', textDocument.uri, new vscode.Position(0, 0)); | 
| 82 |  | - assert.equal(await isLanguageServerDownloaded(), true, 'Language Server not downloaded'); | 
|  | 81 | + await waitForCondition(isLanguageServerDownloaded, 30_000, 'Language Server not downloaded'); | 
|  | 82 | + // For for LS to get extracted. | 
|  | 83 | + await sleep(10_000); | 
| 83 | 84 |  return textDocument; | 
| 84 | 85 |  } | 
| 85 | 86 | 
 | 
| 86 |  | - const assertFile = (expectedLocation: string, location: vscode.Uri) => { | 
| 87 |  | - let relLocation = vscode.workspace.asRelativePath(location); | 
| 88 |  | - let expectedRelLocation = vscode.workspace.asRelativePath(expectedLocation); | 
| 89 |  | - if (isWindows) { | 
| 90 |  | - relLocation = relLocation.toUpperCase(); | 
| 91 |  | - expectedRelLocation = expectedRelLocation.toUpperCase(); | 
| 92 |  | - } | 
| 93 |  | - assert.equal(expectedRelLocation, relLocation, 'Position is in wrong file'); | 
| 94 |  | - }; | 
| 95 |  | - | 
| 96 |  | - const assertRange = (expectedRange: vscode.Range, range: vscode.Range) => { | 
| 97 |  | - const formatPosition = (position: vscode.Position) => { | 
| 98 |  | - return `${position.line},${position.character}`; | 
| 99 |  | - }; | 
| 100 |  | - assert.equal(formatPosition(expectedRange.start), formatPosition(range.start), 'Start position is incorrect'); | 
| 101 |  | - assert.equal(formatPosition(expectedRange.end), formatPosition(range.end), 'End position is incorrect'); | 
| 102 |  | - }; | 
| 103 |  | - | 
| 104 | 87 |  test('Definitions', async () => { | 
| 105 |  | - const startPosition = new vscode.Position(2, 6); | 
| 106 |  | - const expectedFiles = [fileDefinitions]; | 
| 107 |  | - const expectedRanges = [new vscode.Range(2, 4, 2, 16)]; | 
|  | 88 | + const startPosition = new vscode.Position(13, 6); | 
| 108 | 89 |  const textDocument = await openFile(fileDefinitions); | 
| 109 |  | - | 
| 110 |  | - const locations = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, startPosition); | 
| 111 |  | - assert.equal(expectedFiles.length, locations!.length, 'Wrong number of results'); | 
| 112 |  | - | 
| 113 |  | - for (let i = 0; i < locations!.length; i += 1) { | 
| 114 |  | - assertFile(expectedFiles[i], locations![i].uri); | 
| 115 |  | - assertRange(expectedRanges[i], locations![i].range!); | 
|  | 90 | + let tested = false; | 
|  | 91 | + for (let i = 0; i < 5; i += 1) { | 
|  | 92 | + const locations = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, startPosition); | 
|  | 93 | + if (locations && locations.length > 0) { | 
|  | 94 | + expect(locations![0].uri.fsPath).to.contain(path.basename(fileDefinitions)); | 
|  | 95 | + tested = true; | 
|  | 96 | + break; | 
|  | 97 | + } else { | 
|  | 98 | + // Wait for LS to start. | 
|  | 99 | + await sleep(5_000); | 
|  | 100 | + } | 
|  | 101 | + } | 
|  | 102 | + if (!tested) { | 
|  | 103 | + assert.fail('Failled to test definitions'); | 
| 116 | 104 |  } | 
| 117 |  | - }); | 
| 118 |  | - | 
| 119 |  | - test('Exclude subfolder', async () => { | 
| 120 |  | - await openFile(fileOne); | 
| 121 |  | - const diag = vscode.languages.getDiagnostics(); | 
| 122 |  | - | 
| 123 |  | - const main = diag.filter(d => d[0].fsPath.indexOf('one.py') >= 0); | 
| 124 |  | - assert.equal(main.length > 0, true); | 
| 125 |  | - | 
| 126 |  | - const subdir1 = diag.filter(d => d[0].fsPath.indexOf('dir1file.py') >= 0); | 
| 127 |  | - assert.equal(subdir1.length, 0); | 
| 128 |  | - | 
| 129 |  | - const subdir2 = diag.filter(d => d[0].fsPath.indexOf('dir2file.py') >= 0); | 
| 130 |  | - assert.equal(subdir2.length, 0); | 
| 131 | 105 |  }); | 
| 132 | 106 | }); | 
0 commit comments