|
| 1 | +import * as assert from "node:assert"; |
| 2 | +import * as path from "node:path"; |
| 3 | +import * as vscode from "vscode"; |
| 4 | + |
| 5 | +/** |
| 6 | + * Bootstrap e2e tests. Everything here is read-only and machine-agnostic: |
| 7 | + * `mise bootstrap` is never executed (only definition navigation and command |
| 8 | + * registration are exercised), the fixture entries point at resources that do |
| 9 | + * not exist anywhere, and the suite isolates the machine's global mise config |
| 10 | + * via MISE_GLOBAL_CONFIG_FILE (see .vscode-test.js), so results are identical |
| 11 | + * on macOS (dev machines) and Linux (CI). |
| 12 | + */ |
| 13 | +suite("Bootstrap Test Suite", function () { |
| 14 | + this.timeout(30_000); |
| 15 | + |
| 16 | + let workspaceRoot: string; |
| 17 | + let miseTomlDocument: vscode.TextDocument; |
| 18 | + |
| 19 | + const lineOf = (text: string): number => { |
| 20 | + for (let i = 0; i < miseTomlDocument.lineCount; i++) { |
| 21 | + if (miseTomlDocument.lineAt(i).text.includes(text)) { |
| 22 | + return i; |
| 23 | + } |
| 24 | + } |
| 25 | + assert.fail(`Line containing "${text}" not found in fixture`); |
| 26 | + }; |
| 27 | + |
| 28 | + const openDefinition = async (tablePath: string[], key: string) => { |
| 29 | + await vscode.commands.executeCommand("mise.openBootstrapEntryDefinition", { |
| 30 | + label: key, |
| 31 | + state: "missing", |
| 32 | + definition: { tablePath, key }, |
| 33 | + }); |
| 34 | + const editor = vscode.window.activeTextEditor; |
| 35 | + assert.ok(editor, "An editor should be opened"); |
| 36 | + return editor; |
| 37 | + }; |
| 38 | + |
| 39 | + suiteSetup(async () => { |
| 40 | + const root = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; |
| 41 | + assert.ok(root, "Workspace root should be available"); |
| 42 | + workspaceRoot = root; |
| 43 | + |
| 44 | + const extension = vscode.extensions.getExtension("hverlin.mise-vscode"); |
| 45 | + assert.ok(extension, "Extension should be available"); |
| 46 | + await extension.activate(); |
| 47 | + |
| 48 | + miseTomlDocument = await vscode.workspace.openTextDocument( |
| 49 | + path.join(workspaceRoot, "mise.toml"), |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + test("bootstrap commands are registered", async () => { |
| 54 | + const commands = await vscode.commands.getCommands(true); |
| 55 | + for (const command of [ |
| 56 | + "mise.runBootstrap", |
| 57 | + "mise.runBootstrapDryRun", |
| 58 | + "mise.showBootstrap", |
| 59 | + "mise.openBootstrapEntryDefinition", |
| 60 | + ]) { |
| 61 | + assert.ok( |
| 62 | + commands.includes(command), |
| 63 | + `Command ${command} should be registered`, |
| 64 | + ); |
| 65 | + } |
| 66 | + }); |
| 67 | + |
| 68 | + test("navigates to a [bootstrap.repos] entry declaration", async () => { |
| 69 | + const editor = await openDefinition( |
| 70 | + ["bootstrap", "repos"], |
| 71 | + "vendor/mise-e2e-repo", |
| 72 | + ); |
| 73 | + |
| 74 | + assert.ok( |
| 75 | + editor.document.fileName.endsWith("mise.toml"), |
| 76 | + `Should open mise.toml, got ${editor.document.fileName}`, |
| 77 | + ); |
| 78 | + assert.equal( |
| 79 | + editor.selection.start.line, |
| 80 | + lineOf('"vendor/mise-e2e-repo"'), |
| 81 | + "Selection should be on the repo declaration line", |
| 82 | + ); |
| 83 | + }); |
| 84 | + |
| 85 | + test("navigates to a [dotfiles] entry declaration", async () => { |
| 86 | + const editor = await openDefinition( |
| 87 | + ["dotfiles"], |
| 88 | + "~/.mise-vscode-e2e-dotfile", |
| 89 | + ); |
| 90 | + |
| 91 | + assert.equal( |
| 92 | + editor.selection.start.line, |
| 93 | + lineOf('"~/.mise-vscode-e2e-dotfile"'), |
| 94 | + "Selection should be on the dotfile declaration line", |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + test("navigates to a [bootstrap.macos.defaults] key declaration", async () => { |
| 99 | + const editor = await openDefinition( |
| 100 | + ["bootstrap", "macos", "defaults", "com.example.mise-vscode-e2e"], |
| 101 | + "ExampleKey", |
| 102 | + ); |
| 103 | + |
| 104 | + assert.equal( |
| 105 | + editor.selection.start.line, |
| 106 | + lineOf("ExampleKey"), |
| 107 | + "Selection should be on the defaults key line", |
| 108 | + ); |
| 109 | + }); |
| 110 | + |
| 111 | + test("navigates to a [bootstrap.macos.finder] shorthand declaration", async () => { |
| 112 | + // mise resolves `[bootstrap.macos.finder] show_pathbar` to |
| 113 | + // `com.apple.finder ShowPathbar` in status output; navigation must find |
| 114 | + // the shorthand declaration via the alternates |
| 115 | + await vscode.commands.executeCommand("mise.openBootstrapEntryDefinition", { |
| 116 | + label: "com.apple.finder ShowPathbar", |
| 117 | + state: "unset", |
| 118 | + definition: { |
| 119 | + tablePath: ["bootstrap", "macos", "defaults", "com.apple.finder"], |
| 120 | + key: "ShowPathbar", |
| 121 | + }, |
| 122 | + alternates: [ |
| 123 | + { tablePath: ["bootstrap", "macos", "finder"], key: "show_pathbar" }, |
| 124 | + ], |
| 125 | + }); |
| 126 | + const editor = vscode.window.activeTextEditor; |
| 127 | + assert.ok(editor, "An editor should be opened"); |
| 128 | + |
| 129 | + assert.equal( |
| 130 | + editor.selection.start.line, |
| 131 | + lineOf("show_pathbar"), |
| 132 | + "Selection should be on the shorthand declaration line", |
| 133 | + ); |
| 134 | + }); |
| 135 | + |
| 136 | + test("falls back to the enclosing table when the key does not exist", async () => { |
| 137 | + const editor = await openDefinition( |
| 138 | + ["bootstrap", "macos", "defaults", "com.example.mise-vscode-e2e"], |
| 139 | + "KeyThatDoesNotExist", |
| 140 | + ); |
| 141 | + |
| 142 | + assert.equal( |
| 143 | + editor.selection.start.line, |
| 144 | + lineOf('"com.example.mise-vscode-e2e"'), |
| 145 | + "Selection should fall back to the domain table declaration", |
| 146 | + ); |
| 147 | + }); |
| 148 | + |
| 149 | + test("does not throw for an entry declared nowhere", async () => { |
| 150 | + await vscode.commands.executeCommand("mise.openBootstrapEntryDefinition", { |
| 151 | + label: "ghost", |
| 152 | + state: "missing", |
| 153 | + definition: { tablePath: ["bootstrap", "repos"], key: "does/not-exist" }, |
| 154 | + }); |
| 155 | + }); |
| 156 | + |
| 157 | + test("show bootstrap status webview opens without error", async () => { |
| 158 | + await vscode.commands.executeCommand("mise.showBootstrap"); |
| 159 | + }); |
| 160 | +}); |
0 commit comments