From 500a01c57b13432571e4d161af3928d1ac689223 Mon Sep 17 00:00:00 2001 From: Akash Singh Date: Thu, 7 Mar 2024 03:33:42 +0530 Subject: [PATCH] Tests on CI pipeline --- .github/workflows/publish.yml | 3 + out/extension.test.js | 195 +++++++++++++++++++++++++++++++++ out/extension.test.js.map | 1 + out/test/extension.test.js | 117 ++++++++++++++++++-- out/test/extension.test.js.map | 2 +- package-lock.json | 132 +++++++++++++++++++++- package.json | 4 +- src/test/extension.test.ts | 143 ++++++++++++++++++++++-- 8 files changed, 575 insertions(+), 22 deletions(-) create mode 100644 out/extension.test.js create mode 100644 out/extension.test.js.map diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 57ae1f2..dc59294 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,6 +19,9 @@ jobs: - name: Install dependencies run: npm install + + - name: Run Test Script + run: npm run test - name: Publish to Visual Studio Marketplace uses: HaaLeo/publish-vscode-extension@v1 diff --git a/out/extension.test.js b/out/extension.test.js new file mode 100644 index 0000000..103d30e --- /dev/null +++ b/out/extension.test.js @@ -0,0 +1,195 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const assert = __importStar(require("assert")); +const vscode = __importStar(require("vscode")); +suite('Extension Test Suite', () => { + test('Initial Test', () => { + assert.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); + test('Extension Commands Test', () => __awaiter(void 0, void 0, void 0, function* () { + const context = { + subscriptions: [], + extensionPath: '', + extensionUri: vscode.Uri.parse(''), + asAbsolutePath: () => '', + storagePath: '', + globalStoragePath: '', + logPath: '', + storageUri: vscode.Uri.parse(''), + globalStorageUri: vscode.Uri.parse(''), + logUri: vscode.Uri.parse(''), + extensionMode: vscode.ExtensionMode.Production, + extension: { + extensionPath: '', + id: '', + isActive: true, + packageJSON: {}, + activate: () => Promise.resolve(), + exports: {}, + extensionKind: vscode.ExtensionKind.UI, + extensionUri: vscode.Uri.parse(''), + }, + asWebviewUri: () => vscode.Uri.parse(''), + extensionRuntime: vscode.ExtensionRuntime.Node, + subscriptionsDisposed: false, + globalStorage: { + get: () => { }, + update: () => { }, + setKeysForSync: () => { }, + setValuesForSync: () => { }, + getKeysForSync: () => [], + getValuesForSync: () => [], + onDidChange: () => { }, + onDidChangeKeys: () => { }, + onDidChangeValues: () => { }, + dispose: () => { }, + }, + workspaceStatePath: '', + globalStatePath: '', + logPathFile: '', + storagePathFile: '', + globalStoragePathFile: '', + storageUriFile: vscode.Uri.parse(''), + globalStorageUriFile: vscode.Uri.parse(''), + logUriFile: vscode.Uri.parse(''), + workspaceStateFile: { + get: () => { }, + update: () => { }, + setKeysForSync: () => { }, + setValuesForSync: () => { }, + getKeysForSync: () => [], + getValuesForSync: () => [], + onDidChange: () => { }, + onDidChangeKeys: () => { }, + onDidChangeValues: () => { }, + dispose: () => { }, + }, + globalStateFile: { + get: () => { }, + update: () => { }, + setKeysForSync: () => { }, + setValuesForSync: () => { }, + getKeysForSync: () => [], + getValuesForSync: () => [], + onDidChange: () => { }, + onDidChangeKeys: () => { }, + onDidChangeValues: () => { }, + dispose: () => { }, + }, + extensionRuntimeFile: vscode.ExtensionRuntime.Node, + extensionFile: { + extensionPath: '', + id: '', + isActive: true, + packageJSON: {}, + activate: () => { }, + exports: {}, + extensionKind: vscode.ExtensionKind.UI, + }, + asWebviewUriFile: () => vscode.Uri.parse(''), + extensionModeFile: vscode.ExtensionMode.Production, + environmentVariableCollectionFile: { + replace: () => { }, + append: () => { }, + prepend: () => { }, + get: () => { }, + forEach: () => { }, + clear: () => { }, + delete: () => { }, + dispose: () => { }, + }, + extensionKind: vscode.ExtensionKind.UI, + }; + // Test 'heykeploy.HeyKeploy' command + const helloCommand = vscode.commands.getCommands().then((commands) => { + assert.ok(commands.includes('heykeploy.HeyKeploy')); + return vscode.commands.executeCommand('heykeploy.HeyKeploy'); + }); + yield helloCommand; + // Test 'heykeploy.KeployVersion' command + const versionCommand = vscode.commands.getCommands().then((commands) => { + assert.ok(commands.includes('heykeploy.KeployVersion')); + return vscode.commands.executeCommand('heykeploy.KeployVersion'); + }); + yield versionCommand; + // Test 'Keploy-Sidebar' view provider + const sidebarProvider = vscode.window.registerWebviewViewProvider('Keploy-Sidebar', { + resolveWebviewView: () => { + return { + webview: { + html: '', + onDidReceiveMessage: () => { }, + postMessage: () => { }, + asWebviewUri: () => vscode.Uri.parse(''), + cspSource: '', + options: {}, + state: {}, + dispose: () => { }, + }, + onDidChangeVisibility: () => { }, + onDidChangeViewState: () => { }, + title: '', + description: '', + webviewViewType: '', + visible: true, + active: true, + visibleRange: { + start: 0, + end: 0, + }, + dispose: () => { }, + }; + }, + }); + assert.ok(sidebarProvider); + })); +}); +// extension.test.ts +// import * as assert from 'assert'; +// import * as vscode from 'vscode'; +// suite('Extension Test Suite', () => { +// test('Initial Test', () => { +// assert.strictEqual(-1, [1, 2, 3].indexOf(5)); +// assert.strictEqual(-1, [1, 2, 3].indexOf(0)); +// }); +// test('Extension Commands Test', async () => { +// // Test your extension's functionality here +// await vscode.commands.executeCommand('heykeploy.KeployVersion'); +// await vscode.commands.executeCommand('heykeploy.HeyKeploy'); +// }); +// }); +// // extension.test.ts +//# sourceMappingURL=extension.test.js.map \ No newline at end of file diff --git a/out/extension.test.js.map b/out/extension.test.js.map new file mode 100644 index 0000000..49708d8 --- /dev/null +++ b/out/extension.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../src/extension.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,+CAAiC;AAGjC,KAAK,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACjC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;QACxB,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yBAAyB,EAAE,GAAS,EAAE;QACzC,MAAM,OAAO,GAA4B;YACvC,aAAa,EAAE,EAAE;YACjB,aAAa,EAAE,EAAE;YACjB,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAClC,cAAc,EAAE,GAAG,EAAE,CAAC,EAAE;YACx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IAC7B,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,oBAAoB;AAEpB,oCAAoC;AACpC,oCAAoC;AAEpC,wCAAwC;AACxC,iCAAiC;AACjC,oDAAoD;AACpD,oDAAoD;AACpD,QAAQ;AAER,kDAAkD;AAClD,kDAAkD;AAClD,uEAAuE;AACvE,mEAAmE;AAEnE,QAAQ;AACR,MAAM;AACN,uBAAuB"} \ No newline at end of file diff --git a/out/test/extension.test.js b/out/test/extension.test.js index 04257df..6892af4 100644 --- a/out/test/extension.test.js +++ b/out/test/extension.test.js @@ -22,17 +22,120 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); -const assert = __importStar(require("assert")); -// You can import and use all API from the 'vscode' module -// as well as import your extension to test it +// import * as assert from 'assert'; const vscode = __importStar(require("vscode")); -// import * as myExtension from '../../extension'; +const SidebarProvider_1 = require("../SidebarProvider"); +const assert_1 = require("assert"); +const sinon_1 = __importDefault(require("sinon")); +/// FakeWebview class for mocking +class FakeWebview { + constructor() { + this.html = ''; + } + // Mock implementation of asWebviewUri method + asWebviewUri(uri) { + return uri; + } + postMessage(_) { } + // Mock implementation of onDidReceiveMessage method + onDidReceiveMessage(listener) { + // Mock implementation + return { + dispose: () => { } // Empty dispose method for simplicity + }; + } +} +// FakeWebviewView class for mocking +class FakeWebviewView { + constructor(webview) { + this.webview = webview; + } + dispose() { } +} suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); test('Sample test', () => { - assert.strictEqual(-1, [1, 2, 3].indexOf(5)); - assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + assert_1.strict.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert_1.strict.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); + test('heykeploy.HeyKeploy command test', () => __awaiter(void 0, void 0, void 0, function* () { + // Mocking the vscode.window.showInformationMessage function + const showInformationMessage = vscode.window.showInformationMessage; + vscode.window.showInformationMessage = (message) => { + assert_1.strict.strictEqual(message, 'Hey Keploy Community!'); + return Promise.resolve(undefined); // Return a resolved Promise + }; + // Trigger the command + yield vscode.commands.executeCommand('heykeploy.HeyKeploy'); + // Restore original function + vscode.window.showInformationMessage = showInformationMessage; + })); + test('heykeploy.KeployVersion command test', () => __awaiter(void 0, void 0, void 0, function* () { + // Mocking the vscode.window.createWebviewPanel function + const createWebviewPanel = vscode.window.createWebviewPanel; + vscode.window.createWebviewPanel = (viewType, title, showOptions, options) => { + let viewColumn; + if (typeof showOptions === 'number') { + viewColumn = showOptions; // showOptions is of type vscode.ViewColumn + } + else { + viewColumn = showOptions.viewColumn; // showOptions is an object containing viewColumn + } + assert_1.strict.strictEqual(viewType, 'keployVersion'); + assert_1.strict.strictEqual(title, 'Keploy Version'); + assert_1.strict.strictEqual(viewColumn, vscode.ViewColumn.One); + return { + webview: { + html: '', // Mock empty HTML + }, + dispose: () => { }, // Mock dispose function + }; + }; + // Mocking the getKeployVersion function + const getKeployVersion = () => Promise.resolve('1.0.0'); + // Trigger the command + yield vscode.commands.executeCommand('heykeploy.KeployVersion'); + // Restore original function + vscode.window.createWebviewPanel = createWebviewPanel; + })); +}); +suite('Sidebar Test Suite', () => { + test('Sidebar Provider Registration', () => { + const extensionUri = vscode.Uri.parse('fake://extension'); + const sidebarProvider = new SidebarProvider_1.SidebarProvider(extensionUri); + const registerWebviewViewProviderSpy = sinon_1.default.spy(vscode.window, 'registerWebviewViewProvider'); + // Register the sidebar provider + vscode.window.registerWebviewViewProvider('Test-Sidebar', sidebarProvider); + // Ensure that registerWebviewViewProvider was called with the correct arguments + (0, assert_1.strict)(registerWebviewViewProviderSpy.calledOnce); + (0, assert_1.strict)(registerWebviewViewProviderSpy.calledWith('Test-Sidebar', sinon_1.default.match.instanceOf(SidebarProvider_1.SidebarProvider))); + // Clean up + registerWebviewViewProviderSpy.restore(); }); + test('Sidebar Content Rendering', () => __awaiter(void 0, void 0, void 0, function* () { + const extensionUri = vscode.Uri.parse('http://www.example.com/some/path'); + const sidebarProvider = new SidebarProvider_1.SidebarProvider(extensionUri); + const webview = new FakeWebview(); + const view = new FakeWebviewView(webview); + // Simulate the creation of the webview panel + sidebarProvider.resolveWebviewView(view); + // Ensure that the webview content is set correctly + assert_1.strict.strictEqual(webview.html.includes(''), true); + // assert.strictEqual(webview.html.includes(''), true); + // assert.strictEqual(webview.html.includes(''), true); + // assert.strictEqual(webview.html.includes(''), true); + })); }); //# sourceMappingURL=extension.test.js.map \ No newline at end of file diff --git a/out/test/extension.test.js.map b/out/test/extension.test.js.map index 5fe9345..16fff66 100644 --- a/out/test/extension.test.js.map +++ b/out/test/extension.test.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,0DAA0D;AAC1D,8CAA8C;AAC9C,+CAAiC;AACjC,kDAAkD;AAElD,KAAK,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;IAEzD,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;QACxB,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,+CAAiC;AACjC,wDAAqD;AACrD,mCAA0C;AAC1C,kDAA0B;AAG1B,iCAAiC;AACjC,MAAM,WAAW;IAAjB;QACS,SAAI,GAAW,EAAE,CAAC;IAe3B,CAAC;IAbC,6CAA6C;IACtC,YAAY,CAAC,GAAe;QACjC,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,WAAW,CAAC,CAAM,IAAI,CAAC;IAC9B,oDAAoD;IAC7C,mBAAmB,CAAC,QAAgC;QACzD,sBAAsB;QACtB,OAAO;YACL,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,sCAAsC;SACzD,CAAC;IACJ,CAAC;CACF;AAED,oCAAoC;AACpC,MAAM,eAAe;IAGnB,YAAY,OAAoB;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,OAAO,KAAK,CAAC;CAGrB;AAGD,KAAK,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACjC,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;QACvB,eAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,eAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC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AAC,GAAG,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAC1E,MAAM,eAAe,GAAG,IAAI,iCAAe,CAAC,YAAY,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAoB,CAAC;QACpD,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC,OAAO,CAAkC,CAAC;QAE3E,6CAA6C;QAC7C,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzC,mDAAmD;QACnD,eAAM,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,kFAAkF,CAAC,EAAG,IAAI,CAAC,CAAC;QACrI,kHAAkH;QAClH,2GAA2G;QAC3G,sGAAsG;IACxG,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 511578b..220256c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,14 @@ { "name": "heykeploy", - "version": "2.0.0", + "version": "2.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "heykeploy", - "version": "2.0.0", + "version": "2.0.2", "dependencies": { + "sinon": "^17.0.1", "svelte": "^4.2.12" }, "devDependencies": { @@ -18,6 +19,7 @@ "@tsconfig/svelte": "^1.0.0", "@types/mocha": "^10.0.6", "@types/node": "18.x", + "@types/sinon": "^17.0.3", "@types/vscode": "^1.86.0", "@typescript-eslint/eslint-plugin": "^6.19.1", "@typescript-eslint/parser": "^6.19.1", @@ -693,6 +695,45 @@ "win32" ] }, + "node_modules/@sinonjs/commons": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/fake-timers": { + "version": "11.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", + "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", + "dependencies": { + "@sinonjs/commons": "^3.0.0" + } + }, + "node_modules/@sinonjs/samsam": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", + "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", + "dependencies": { + "@sinonjs/commons": "^2.0.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + } + }, + "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/text-encoding": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", + "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==" + }, "node_modules/@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", @@ -752,6 +793,21 @@ "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", "dev": true }, + "node_modules/@types/sinon": { + "version": "17.0.3", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", + "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", + "dev": true, + "dependencies": { + "@types/sinonjs__fake-timers": "*" + } + }, + "node_modules/@types/sinonjs__fake-timers": { + "version": "8.1.5", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", + "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", + "dev": true + }, "node_modules/@types/vscode": { "version": "1.87.0", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.87.0.tgz", @@ -2011,7 +2067,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "engines": { "node": ">=8" } @@ -2315,6 +2370,11 @@ "setimmediate": "^1.0.5" } }, + "node_modules/just-extend": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", + "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==" + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -2372,6 +2432,11 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -2643,6 +2708,18 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "node_modules/nise": { + "version": "5.1.9", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.9.tgz", + "integrity": "sha512-qOnoujW4SV6e40dYxJOb3uvuoPHtmLzIk4TFo+j0jPJoC+5Z9xja5qH5JZobEPsa8+YYphMrOSwnrshEhG2qww==", + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^6.2.1" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -2784,6 +2861,11 @@ "node": "14 || >=16.14" } }, + "node_modules/path-to-regexp": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", + "integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==" + }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -3281,6 +3363,42 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/sinon": { + "version": "17.0.1", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-17.0.1.tgz", + "integrity": "sha512-wmwE19Lie0MLT+ZYNpDymasPHUKTaZHUH/pKEubRXIzySv9Atnlw+BUMGCzWgV7b7wO+Hw6f1TEOr0IUnmU8/g==", + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/samsam": "^8.0.0", + "diff": "^5.1.0", + "nise": "^5.1.5", + "supports-color": "^7.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/sinon" + } + }, + "node_modules/sinon/node_modules/diff": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", + "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/sinon/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -3675,6 +3793,14 @@ "node": ">= 0.8.0" } }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "engines": { + "node": ">=4" + } + }, "node_modules/type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", diff --git a/package.json b/package.json index 3c5bc21..cf832de 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "compile": "tsc -p ./", "rollup": "rollup -c --bundleConfigAsCjs", "watch": "rollup -c --bundleConfigAsCjs && tsc -watch -p ./", - "debug" : "tsc -watch -p ./", + "debug": "tsc -watch -p ./", "pretest": "npm run compile && npm run lint", "lint": "eslint src --ext ts", "test": "vscode-test" @@ -67,6 +67,7 @@ "@tsconfig/svelte": "^1.0.0", "@types/mocha": "^10.0.6", "@types/node": "18.x", + "@types/sinon": "^17.0.3", "@types/vscode": "^1.86.0", "@typescript-eslint/eslint-plugin": "^6.19.1", "@typescript-eslint/parser": "^6.19.1", @@ -81,6 +82,7 @@ "typescript": "^4.9.5" }, "dependencies": { + "sinon": "^17.0.1", "svelte": "^4.2.12" } } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 4ca0ab4..dcf9368 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -1,15 +1,138 @@ -import * as assert from 'assert'; - -// You can import and use all API from the 'vscode' module -// as well as import your extension to test it +// import * as assert from 'assert'; import * as vscode from 'vscode'; -// import * as myExtension from '../../extension'; +import { SidebarProvider } from '../SidebarProvider'; +import { strict as assert } from 'assert'; +import sinon from 'sinon'; + + +/// FakeWebview class for mocking +class FakeWebview { + public html: string = ''; + + // Mock implementation of asWebviewUri method + public asWebviewUri(uri: vscode.Uri): vscode.Uri { + return uri; + } + + public postMessage(_: any) { } + // Mock implementation of onDidReceiveMessage method + public onDidReceiveMessage(listener: (message: any) => void): vscode.Disposable { + // Mock implementation + return { + dispose: () => {} // Empty dispose method for simplicity + }; + } +} + +// FakeWebviewView class for mocking +class FakeWebviewView { + public webview: FakeWebview; + + constructor(webview: FakeWebview) { + this.webview = webview; + } + + public dispose() { } + + +} + suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); + test('Sample test', () => { + assert.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); + + test('heykeploy.HeyKeploy command test', async () => { + // Mocking the vscode.window.showInformationMessage function + const showInformationMessage = vscode.window.showInformationMessage; + vscode.window.showInformationMessage = (message: string) => { + assert.strictEqual(message, 'Hey Keploy Community!'); + return Promise.resolve(undefined); // Return a resolved Promise + }; + + // Trigger the command + await vscode.commands.executeCommand('heykeploy.HeyKeploy'); + + // Restore original function + vscode.window.showInformationMessage = showInformationMessage; + }); + + test('heykeploy.KeployVersion command test', async () => { + // Mocking the vscode.window.createWebviewPanel function + const createWebviewPanel = vscode.window.createWebviewPanel; + vscode.window.createWebviewPanel = ( + viewType: string, + title: string, + showOptions: vscode.ViewColumn | { readonly viewColumn: vscode.ViewColumn; readonly preserveFocus?: boolean | undefined; }, + options?: vscode.WebviewPanelOptions & vscode.WebviewOptions + ) => { + let viewColumn: vscode.ViewColumn; + if (typeof showOptions === 'number') { + viewColumn = showOptions; // showOptions is of type vscode.ViewColumn + } else { + viewColumn = showOptions.viewColumn; // showOptions is an object containing viewColumn + } + assert.strictEqual(viewType, 'keployVersion'); + assert.strictEqual(title, 'Keploy Version'); + assert.strictEqual(viewColumn, vscode.ViewColumn.One); + return { + webview: { + html: '', // Mock empty HTML + }, + dispose: () => { }, // Mock dispose function + } as vscode.WebviewPanel; + }; + + // Mocking the getKeployVersion function + const getKeployVersion = () => Promise.resolve('1.0.0'); + + // Trigger the command + await vscode.commands.executeCommand('heykeploy.KeployVersion'); + + // Restore original function + vscode.window.createWebviewPanel = createWebviewPanel; + }); +}); + + + +suite('Sidebar Test Suite', () => { + test('Sidebar Provider Registration', () => { + const extensionUri = vscode.Uri.parse('fake://extension'); + const sidebarProvider = new SidebarProvider(extensionUri); + + const registerWebviewViewProviderSpy = sinon.spy(vscode.window, 'registerWebviewViewProvider'); + + // Register the sidebar provider + vscode.window.registerWebviewViewProvider( + 'Test-Sidebar', + sidebarProvider + ); + + // Ensure that registerWebviewViewProvider was called with the correct arguments + assert(registerWebviewViewProviderSpy.calledOnce); + assert( + registerWebviewViewProviderSpy.calledWith( + 'Test-Sidebar', + sinon.match.instanceOf(SidebarProvider) + ) + ); + + // Clean up + registerWebviewViewProviderSpy.restore(); + }); + + test('Sidebar Content Rendering', async () => { + const extensionUri = vscode.Uri.parse('http://www.example.com/some/path'); + const sidebarProvider = new SidebarProvider(extensionUri); + const webview = new FakeWebview() as vscode.Webview; + const view = new FakeWebviewView(webview) as unknown as vscode.WebviewView; - test('Sample test', () => { - assert.strictEqual(-1, [1, 2, 3].indexOf(5)); - assert.strictEqual(-1, [1, 2, 3].indexOf(0)); - }); + // Simulate the creation of the webview panel + sidebarProvider.resolveWebviewView(view); + // Ensure that the webview content is set correctly + assert.strictEqual(webview.html.includes('') , true); + }); });