Skip to content

Commit 6228ac8

Browse files
committed
Added two new tests to try out
1 parent 986ab9f commit 6228ac8

File tree

6 files changed

+362
-3
lines changed

6 files changed

+362
-3
lines changed

.github/workflows/integration-tests.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ jobs:
5555
env:
5656
NODE_ENV: test
5757
ZEPHYR_BASE: /tmp/zephyr
58+
59+
- name: Run open current directory integration tests
60+
run: |
61+
xvfb-run -a node scripts/run-integration-tests.js open-current-dir
62+
env:
63+
NODE_ENV: test
64+
ZEPHYR_BASE: /tmp/zephyr
65+
66+
- name: Run workspace out of tree integration tests
67+
run: |
68+
xvfb-run -a node scripts/run-integration-tests.js out-of-tree
69+
env:
70+
NODE_ENV: test
71+
ZEPHYR_BASE: /tmp/zephyr

scripts/run-integration-tests.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ try {
4343
case 'zephyr-ide-git':
4444
grepPattern = '"Zephyr IDE Git Workspace Test Suite"';
4545
break;
46+
case 'open-current-dir':
47+
grepPattern = '"Open Current Directory Test Suite"';
48+
break;
49+
case 'out-of-tree':
50+
grepPattern = '"Workspace Out Of Tree Test Suite"';
51+
break;
4652
case 'all':
4753
default:
48-
grepPattern = '"Workspace Test Suite"';
54+
grepPattern = '"Test Suite"';
4955
break;
5056
}
5157

src/setup_utilities/workspace-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export async function workspaceSetupFromGit(context: vscode.ExtensionContext, ws
145145
await clearWorkspaceSetupContextFlags(context, wsConfig);
146146

147147
const gitUrl = await vscode.window.showInputBox({
148-
prompt: "Enter the Git repository URL for the Zephyr IDE workspace",
148+
prompt: "Enter the Git repository URL/clone string",
149149
placeHolder:
150150
"https://github.com/mylonics/zephyr-ide-workspace-template.git",
151151
ignoreFocusOut: true,
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
Copyright 2024 mylonics
3+
Author Rijesh Augustine
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import * as assert from "assert";
19+
import * as vscode from "vscode";
20+
import * as fs from "fs-extra";
21+
import * as path from "path";
22+
import * as os from "os";
23+
import { logTestEnvironment, monitorWorkspaceSetup } from "./test-runner";
24+
import { UIMockInterface, MockInteraction } from "./ui-mock-interface";
25+
26+
/*
27+
* OPEN CURRENT DIRECTORY INTEGRATION TEST:
28+
*
29+
* Tests the workspace setup from git with detected west.yml files:
30+
* 1. Setup workspace from git with --branch no_west_folder
31+
* 2. When prompted, choose detected west.yml file (not external install)
32+
* 3. Execute build
33+
*
34+
* This tests the scenario where a git repository contains west.yml files
35+
* and the user chooses to use the local west workspace rather than
36+
* an existing Zephyr installation.
37+
*
38+
* Git command: --branch no_west_folder -- https://github.com/mylonics/zephyr-ide-sample-project.git
39+
* UI Flow: "Use Local West Workspace" option when west.yml is detected
40+
*/
41+
42+
suite("Open Current Directory Test Suite", () => {
43+
let testWorkspaceDir: string;
44+
let originalWorkspaceFolders: readonly vscode.WorkspaceFolder[] | undefined;
45+
46+
suiteSetup(() => {
47+
logTestEnvironment();
48+
console.log("🔬 Testing open current directory workflow");
49+
});
50+
51+
setup(async () => {
52+
const existingWorkspace =
53+
vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
54+
testWorkspaceDir = existingWorkspace
55+
? path.join(existingWorkspace, "open-current-directory-test")
56+
: path.join(os.tmpdir(), "open-current-directory-test-" + Date.now());
57+
58+
await fs.ensureDir(testWorkspaceDir);
59+
60+
const mockWorkspaceFolder: vscode.WorkspaceFolder = {
61+
uri: vscode.Uri.file(testWorkspaceDir),
62+
name: path.basename(testWorkspaceDir),
63+
index: 0,
64+
};
65+
66+
originalWorkspaceFolders = vscode.workspace.workspaceFolders;
67+
Object.defineProperty(vscode.workspace, "workspaceFolders", {
68+
value: [mockWorkspaceFolder],
69+
configurable: true,
70+
});
71+
72+
vscode.workspace.getConfiguration = () =>
73+
({
74+
get: () => undefined,
75+
update: () => Promise.resolve(),
76+
has: () => false,
77+
inspect: (key: string) => ({
78+
key,
79+
defaultValue: undefined,
80+
globalValue: undefined,
81+
workspaceValue: undefined,
82+
workspaceFolderValue: undefined,
83+
}),
84+
} as any);
85+
86+
vscode.window.showInformationMessage = async () => undefined;
87+
vscode.window.showWarningMessage = async () => undefined;
88+
vscode.window.showErrorMessage = async () => undefined;
89+
});
90+
91+
teardown(async () => {
92+
if (originalWorkspaceFolders !== undefined) {
93+
Object.defineProperty(vscode.workspace, "workspaceFolders", {
94+
value: originalWorkspaceFolders,
95+
configurable: true,
96+
});
97+
}
98+
99+
if (testWorkspaceDir && (await fs.pathExists(testWorkspaceDir))) {
100+
await fs.remove(testWorkspaceDir);
101+
}
102+
});
103+
104+
test("Open Current Directory: Git Setup → Detect West.yml → Build", async function () {
105+
this.timeout(1800000);
106+
107+
console.log("🚀 Starting open current directory test...");
108+
109+
try {
110+
const extension = vscode.extensions.getExtension("mylonics.zephyr-ide");
111+
if (extension && !extension.isActive) {
112+
await extension.activate();
113+
}
114+
await new Promise((resolve) => setTimeout(resolve, 3000));
115+
116+
// Initialize UI Mock Interface
117+
const uiMock = new UIMockInterface();
118+
uiMock.activate();
119+
120+
console.log("🏗️ Step 1: Setting up workspace from git with west.yml detection...");
121+
// Prime the mock interface for git setup with branch argument
122+
uiMock.primeInteractions([
123+
{ type: 'input', value: '--branch no_west_folder -- https://github.com/mylonics/zephyr-ide-sample-project.git', description: 'Enter git clone string with branch' }
124+
]);
125+
126+
let result = await vscode.commands.executeCommand(
127+
"zephyr-ide.workspace-setup-from-git"
128+
);
129+
assert.ok(result, "Git workspace setup should succeed");
130+
131+
console.log("🔍 Step 2: Choosing detected west.yml file...");
132+
// Prime the mock interface for west.yml detection prompt
133+
uiMock.primeInteractions([
134+
{ type: 'quickpick', value: 'local-west', description: 'Choose Use Local West Workspace option' }
135+
]);
136+
137+
await monitorWorkspaceSetup("open current directory");
138+
139+
console.log("⚡ Step 3: Executing build...");
140+
// Wait for workspace setup to complete
141+
const ext = vscode.extensions.getExtension("mylonics.zephyr-ide");
142+
const wsConfig = ext?.exports?.getWorkspaceConfig();
143+
if (!wsConfig?.initialSetupComplete) {
144+
console.log("⚠️ Setup not complete, retrying in 10 seconds...");
145+
await new Promise((resolve) => setTimeout(resolve, 10000));
146+
}
147+
148+
result = await vscode.commands.executeCommand("zephyr-ide.build");
149+
assert.ok(result, "Build execution should succeed");
150+
151+
// Deactivate the UI Mock Interface
152+
uiMock.deactivate();
153+
154+
} catch (error) {
155+
console.error("❌ Open current directory test failed:", error);
156+
await new Promise((resolve) => setTimeout(resolve, 30000));
157+
throw error;
158+
}
159+
}).timeout(900000);
160+
161+
});
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
Copyright 2024 mylonics
3+
Author Rijesh Augustine
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import * as assert from "assert";
19+
import * as vscode from "vscode";
20+
import * as fs from "fs-extra";
21+
import * as path from "path";
22+
import * as os from "os";
23+
import { logTestEnvironment, monitorWorkspaceSetup } from "./test-runner";
24+
import { UIMockInterface, MockInteraction } from "./ui-mock-interface";
25+
26+
/*
27+
* WORKSPACE OUT OF TREE INTEGRATION TEST:
28+
*
29+
* Tests the out-of-tree workspace setup workflow:
30+
* 1. Setup workspace from git with --branch no_west
31+
* 2. When prompted, choose "Use Existing Zephyr Installation"
32+
* 3. Select "Global Installation" option
33+
* 4. Go through west selector process (minimal, stm32)
34+
* 5. Execute build
35+
*
36+
* This tests the scenario where a git repository does not contain
37+
* west.yml files and the user chooses to use an existing Zephyr
38+
* installation with global installation type.
39+
*
40+
* Git command: --branch no_west -- https://github.com/mylonics/zephyr-ide-sample-project.git
41+
* UI Flow: "Use Existing Zephyr Installation" → "Global Installation" → west selector
42+
*/
43+
44+
suite("Workspace Out Of Tree Test Suite", () => {
45+
let testWorkspaceDir: string;
46+
let originalWorkspaceFolders: readonly vscode.WorkspaceFolder[] | undefined;
47+
48+
suiteSetup(() => {
49+
logTestEnvironment();
50+
console.log("🔬 Testing workspace out of tree workflow");
51+
});
52+
53+
setup(async () => {
54+
const existingWorkspace =
55+
vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
56+
testWorkspaceDir = existingWorkspace
57+
? path.join(existingWorkspace, "workspace-out-of-tree-test")
58+
: path.join(os.tmpdir(), "workspace-out-of-tree-test-" + Date.now());
59+
60+
await fs.ensureDir(testWorkspaceDir);
61+
62+
const mockWorkspaceFolder: vscode.WorkspaceFolder = {
63+
uri: vscode.Uri.file(testWorkspaceDir),
64+
name: path.basename(testWorkspaceDir),
65+
index: 0,
66+
};
67+
68+
originalWorkspaceFolders = vscode.workspace.workspaceFolders;
69+
Object.defineProperty(vscode.workspace, "workspaceFolders", {
70+
value: [mockWorkspaceFolder],
71+
configurable: true,
72+
});
73+
74+
vscode.workspace.getConfiguration = () =>
75+
({
76+
get: () => undefined,
77+
update: () => Promise.resolve(),
78+
has: () => false,
79+
inspect: (key: string) => ({
80+
key,
81+
defaultValue: undefined,
82+
globalValue: undefined,
83+
workspaceValue: undefined,
84+
workspaceFolderValue: undefined,
85+
}),
86+
} as any);
87+
88+
vscode.window.showInformationMessage = async () => undefined;
89+
vscode.window.showWarningMessage = async () => undefined;
90+
vscode.window.showErrorMessage = async () => undefined;
91+
});
92+
93+
teardown(async () => {
94+
if (originalWorkspaceFolders !== undefined) {
95+
Object.defineProperty(vscode.workspace, "workspaceFolders", {
96+
value: originalWorkspaceFolders,
97+
configurable: true,
98+
});
99+
}
100+
101+
if (testWorkspaceDir && (await fs.pathExists(testWorkspaceDir))) {
102+
await fs.remove(testWorkspaceDir);
103+
}
104+
});
105+
106+
test("Workspace Out Of Tree: Git Setup → Use Existing → Global → West Selector → Build", async function () {
107+
this.timeout(1800000);
108+
109+
console.log("🚀 Starting workspace out of tree test...");
110+
111+
try {
112+
const extension = vscode.extensions.getExtension("mylonics.zephyr-ide");
113+
if (extension && !extension.isActive) {
114+
await extension.activate();
115+
}
116+
await new Promise((resolve) => setTimeout(resolve, 3000));
117+
118+
// Initialize UI Mock Interface
119+
const uiMock = new UIMockInterface();
120+
uiMock.activate();
121+
122+
console.log("🏗️ Step 1: Setting up workspace from git without west folder...");
123+
// Prime the mock interface for git setup with no_west branch
124+
uiMock.primeInteractions([
125+
{ type: 'input', value: '--branch no_west -- https://github.com/mylonics/zephyr-ide-sample-project.git', description: 'Enter git clone string for no_west branch' }
126+
]);
127+
128+
let result = await vscode.commands.executeCommand(
129+
"zephyr-ide.workspace-setup-from-git"
130+
);
131+
assert.ok(result, "Git workspace setup should succeed");
132+
133+
console.log("🔗 Step 2: Choosing existing Zephyr installation...");
134+
// Prime the mock interface for installation type selection
135+
uiMock.primeInteractions([
136+
{ type: 'quickpick', value: 'existing-install', description: 'Choose Use Existing Zephyr Installation option' }
137+
]);
138+
139+
console.log("🌐 Step 3: Selecting global installation...");
140+
// Prime the mock interface for global installation selection
141+
uiMock.primeInteractions([
142+
{ type: 'quickpick', value: 'global', description: 'Choose Global Installation option' }
143+
]);
144+
145+
console.log("⚙️ Step 4: Going through west selector process...");
146+
// Prime the mock interface for west selector (same as standard setup)
147+
uiMock.primeInteractions([
148+
{ type: 'quickpick', value: 'minimal', description: 'Select minimal manifest' },
149+
{ type: 'quickpick', value: 'stm32', description: 'Select STM32 toolchain' },
150+
{ type: 'quickpick', value: 'v4.2.0', description: 'Select default configuration' },
151+
{ type: 'input', value: '', description: 'Select additional west init args' }
152+
]);
153+
154+
await monitorWorkspaceSetup("workspace out of tree");
155+
156+
console.log("⚡ Step 5: Executing build...");
157+
// Wait for workspace setup to complete
158+
const ext = vscode.extensions.getExtension("mylonics.zephyr-ide");
159+
const wsConfig = ext?.exports?.getWorkspaceConfig();
160+
if (!wsConfig?.initialSetupComplete) {
161+
console.log("⚠️ Setup not complete, retrying in 10 seconds...");
162+
await new Promise((resolve) => setTimeout(resolve, 10000));
163+
}
164+
165+
result = await vscode.commands.executeCommand("zephyr-ide.build");
166+
assert.ok(result, "Build execution should succeed");
167+
168+
// Deactivate the UI Mock Interface
169+
uiMock.deactivate();
170+
171+
} catch (error) {
172+
console.error("❌ Workspace out of tree test failed:", error);
173+
await new Promise((resolve) => setTimeout(resolve, 30000));
174+
throw error;
175+
}
176+
}).timeout(900000);
177+
178+
});

src/test/zephyr-ide-git-workspace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ suite("Zephyr IDE Git Workspace Test Suite", () => {
121121
console.log("🏗️ Step 1: Setting up workspace from Zephyr IDE Git...");
122122
// Prime the mock interface for Zephyr IDE git workspace setup
123123
gitUiMock.primeInteractions([
124-
{ type: 'input', value: 'https://github.com/mylonics/zephyr-ide-sample-project.git', description: 'Enter Zephyr IDE git repo URL' }
124+
{ type: 'input', value: '--branch main -- https://github.com/mylonics/zephyr-ide-sample-project.git', description: 'Enter Zephyr IDE git repo URL' }
125125
]);
126126

127127
let result = await vscode.commands.executeCommand(

0 commit comments

Comments
 (0)