From 8c10435216119042822475a1a6491259430a879c Mon Sep 17 00:00:00 2001 From: Darien Pardinas Diaz Date: Mon, 13 May 2024 17:27:36 -0400 Subject: [PATCH] Get first unit test working --- .vscode/launch.json | 5 +++-- package.json | 2 +- src/extension.ts | 2 +- src/test/suite/extension.test.ts | 24 ++++++------------------ webpack.config.js | 2 +- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6d15de1..bffbc27 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,7 @@ "--extensionDevelopmentPath=${workspaceFolder}" ], "outFiles": [ - "${workspaceFolder}/dist/**/*.js" + "${workspaceFolder}/out/**/*.js" ] }, { @@ -21,11 +21,12 @@ "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" } diff --git a/package.json b/package.json index 6c7220e..ae87d6c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "activationEvents": [ "*" ], - "main": "./dist/extension.js", + "main": "./out/extension.js", "contributes": { "configuration": { "title": "REST Control: Configuration", diff --git a/src/extension.ts b/src/extension.ts index fb6d5e7..d95f5c3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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"; diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 23a1a14..18d723c 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -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 { - 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); }); diff --git a/webpack.config.js b/webpack.config.js index 538d2be..ec5c0a4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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' },