From a1fed5fcd933545fe6ef5309206a0bcee28d6116 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 28 Nov 2018 13:31:41 -0800 Subject: [PATCH 1/4] Fix language server smoke tests --- .travis.yml | 2 +- src/test/smoke/msLanguageServer.smoke.test.ts | 55 +++---------------- .../smokeTests/definitions.py | 31 +++++++++++ 3 files changed, 40 insertions(+), 48 deletions(-) create mode 100644 src/testMultiRootWkspc/smokeTests/definitions.py diff --git a/.travis.yml b/.travis.yml index 0eb897e48180..ba94b95bc16c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -108,7 +108,7 @@ script: - if [[ $AZURE_STORAGE_ACCOUNT && "$TRAVIS_BRANCH" == release* && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run clean; vsce package; - azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-$TRAVIS_BRANCH-insiders.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet; + azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-$TRAVIS_BRANCH-unbundled.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet; npm run clean; npm run package; npx gulp clean:cleanExceptTests; diff --git a/src/test/smoke/msLanguageServer.smoke.test.ts b/src/test/smoke/msLanguageServer.smoke.test.ts index 3f99f03fbe0f..47491e093d71 100644 --- a/src/test/smoke/msLanguageServer.smoke.test.ts +++ b/src/test/smoke/msLanguageServer.smoke.test.ts @@ -6,18 +6,17 @@ // tslint:disable:max-func-body-length no-invalid-this no-any import * as assert from 'assert'; +import { expect } from 'chai'; import * as fs from 'fs-extra'; import * as glob from 'glob'; import * as path from 'path'; import * as vscode from 'vscode'; +import { waitForCondition } from '../common'; import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST, SMOKE_TEST_EXTENSIONS_DIR } from '../constants'; -import { isWindows, noop } from '../core'; +import { noop } from '../core'; import { closeActiveWindows, initialize, initializeTest } from '../initialize'; -const decoratorsPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'pythonFiles', 'definition', 'navigation'); -const fileDefinitions = path.join(decoratorsPath, 'definitions.py'); -const wksPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'pythonFiles', 'exclusions'); -const fileOne = path.join(wksPath, 'one.py'); +const fileDefinitions = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'definitions.py'); suite('Smoke Test: Language Server', function () { // Large value to allow for LS to get downloaded. @@ -79,54 +78,16 @@ suite('Smoke Test: Language Server', function () { // In test mode it awaits for the completion before trying // to fetch data for completion, hover.etc. await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', textDocument.uri, new vscode.Position(0, 0)); - assert.equal(await isLanguageServerDownloaded(), true, 'Language Server not downloaded'); + await waitForCondition(isLanguageServerDownloaded, 30_000, 'Language Server not downloaded'); return textDocument; } - const assertFile = (expectedLocation: string, location: vscode.Uri) => { - let relLocation = vscode.workspace.asRelativePath(location); - let expectedRelLocation = vscode.workspace.asRelativePath(expectedLocation); - if (isWindows) { - relLocation = relLocation.toUpperCase(); - expectedRelLocation = expectedRelLocation.toUpperCase(); - } - assert.equal(expectedRelLocation, relLocation, 'Position is in wrong file'); - }; - - const assertRange = (expectedRange: vscode.Range, range: vscode.Range) => { - const formatPosition = (position: vscode.Position) => { - return `${position.line},${position.character}`; - }; - assert.equal(formatPosition(expectedRange.start), formatPosition(range.start), 'Start position is incorrect'); - assert.equal(formatPosition(expectedRange.end), formatPosition(range.end), 'End position is incorrect'); - }; - test('Definitions', async () => { - const startPosition = new vscode.Position(2, 6); - const expectedFiles = [fileDefinitions]; - const expectedRanges = [new vscode.Range(2, 4, 2, 16)]; + const startPosition = new vscode.Position(13, 6); const textDocument = await openFile(fileDefinitions); const locations = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', textDocument.uri, startPosition); - assert.equal(expectedFiles.length, locations!.length, 'Wrong number of results'); - - for (let i = 0; i < locations!.length; i += 1) { - assertFile(expectedFiles[i], locations![i].uri); - assertRange(expectedRanges[i], locations![i].range!); - } - }); - - test('Exclude subfolder', async () => { - await openFile(fileOne); - const diag = vscode.languages.getDiagnostics(); - - const main = diag.filter(d => d[0].fsPath.indexOf('one.py') >= 0); - assert.equal(main.length > 0, true); - - const subdir1 = diag.filter(d => d[0].fsPath.indexOf('dir1file.py') >= 0); - assert.equal(subdir1.length, 0); - - const subdir2 = diag.filter(d => d[0].fsPath.indexOf('dir2file.py') >= 0); - assert.equal(subdir2.length, 0); + expect(locations).to.be.length.greaterThan(0, 'Wrong number of results'); + expect(locations![0].uri.fsPath).to.contain(path.basename(fileDefinitions)); }); }); diff --git a/src/testMultiRootWkspc/smokeTests/definitions.py b/src/testMultiRootWkspc/smokeTests/definitions.py new file mode 100644 index 000000000000..a8379a49f960 --- /dev/null +++ b/src/testMultiRootWkspc/smokeTests/definitions.py @@ -0,0 +1,31 @@ +from contextlib import contextmanager + +def my_decorator(fn): + """ + This is my decorator. + """ + def wrapper(*args, **kwargs): + """ + This is the wrapper. + """ + return 42 + return wrapper + +@my_decorator +def thing(arg): + """ + Thing which is decorated. + """ + pass + +@contextmanager +def my_context_manager(): + """ + This is my context manager. + """ + print("before") + yield + print("after") + +with my_context_manager(): + thing(19) From 4dceb59ea04f5211667fcd39435b828a9bbc3dac Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 28 Nov 2018 13:38:09 -0800 Subject: [PATCH 2/4] Temporarily enable --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ba94b95bc16c..922247cee7e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -105,7 +105,7 @@ script: npm run testSmoke; azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-insiders.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet; fi - - if [[ $AZURE_STORAGE_ACCOUNT && "$TRAVIS_BRANCH" == release* && "$TRAVIS_PULL_REQUEST" == "false" ]]; then + - if [[ $AZURE_STORAGE_ACCOUNT ]]; then npm run clean; vsce package; azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-$TRAVIS_BRANCH-unbundled.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet; From edfd044b2df3684ab26d20659b1f5c64aaabe8d9 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 28 Nov 2018 13:58:30 -0800 Subject: [PATCH 3/4] Updated tests --- src/test/smoke/msLanguageServer.smoke.test.ts | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/test/smoke/msLanguageServer.smoke.test.ts b/src/test/smoke/msLanguageServer.smoke.test.ts index 47491e093d71..ce42dc937372 100644 --- a/src/test/smoke/msLanguageServer.smoke.test.ts +++ b/src/test/smoke/msLanguageServer.smoke.test.ts @@ -13,7 +13,7 @@ import * as path from 'path'; import * as vscode from 'vscode'; import { waitForCondition } from '../common'; import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST, SMOKE_TEST_EXTENSIONS_DIR } from '../constants'; -import { noop } from '../core'; +import { noop, sleep } from '../core'; import { closeActiveWindows, initialize, initializeTest } from '../initialize'; const fileDefinitions = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'definitions.py'); @@ -79,15 +79,28 @@ suite('Smoke Test: Language Server', function () { // to fetch data for completion, hover.etc. await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', textDocument.uri, new vscode.Position(0, 0)); await waitForCondition(isLanguageServerDownloaded, 30_000, 'Language Server not downloaded'); + // For for LS to get extracted. + await sleep(10_000); return textDocument; } test('Definitions', async () => { const startPosition = new vscode.Position(13, 6); const textDocument = await openFile(fileDefinitions); - - const locations = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', textDocument.uri, startPosition); - expect(locations).to.be.length.greaterThan(0, 'Wrong number of results'); - expect(locations![0].uri.fsPath).to.contain(path.basename(fileDefinitions)); + let tested = false; + for (let i = 0; i < 5; i += 1) { + const locations = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', textDocument.uri, startPosition); + if (locations && locations.length > 0) { + expect(locations![0].uri.fsPath).to.contain(path.basename(fileDefinitions)); + tested = true; + break; + } else { + // Wait for LS to start. + await sleep(5_000); + } + } + if (!tested) { + assert.fail('Failled to test definitions'); + } }); }); From e82870d3752dae7c0c878d1af1c759ee8d1870b2 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 28 Nov 2018 14:13:30 -0800 Subject: [PATCH 4/4] Revert changes to travis file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 922247cee7e4..ba94b95bc16c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -105,7 +105,7 @@ script: npm run testSmoke; azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-insiders.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet; fi - - if [[ $AZURE_STORAGE_ACCOUNT ]]; then + - if [[ $AZURE_STORAGE_ACCOUNT && "$TRAVIS_BRANCH" == release* && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run clean; vsce package; azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-$TRAVIS_BRANCH-unbundled.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet;