summaryrefslogtreecommitdiff
path: root/client/src/test/helper.ts
diff options
context:
space:
mode:
authorbscan <10503608+bscan@users.noreply.github.com>2022-01-17 22:27:13 -0500
committerbscan <10503608+bscan@users.noreply.github.com>2022-01-17 22:27:13 -0500
commitfa03b409a799cd540bc07e2d466cb6cbf790baab (patch)
treeb85dfdd2f76faf33175dc1b9d67194883ed19122 /client/src/test/helper.ts
parent7e7a4e52d485afba9931ea7013cf05bea272b8c7 (diff)
downloadPerlNavigator-fa03b409a799cd540bc07e2d466cb6cbf790baab.zip
Initial commit
Diffstat (limited to 'client/src/test/helper.ts')
-rw-r--r--client/src/test/helper.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/client/src/test/helper.ts b/client/src/test/helper.ts
new file mode 100644
index 0000000..6e6724d
--- /dev/null
+++ b/client/src/test/helper.ts
@@ -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('vscode-samples.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));
+}