Merge pull request #79 from Microsoft/octref/test

Add test for lsp-sample
This commit is contained in:
Pine
2018-06-26 09:26:43 +02:00
committed by GitHub
13 changed files with 473 additions and 309 deletions

View File

@ -1,3 +1,4 @@
out
node_modules
client/server
client/server
.vscode-test

View File

@ -7,7 +7,7 @@
"request": "launch",
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
@ -22,6 +22,20 @@
"port": 6009,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"name": "Language Server E2E Test",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/client/out/test",
"${workspaceRoot}/client/testFixture"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
}
]
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as vscode from 'vscode'
import * as assert from 'assert'
import { getDocUri, activate } from './helper'
describe('Should do completion', () => {
const docUri = getDocUri('completion.txt')
it('Completes JS/TS in txt file', async () => {
await testCompletion(docUri, new vscode.Position(0, 0), {
items: [
{ label: 'JavaScript', kind: vscode.CompletionItemKind.Text },
{ label: 'TypeScript', kind: vscode.CompletionItemKind.Text }
]
})
})
})
async function testCompletion(docUri: vscode.Uri, position: vscode.Position, expectedCompletionList: vscode.CompletionList) {
await activate(docUri)
// Executing the command `vscode.executeCompletionItemProvider` to simulate triggering completion
const actualCompletionList = (await vscode.commands.executeCommand(
'vscode.executeCompletionItemProvider',
docUri,
position
)) as vscode.CompletionList
assert.equal(actualCompletionList.items.length, expectedCompletionList.items.length);
expectedCompletionList.items.forEach((expectedItem, i) => {
const actualItem = actualCompletionList.items[i]
assert.equal(actualItem.label, expectedItem.label)
assert.equal(actualItem.kind, expectedItem.kind)
})
}

View File

@ -0,0 +1,42 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as vscode from 'vscode'
import * as assert from 'assert'
import { getDocUri, activate } from './helper'
describe('Should get diagnostics', () => {
const docUri = getDocUri('diagnostics.txt')
it('Diagnoses uppercase texts', async () => {
await testDiagnostics(docUri, [
{ message: 'ANY is all uppercase.', range: toRange(0, 0, 0, 3), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
{ message: 'ANY is all uppercase.', range: toRange(0, 14, 0, 17), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
{ message: 'OS is all uppercase.', range: toRange(0, 18, 0, 20), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' }
])
})
})
function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
const start = new vscode.Position(sLine, sChar)
const end = new vscode.Position(eLine, eChar)
return new vscode.Range(start, end)
}
async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
await activate(docUri)
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
assert.equal(actualDiagnostics.length, expectedDiagnostics.length);
expectedDiagnostics.forEach((expectedDiagnostic, i) => {
const actualDiagnostic = actualDiagnostics[i]
assert.equal(actualDiagnostic.message, expectedDiagnostic.message)
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range)
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity)
})
}

View File

@ -0,0 +1,45 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as vscode from 'vscode'
import * as path from 'path'
export let doc: vscode.TextDocument
export let editor: vscode.TextEditor
export let documentEol: string
export let platformEol: string
/**
* Activates the vscode.lsp-sample extension
*/
export async function activate(docUri: vscode.Uri) {
// The extensionId is `publisher.name` from package.json
const ext = vscode.extensions.getExtension('vscode.lsp-sample')
await ext.activate();
try {
doc = await vscode.workspace.openTextDocument(docUri)
editor = await vscode.window.showTextDocument(doc)
await sleep(2000) // Wait for server activation
} catch (e) {
console.error(e)
}
}
async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export const getDocPath = (p: string) => {
return path.resolve(__dirname, '../../testFixture', p)
}
export const getDocUri = (p: string) => {
return vscode.Uri.file(getDocPath(p))
}
export async function setTestContent(content: string): Promise<boolean> {
const all = new vscode.Range(doc.positionAt(0), doc.positionAt(doc.getText().length))
return editor.edit(eb => eb.replace(all, content))
}

View File

@ -0,0 +1,15 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as testRunner from 'vscode/lib/testrunner';
testRunner.configure({
ui: 'bdd',
useColors: true,
timeout: 100000
});
module.exports = testRunner;

View File

@ -0,0 +1 @@
ANY browsers, ANY OS.

View File

@ -52,7 +52,8 @@
"watch:client": "tsc -w -p ./client/tsconfig.json",
"watch:server": "tsc -w -p ./server/tsconfig.json",
"compile": "npm run compile:client && npm run compile:server",
"postinstall": "cd client && npm install && cd ../server && npm install && cd .."
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
"test": "sh ./scripts/e2e.sh"
},
"devDependencies": {
"@types/mocha": "^5.2.0",

6
lsp-sample/scripts/e2e.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
export CODE_TESTS_PATH="$(pwd)/client/out/test"
export CODE_TESTS_WORKSPACE="$(pwd)/client/testFixture"
node "$(pwd)/client/node_modules/vscode/bin/test"

View File

@ -14,8 +14,8 @@
"resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-4.1.3.tgz",
"integrity": "sha512-D6p3q9x8QPtPLRUO5d2UKizjFYfg8zLVJqKoMpAaom8Wuhl1oKRCjeLg+Cp4mgPeCwR71wbgX2BM/jL51ni/0g==",
"requires": {
"vscode-languageserver-protocol": "3.7.2",
"vscode-uri": "1.0.3"
"vscode-languageserver-protocol": "^3.7.2",
"vscode-uri": "^1.0.1"
}
},
"vscode-languageserver-protocol": {
@ -23,8 +23,8 @@
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.7.2.tgz",
"integrity": "sha512-VVJwIA/FPl/FnVtrns0FPK6TLi/ET7n1Yo6tCrm6aG7+yAVwIGWdpTmKE+nbP8wEMMbHCkIabk63IJvfz2HNRg==",
"requires": {
"vscode-jsonrpc": "3.6.2",
"vscode-languageserver-types": "3.7.2"
"vscode-jsonrpc": "^3.6.2",
"vscode-languageserver-types": "^3.7.2"
}
},
"vscode-languageserver-types": {

View File

@ -14,6 +14,5 @@
"dependencies": {
"vscode-languageserver": "^4.1.3"
},
"scripts": {
}
"scripts": {}
}