Skip to content

Commit

Permalink
Added commands custom.workspaceFile, custom.workspaceFolders and cust…
Browse files Browse the repository at this point in the history
…om.getCommands
  • Loading branch information
Darien Pardinas Diaz committed May 19, 2024
1 parent f3025cc commit 0c7abc3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 20 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions src/services/requestProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 19 additions & 6 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
});

});
5 changes: 3 additions & 2 deletions src/test/suite/sendPostRequest.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit 0c7abc3

Please sign in to comment.