|
| 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 | +}); |
0 commit comments