-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple end to end tests for CodeLens and Hover scaffolding usag…
…es. (#7)
- Loading branch information
Showing
7 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as vscode from 'vscode'; | ||
import * as assert from 'assert'; | ||
import { getDocUri, activate } from './helper'; | ||
|
||
suite('Should show CodeLens', () => { | ||
const docUri = getDocUri('diamond.py'); | ||
|
||
test('Show CodeLenses in diamond.py', async () => { | ||
await testCodeLens(docUri, 4); | ||
}); | ||
}); | ||
|
||
async function testCodeLens( | ||
docUri: vscode.Uri, | ||
expectedCodeLensNumber: number | ||
) { | ||
await activate(docUri); | ||
const actualCodeLenses = (await vscode.commands.executeCommand( | ||
'vscode.executeCodeLensProvider', | ||
docUri | ||
)) as vscode.CodeLens[]; | ||
assert.ok(actualCodeLenses.length === expectedCodeLensNumber); | ||
// TODO: to add the check for the contents once the functionality has been | ||
// fully implemented | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
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('kaiyan.python-mro')!; | ||
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, '../../../tests/examples', 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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as vscode from 'vscode'; | ||
import * as assert from 'assert'; | ||
import { getDocUri, activate } from './helper'; | ||
|
||
suite('Should show Hover', () => { | ||
const docUri = getDocUri('diamond.py'); | ||
|
||
test('Show Hover in diamond.py', async () => { | ||
await testHover(docUri, new vscode.Position(9, 3)); | ||
}); | ||
}); | ||
|
||
async function testHover( | ||
docUri: vscode.Uri, | ||
hoverPosition: vscode.Position | ||
) { | ||
await activate(docUri); | ||
const actualHoverResults = (await vscode.commands.executeCommand( | ||
'vscode.executeHoverProvider', | ||
docUri, | ||
hoverPosition, | ||
)) as vscode.Hover[]; | ||
assert.ok(actualHoverResults.length > 0); | ||
let foundMRO = false; | ||
actualHoverResults.forEach(hover => { | ||
if (hover.contents.length > 0) { | ||
let firstLine = hover.contents[0]; | ||
let firstLineContent: string; | ||
if (typeof firstLine === 'string') { | ||
firstLineContent = firstLine; | ||
} else { | ||
firstLineContent = firstLine.value; | ||
} | ||
if (firstLineContent === 'Target class name') { | ||
foundMRO = true; | ||
} | ||
} | ||
}); | ||
assert.ok(foundMRO); | ||
// TODO: to add the check for the contents once the functionality has been | ||
// fully implemented | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
import * as path from 'path'; | ||
import * as Mocha from 'mocha'; | ||
import * as glob from 'glob'; | ||
|
||
export function run(): Promise<void> { | ||
// Create the mocha test | ||
const mocha = new Mocha({ | ||
ui: 'tdd', | ||
}); | ||
mocha.useColors(true); | ||
mocha.timeout(100000); | ||
|
||
const testsRoot = __dirname; | ||
|
||
return new Promise((resolve, reject) => { | ||
glob('**.test.js', { cwd: testsRoot }, (err, files) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
// Add files to the test suite | ||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); | ||
|
||
try { | ||
// Run the mocha test | ||
mocha.run(failures => { | ||
if (failures > 0) { | ||
reject(new Error(`${failures} tests failed.`)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as path from 'path'; | ||
|
||
import { runTests } from 'vscode-test'; | ||
|
||
async function main() { | ||
try { | ||
// The folder containing the Extension Manifest package.json | ||
// Passed to `--extensionDevelopmentPath` | ||
const extensionDevelopmentPath = path.resolve(__dirname, '../../../'); | ||
|
||
// The path to test runner | ||
// Passed to --extensionTestsPath | ||
const extensionTestsPath = path.resolve(__dirname, './index'); | ||
|
||
// Download VS Code, unzip it and run the integration test | ||
await runTests({ extensionDevelopmentPath, extensionTestsPath }); | ||
} catch (err) { | ||
console.error('Failed to run tests'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
export CODE_TESTS_PATH="$(pwd)/client/out/test" | ||
export CODE_TESTS_WORKSPACE="$(pwd)/tests/examples" | ||
|
||
node "$(pwd)/client/out/test/runTest" |