Skip to content

Commit 7475d5d

Browse files
committed
Some test path fixes
1 parent a114373 commit 7475d5d

5 files changed

Lines changed: 129 additions & 42 deletions

File tree

src/extension.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ import {
136136
} from "./vcastUtilities";
137137

138138
import fs = require("fs");
139-
import { getNonce } from "./manage/manageSrc/manageUtils";
139+
import { getNonce, resolveWebviewBase } from "./manage/manageSrc/manageUtils";
140140
const path = require("path");
141141
let messagePane: vscode.OutputChannel = vscode.window.createOutputChannel(
142142
"VectorCAST Test Explorer"
@@ -744,20 +744,19 @@ function configureExtension(context: vscode.ExtensionContext) {
744744
const addTestsuiteToCompiler = vscode.commands.registerCommand(
745745
"vectorcastTestExplorer.addTestsuiteToCompiler",
746746
async (node: any) => {
747+
const manageWebviewSrcDir = resolveWebviewBase(context);
747748
const panel = vscode.window.createWebviewPanel(
748749
"addTestsuiteToCompiler",
749750
"Add Testsuite to Compiler",
750751
vscode.ViewColumn.Active,
751752
{
752753
enableScripts: true,
753754
retainContextWhenHidden: true,
754-
localResourceRoots: [
755-
vscode.Uri.file(path.join(context.extensionPath, "src", "manage")),
756-
],
755+
localResourceRoots: [vscode.Uri.file(manageWebviewSrcDir)],
757756
}
758757
);
759758

760-
panel.webview.html = getTestsuiteWebviewContent(context, panel);
759+
panel.webview.html = await getTestsuiteWebviewContent(context, panel);
761760

762761
panel.webview.onDidReceiveMessage((message) => {
763762
if (message.command === "submit") {
@@ -779,11 +778,11 @@ function configureExtension(context: vscode.ExtensionContext) {
779778
context.subscriptions.push(addTestsuiteToCompiler);
780779

781780
// Webview HTML content.
782-
function getTestsuiteWebviewContent(
781+
async function getTestsuiteWebviewContent(
783782
context: vscode.ExtensionContext,
784783
panel: vscode.WebviewPanel
785-
): string {
786-
const base = path.join(context.extensionPath, "src", "manage", "webviews");
784+
): Promise<string> {
785+
const base = resolveWebviewBase(context);
787786

788787
// on-disk locations
789788
const cssOnDisk = vscode.Uri.file(
@@ -1182,22 +1181,23 @@ async function installPreActivationEventHandlers(
11821181
const importEnviroToProject = vscode.commands.registerCommand(
11831182
"vectorcastTestExplorer.importEnviroToProject",
11841183
async (_args: vscode.Uri, argList: vscode.Uri[]) => {
1184+
const manageWebviewSrcDir = await resolveWebviewBase(context);
11851185
const panel = vscode.window.createWebviewPanel(
11861186
"importEnviroToProject",
11871187
"Import Environment to Project",
11881188
vscode.ViewColumn.Active,
11891189
{
11901190
enableScripts: true,
11911191
retainContextWhenHidden: true,
1192-
localResourceRoots: [
1193-
vscode.Uri.file(
1194-
path.join(context.extensionPath, "src", "manage", "webviews")
1195-
),
1196-
],
1192+
localResourceRoots: [vscode.Uri.file(manageWebviewSrcDir)],
11971193
}
11981194
);
11991195

1200-
panel.webview.html = getImportEnvWebviewContent(context, panel, argList);
1196+
panel.webview.html = await getImportEnvWebviewContent(
1197+
context,
1198+
panel,
1199+
argList
1200+
);
12011201

12021202
panel.webview.onDidReceiveMessage(
12031203
async (message) => {
@@ -1247,23 +1247,20 @@ async function installPreActivationEventHandlers(
12471247
const addEnviroToProject = vscode.commands.registerCommand(
12481248
"vectorcastTestExplorer.addEnviroToProject",
12491249
async (_projectNode: any) => {
1250+
const manageWebviewSrcDir = resolveWebviewBase(context);
12501251
const panel = vscode.window.createWebviewPanel(
12511252
"addEnviroToProject",
12521253
"Add Environment To Project",
12531254
vscode.ViewColumn.Active,
12541255
{
12551256
enableScripts: true,
12561257
retainContextWhenHidden: true,
1257-
localResourceRoots: [
1258-
vscode.Uri.file(
1259-
path.join(context.extensionPath, "src", "manage", "webviews")
1260-
),
1261-
],
1258+
localResourceRoots: [vscode.Uri.file(manageWebviewSrcDir)],
12621259
}
12631260
);
12641261

12651262
// no initial env files
1266-
panel.webview.html = getImportEnvWebviewContent(context, panel, []);
1263+
panel.webview.html = await getImportEnvWebviewContent(context, panel, []);
12671264

12681265
panel.webview.onDidReceiveMessage(
12691266
async (message) => {
@@ -1330,12 +1327,12 @@ async function installPreActivationEventHandlers(
13301327
*
13311328
* The label "Source Files" is replaced with "Env Files" in this version.
13321329
*/
1333-
function getImportEnvWebviewContent(
1330+
async function getImportEnvWebviewContent(
13341331
context: vscode.ExtensionContext,
13351332
panel: vscode.WebviewPanel,
13361333
argList: vscode.Uri[]
1337-
): string {
1338-
const base = path.join(context.extensionPath, "src", "manage", "webviews");
1334+
): Promise<string> {
1335+
const base = resolveWebviewBase(context);
13391336

13401337
// on-disk resource locations
13411338
const cssOnDisk = vscode.Uri.file(path.join(base, "css", "importEnv.css"));
@@ -1388,22 +1385,23 @@ async function installPreActivationEventHandlers(
13881385
const newEnviroInProjectVCASTCommand = vscode.commands.registerCommand(
13891386
"vectorcastTestExplorer.newEnviroInProjectVCAST",
13901387
async (_args: vscode.Uri, argList: vscode.Uri[]) => {
1388+
const manageWebviewSrcDir = resolveWebviewBase(context);
13911389
const panel = vscode.window.createWebviewPanel(
13921390
"newEnvProject",
13931391
"Create Environment in Project",
13941392
vscode.ViewColumn.Active,
13951393
{
13961394
enableScripts: true,
13971395
retainContextWhenHidden: true,
1398-
localResourceRoots: [
1399-
vscode.Uri.file(
1400-
path.join(context.extensionPath, "src", "manage", "webviews")
1401-
),
1402-
],
1396+
localResourceRoots: [vscode.Uri.file(manageWebviewSrcDir)],
14031397
}
14041398
);
14051399

1406-
panel.webview.html = getNewEnvWebviewContent(context, panel, argList);
1400+
panel.webview.html = await getNewEnvWebviewContent(
1401+
context,
1402+
panel,
1403+
argList
1404+
);
14071405

14081406
panel.webview.onDidReceiveMessage(
14091407
async (message) => {
@@ -1436,12 +1434,12 @@ async function installPreActivationEventHandlers(
14361434
);
14371435
context.subscriptions.push(newEnviroInProjectVCASTCommand);
14381436

1439-
function getNewEnvWebviewContent(
1437+
async function getNewEnvWebviewContent(
14401438
context: vscode.ExtensionContext,
14411439
panel: vscode.WebviewPanel,
14421440
argList: vscode.Uri[]
1443-
): string {
1444-
const base = path.join(context.extensionPath, "src", "manage", "webviews");
1441+
): Promise<string> {
1442+
const base = resolveWebviewBase(context);
14451443
const cssOnDisk = vscode.Uri.file(
14461444
path.join(base, "css", "newEnvProject.css")
14471445
);

src/manage/manageSrc/manageUtils.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as vscode from "vscode";
2+
import * as fs from "fs";
3+
import * as path from "path";
24

35
import { globalController } from "../../testPane";
6+
import { vectorMessage } from "../../messagePane";
47

58
/**
69
* Searches the entire globalController for a test item with the specified id.
@@ -63,3 +66,47 @@ export function getNonce(): string {
6366
}
6467
return text;
6568
}
69+
70+
/**
71+
* Resolves the on‐disk base directory for our `src/manage/webviews` folder.
72+
*
73+
* 1. Tries the normal location under the installed extension:
74+
* <extensionPath>/src/manage/webviews
75+
* 2. If that doesn’t exist, checks if we're running in the E2E test harness
76+
* under "<...>/tests/internal/e2e/test/extension". If so, strips off
77+
* that suffix and uses the repo root to locate:
78+
* <repoRoot>/src/manage/webviews
79+
* 3. If neither exists, throws an error.
80+
*
81+
* @param context The ExtensionContext, used to read `extensionPath`.
82+
* @returns The filesystem path to the `webviews` folder.
83+
* @throws If no valid `webviews` folder can be found.
84+
*/
85+
export function resolveWebviewBase(context: vscode.ExtensionContext): string {
86+
// 1) Normal installed extension layout
87+
const normal = path.join(context.extensionPath, "src", "manage", "webviews");
88+
if (fs.existsSync(normal)) {
89+
return normal;
90+
}
91+
92+
// 2) Fallback for E2E tests under tests/internal/e2e/test/extension
93+
const marker = path.join("tests", "internal", "e2e", "test", "extension");
94+
const extPath = context.extensionPath;
95+
const idx = extPath.indexOf(marker);
96+
if (idx !== -1) {
97+
const repoRoot = extPath.slice(0, idx);
98+
const fallback = path.join(repoRoot, "src", "manage", "webviews");
99+
if (fs.existsSync(fallback)) {
100+
return fallback;
101+
}
102+
}
103+
104+
throw new Error(
105+
`Could not resolve webview base directory. Tried:\n` +
106+
` ${normal}\n` +
107+
(marker && extPath.indexOf(marker) !== -1
108+
? ` ${path.join(extPath.slice(0, extPath.indexOf(marker)), "src/manage/webviews")}\n`
109+
: "") +
110+
`Please ensure that 'src/manage/webviews' exists either under the extension path or under the repo root.`
111+
);
112+
}

src/manage/webviews/html/addTestsuite.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<h2>Add Testsuite to Compiler</h2>
1414
<label for="testsuiteInput">Testsuite Name:</label>
1515
<input
16-
aria-label="testSuiteInput"
16+
aria-label="Testsuite Input"
1717
type="text"
1818
id="testsuiteInput"
1919
placeholder="Enter Testsuite Name"

src/manage/webviews/html/newEnvProject.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ <h2>Create Environment in Project</h2>
6060
type="button"
6161
class="primary-button"
6262
id="btnSubmit"
63-
aria-label="OK"
63+
aria-label="Import OK"
6464
>OK</button>
6565
</div>
6666
</div>

tests/internal/e2e/test/specs/vcast_manage.test.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe("vTypeCheck VS Code Extension", () => {
234234
"Add existing Environment to Project"
235235
);
236236
console.log("Insert the path to the env file");
237-
await insertStringToInput(testInputManage, "envFileInput");
237+
await insertStringToInput(testInputManage, "Environment File Path");
238238

239239
const button = await $(`aria/OK`);
240240
await button.click();
@@ -421,7 +421,7 @@ describe("vTypeCheck VS Code Extension", () => {
421421
true,
422422
"Add Testsuite to Compiler"
423423
);
424-
await insertStringToInput("GreyBox", "testSuiteInput");
424+
await insertStringToInput("GreyBox", "Testsuite Input");
425425

426426
const button = await $(`aria/OK`);
427427
await button.click();
@@ -455,7 +455,6 @@ describe("vTypeCheck VS Code Extension", () => {
455455
console.log("Checking if Testsuite node is in tree");
456456
const testsuiteNode = await findTreeNodeAtLevel(2, "GreyBox");
457457
expect(testsuiteNode).toBeDefined();
458-
// Check for VSCODE info message?
459458
});
460459

461460
it("testing deleting a Testsuite", async () => {
@@ -482,7 +481,6 @@ describe("vTypeCheck VS Code Extension", () => {
482481
console.log("Checking if Testsuite node is not in Tree");
483482
const testsuiteNode = await findTreeNodeAtLevel(2, "GreyBox");
484483
expect(testsuiteNode).toBeUndefined();
485-
// Check for VSCODE info message?
486484
});
487485

488486
it("testing deleting a project Environment", async () => {
@@ -514,7 +512,6 @@ describe("vTypeCheck VS Code Extension", () => {
514512
console.log("Checking if Env node is in Tree");
515513
const testsuiteNode = await findTreeNodeAtLevel(3, "BAR");
516514
expect(testsuiteNode).toBeDefined();
517-
// Check for VSCODE info message?
518515
});
519516

520517
it("testing building a single project environment", async () => {
@@ -553,7 +550,6 @@ describe("vTypeCheck VS Code Extension", () => {
553550
console.log("Checking if Env node is in Tree");
554551
const testsuiteNode = await findTreeNodeAtLevel(3, "BAR");
555552
expect(testsuiteNode).toBeDefined();
556-
// Check for VSCODE info message?
557553
});
558554

559555
it("testing remove environment from testsuite", async () => {
@@ -582,7 +578,53 @@ describe("vTypeCheck VS Code Extension", () => {
582578
console.log("Checking if Env node is not in Tree");
583579
const testsuiteNode = await findTreeNodeAtLevel(3, "FREE-ENV");
584580
expect(testsuiteNode).toBeUndefined();
585-
// Check for VSCODE info message?
581+
});
582+
583+
it("testing deleting an environment from project", async () => {
584+
await updateTestID();
585+
await bottomBar.toggle(true);
586+
const outputView = await bottomBar.openOutputView();
587+
await outputView.clearText();
588+
589+
const notificationsCenter = await workbench.openNotificationsCenter();
590+
await notificationsCenter.clearAllNotifications();
591+
await executeContextMenuAction(
592+
3,
593+
"QUACK",
594+
true,
595+
"Delete Environment from Project"
596+
);
597+
598+
const notifications = await $("aria/Notifications");
599+
await notifications.click();
600+
const vcastNotificationSourceElement = await $(
601+
"aria/VectorCAST Test Explorer (Extension)"
602+
);
603+
const vcastNotification = await vcastNotificationSourceElement.$("..");
604+
await (await vcastNotification.$("aria/Delete")).click();
605+
606+
console.log("Checking for Output logs");
607+
await browser.waitUntil(
608+
async () =>
609+
(await outputView.getText())
610+
.toString()
611+
.includes(
612+
`manage: '-pTest.vcm -eQUACK --delete --force' returned exit code: 0`
613+
),
614+
{ timeout: TIMEOUT }
615+
);
616+
617+
await browser.waitUntil(
618+
async () =>
619+
(await outputView.getText())
620+
.toString()
621+
.includes(`Processing environment data for:`),
622+
{ timeout: TIMEOUT }
623+
);
624+
625+
console.log("Checking if Env node is not in Tree");
626+
const testsuiteNode = await findTreeNodeAtLevel(3, "QUACK");
627+
expect(testsuiteNode).toBeUndefined();
586628
});
587629

588630
it("testing creating an Env from Source Files", async () => {
@@ -620,7 +662,7 @@ describe("vTypeCheck VS Code Extension", () => {
620662
// Open the webview
621663
await webview.open();
622664

623-
const button = await $(`aria/importOk`);
665+
const button = await $(`aria/Import OK`);
624666
await button.click();
625667

626668
console.log("Checking for Output logs");

0 commit comments

Comments
 (0)