From e1c02d5bcc7d39d01c0982a50a103375723fea3f Mon Sep 17 00:00:00 2001 From: Aleksey Selihov <1+faumaray@noreply@void.com> Date: Sat, 5 Dec 2026 09:21:17 +0000 Subject: [PATCH] test: execute the extension against a mocked VS Code API --- package.json | 1 + test/extension.test.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/extension.test.js diff --git a/package.json b/package.json index e869e33..9354e90 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "categories": ["Other"], "activationEvents": [], "main": "./extension.js", + "scripts": {"test": "node test/extension.test.js"}, "contributes": { "commands": [{"command":"vbs.build","title":"VBS: Build"},{"command":"vbs.test","title":"VBS: Test"},{"command":"vbs.install","title":"VBS: Install"},{"command":"vbs.package","title":"VBS: Package (installer)"},{"command":"vbs.daemonStart","title":"VBS: Start Daemon"},{"command":"vbs.daemonStatus","title":"VBS: Daemon Status"}] } diff --git a/test/extension.test.js b/test/extension.test.js new file mode 100644 index 0000000..daa4fad --- /dev/null +++ b/test/extension.test.js @@ -0,0 +1,37 @@ +// Minimal VS Code API mock: records terminal commands without launching VS Code. +const Module = require('module'); +const registered = new Map(); +const terminals = []; +const vscodeMock = { + window: { + createTerminal: ({ name }) => ({ + name, + show() {}, + sendText(text) { terminals.push({ name, text }); }, + }), + }, + commands: { + registerCommand: (id, fn) => { registered.set(id, fn); return { dispose() {} }; }, + }, + workspace: { workspaceFolders: [{ uri: { fsPath: '/tmp/vbs-workspace' } }] }, +}; +const originalLoad = Module._load; +Module._load = function (request) { + if (request === 'vscode') return vscodeMock; + return originalLoad.apply(this, arguments); +}; +const extension = require('../extension.js'); +const context = { subscriptions: [] }; +extension.activate(context); +for (const [id, fn] of registered) fn(); +if (registered.size !== 6) throw new Error('expected 6 commands, got ' + registered.size); +if (terminals.length !== registered.size) throw new Error('every command must open a terminal'); +const build = terminals.find((t) => t.name === 'VBS: Build'); +if (!build) throw new Error('build command missing'); +if (!build.text.includes('build')) throw new Error('build args missing: ' + build.text); +if (!build.text.includes('--project /tmp/vbs-workspace')) + throw new Error('workspace project not injected: ' + build.text); +const install = terminals.find((t) => t.name === 'VBS: Install'); +if (!install || !install.text.includes('--prefix')) throw new Error('install prefix missing'); +extension.deactivate(); +console.log('extension tests passed: ' + terminals.length + ' commands');