Skip to content

Commit

Permalink
Get first unit test working
Browse files Browse the repository at this point in the history
  • Loading branch information
Darien Pardinas Diaz authored and dpar39 committed May 13, 2024
1 parent d21ab16 commit 8c10435
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
"${workspaceFolder}/out/**/*.js"
]
},
{
"name": "Test Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"${workspaceFolder}/sampleWorkspace",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: test-watch"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"activationEvents": [
"*"
],
"main": "./dist/extension.js",
"main": "./out/extension.js",
"contributes": {
"configuration": {
"title": "REST Control: Configuration",
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AddressInfo } from "net";
import { ControlRequest } from "./models/controlRequest";
import { processRemoteControlRequest } from "./services/requestProcessor";

let server: http.Server;
export let server: http.Server;
let statusbar: vscode.StatusBarItem;

export const EXTENSION_ID: string = "dpar39.vscode-rest-control";
Expand Down
24 changes: 6 additions & 18 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
import * as assert from "assert";
import * as path from "path";
import { EXTENSION_ID } from "../../extension";
import { EXTENSION_ID, server } from "../../extension";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
import { makeRequest } from "./sendPostRequest";
// import * as myExtension from '../extension';

async function sleep(ms: number): Promise<void> {
return new Promise(
(resolve) => setTimeout(resolve, ms));
}

suite("Extension Test Suite", () => {
suiteSetup(async () => {
const sampleWorkspace = path.resolve(__dirname, "../../../sampleWorkspace");
let uri = vscode.Uri.file(sampleWorkspace);
await vscode.commands.executeCommand("vscode.openFolder", uri);
await sleep(3000);
});
suiteSetup(async () => { });

suiteTeardown(() => {});
suiteTeardown(() => { });

test("check can list extensions", async () => {
const address = server.address() as any;
const extensionIds: string[] = (await makeRequest(
"custom.listInstalledExtensions",
[]
[], address.port
)) as string[];
assert(extensionIds.includes(EXTENSION_ID));
});
}).timeout(5000);
});
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config = {
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
path: path.resolve(__dirname, 'out'),
filename: 'extension.js',
libraryTarget: 'commonjs2'
},
Expand Down

0 comments on commit 8c10435

Please sign in to comment.