|
| 1 | +import * as assert from "assert"; |
| 2 | +import * as vscode from "vscode"; |
| 3 | +import * as path from "path"; |
| 4 | +import * as fs from "fs"; |
| 5 | +import * as os from "os"; |
| 6 | + |
| 7 | +import { execSync } from "child_process"; |
| 8 | + |
| 9 | +suite("Extension Integration", () => { |
| 10 | + test("Git branch detected in not-in-workspace file", async () => { |
| 11 | + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "git-commit-test-")); |
| 12 | + const commitMessage = path.join(tmpDir, "COMMIT_EDITMSG"); |
| 13 | + fs.writeFileSync(commitMessage, "Initial commit\n\nDetails here.\n"); |
| 14 | + |
| 15 | + // Create a repo and a branch that we can detect |
| 16 | + execSync("git init", { cwd: tmpDir }); |
| 17 | + execSync("git checkout -b test-branch", { cwd: tmpDir }); |
| 18 | + |
| 19 | + // Open the file in an editor |
| 20 | + const doc = await vscode.workspace.openTextDocument( |
| 21 | + vscode.Uri.file(commitMessage), |
| 22 | + ); |
| 23 | + await vscode.window.showTextDocument(doc); |
| 24 | + |
| 25 | + // Wait for extension activation to complete |
| 26 | + const ext = vscode.extensions.getExtension( |
| 27 | + "walles.git-commit-message-plus", |
| 28 | + )!; |
| 29 | + await ext.activate(); |
| 30 | + |
| 31 | + // Wait (up to ~2s) for async branch detection to populate gitBranch |
| 32 | + const deadline = Date.now() + 2000; |
| 33 | + let actualBranch: string | undefined = ext.exports.gitBranch; |
| 34 | + while (!actualBranch && Date.now() < deadline) { |
| 35 | + await new Promise((r) => globalThis.setTimeout(r, 50)); |
| 36 | + actualBranch = ext.exports.gitBranch; |
| 37 | + } |
| 38 | + |
| 39 | + assert.strictEqual(actualBranch, "test-branch"); |
| 40 | + |
| 41 | + // Clean up |
| 42 | + fs.rmSync(tmpDir, { recursive: true, force: true }); |
| 43 | + }); |
| 44 | +}); |
0 commit comments