diff --git a/package-lock.json b/package-lock.json index 160b01e..1a753bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1536,9 +1536,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001618", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001618.tgz", - "integrity": "sha512-p407+D1tIkDvsEAPS22lJxLQQaG8OTBEqo0KhzfABGk0TU4juBNDSfH0hyAp/HRyx+M8L17z/ltyhxh27FTfQg==", + "version": "1.0.30001620", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001620.tgz", + "integrity": "sha512-WJvYsOjd1/BYUY6SNGUosK9DUidBPDTnOARHp3fSmFO1ekdxaY6nKRttEVrfMmYi80ctS0kz1wiWmm14fVc3ew==", "dev": true, "funding": [ { @@ -2001,9 +2001,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.767", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.767.tgz", - "integrity": "sha512-nzzHfmQqBss7CE3apQHkHjXW77+8w3ubGCIoEijKCJebPufREaFETgGXWTkh32t259F3Kcq+R8MZdFdOJROgYw==", + "version": "1.4.774", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.774.tgz", + "integrity": "sha512-132O1XCd7zcTkzS3FgkAzKmnBuNJjK8WjcTtNuoylj7MYbqw5eXehjQ5OK91g0zm7OTKIPeaAG4CPoRfD9M1Mg==", "dev": true }, "node_modules/emoji-regex": { @@ -2115,9 +2115,9 @@ } }, "node_modules/es-module-lexer": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.2.tgz", - "integrity": "sha512-l60ETUTmLqbVbVHv1J4/qj+M8nq7AwMzEcg3kmJDt9dCNrTk+yHcYFf/Kw75pMDwd9mPcIGCG5LcS20SxYRzFA==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.3.tgz", + "integrity": "sha512-i1gCgmR9dCl6Vil6UKPI/trA69s08g/syhiDK9TG0Nf1RJjjFI+AzoWW7sPufzkgYAn861skuCwJa0pIIHYxvg==", "dev": true }, "node_modules/escalade": { diff --git a/package.json b/package.json index a2499c7..c269d8c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "This extension allows you to remotely control Visual Studio Code via a REST endpoint, taking automation to the next level.", "publisher": "dpar39", "license": "MIT", - "version": "0.0.4", + "version": "0.0.5", "engines": { "vscode": "^1.55.0" }, @@ -73,7 +73,7 @@ "test-watch": "tsc -watch -p ./", "pretest": "npm run test-compile && npm run lint", "lint": "eslint src --ext ts", - "test": "node ./out/test/runTest.js" + "test": "xvfb-run -a node ./out/test/runTest.js" }, "devDependencies": { "@types/glob": "^7.1.6", diff --git a/src/services/requestProcessor.ts b/src/services/requestProcessor.ts index 9eab976..8f2347c 100644 --- a/src/services/requestProcessor.ts +++ b/src/services/requestProcessor.ts @@ -69,6 +69,24 @@ export async function processRemoteControlRequest(requestObject: ControlRequest) return vscode.extensions.all.map((e) => e.id); } + if (command === "custom.workspaceFile") { + return vscode.workspace.workspaceFile?.toString(); + } + + if (command === "custom.getCommands") { + return await vscode.commands.getCommands(); + } + + if (command === "custom.workspaceFolders") { + return vscode.workspace.workspaceFolders?.map(ws => { + return { + name: ws.name, + index: ws.index, + uri: ws.uri.toString(), + }; + }); + } + if (command === "custom.showInformationMessage") { return await vscode.window.showInformationMessage(args[0], ...args.slice(1)); } diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 11793bf..d44f777 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -12,8 +12,13 @@ async function main() { // Passed to --extensionTestsPath const extensionTestsPath = path.resolve(__dirname, "./suite/index"); + // Get the directory path to a sample workspace + const sampleWorkspace = path.resolve(__dirname, "../../sampleWorkspace"); + + // VSCode launch arguments + const launchArgs = [sampleWorkspace]; // Download VS Code, unzip it and run the integration test - await runTests({ extensionDevelopmentPath, extensionTestsPath}); + await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs }); } catch (err) { console.error("Failed to run tests"); process.exit(1); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index cd3725d..0c1df95 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -1,5 +1,5 @@ import * as assert from "assert"; -import { EXTENSION_ID, getListeningPort } from "../../extension"; +import { EXTENSION_ID } from "../../extension"; // You can import and use all API from the 'vscode' module // as well as import your extension to test it @@ -8,13 +8,26 @@ import { makeRequest } from "./sendPostRequest"; suite("Extension Test Suite", () => { suiteSetup(async () => { }); - suiteTeardown(() => { }); + suiteTeardown(async () => { }); test("check can list extensions", async () => { - const extensionIds: string[] = (await makeRequest( - "custom.listInstalledExtensions", - [], getListeningPort() - )) as string[]; + const extensionIds: string[] = (await makeRequest("custom.listInstalledExtensions")) as string[]; assert(extensionIds.includes(EXTENSION_ID)); }).timeout(5000); + + test("get workspace folders", async () => { + const workspaceFolders = (await makeRequest("custom.workspaceFolders")) as string[]; + assert(workspaceFolders.length === 1); + const ws = workspaceFolders[0] as any; + assert(ws.name === 'sampleWorkspace'); + assert(ws.index === 0); + assert(ws.uri.startsWith("file://")); + assert(ws.uri.endsWith("/sampleWorkspace")); + }); + + test("get all commands registred in vscode", async () => { + const commands: string[] = (await makeRequest("custom.getCommands")) as string[]; + assert(commands.length > 100); + }); + }); diff --git a/src/test/suite/sendPostRequest.ts b/src/test/suite/sendPostRequest.ts index 9485c55..ef87837 100644 --- a/src/test/suite/sendPostRequest.ts +++ b/src/test/suite/sendPostRequest.ts @@ -1,12 +1,13 @@ import * as http from "http"; +import { getListeningPort } from "../../extension"; -export async function makeRequest(command: string, args: any[], port: number = 37100) { +export async function makeRequest(command: string, args: any[] = [], port: number = 0) { return new Promise((resolve, reject) => { const req = http.request( { method: "POST", hostname: "localhost", - port: port, + port: port || getListeningPort(), path: "/", }, (res) => {