Skip to content

Commit

Permalink
Merge branch 'main' into recorcd-test
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush3160 authored Sep 23, 2024
2 parents 86ef088 + 43d50e2 commit 3cd9089
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 53 deletions.
45 changes: 5 additions & 40 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, win32]
arch: [x64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -22,49 +18,18 @@ jobs:
with:
node-version: '18'

# Install npm dependencies based on the architecture
- name: Install dependencies
run: |
if [ "${{ matrix.arch }}" == "arm64" ]; then
npm_config_arch=arm64 npm install --build-from-source
else
npm_config_arch=x64 npm install --build-from-source
fi
run: npm install

- name: Run Rollup for Compilation
- name: Run Rollup
run: npm run rollupci

- name: List Compiled Files (Debugging)
- name: List contents of out/compiled directory (for debugging)
run: ls -R out/compiled

- name: Install vsce
run: npm install -g @vscode/vsce

- name: Package VSIX for Target Platform
run: |
case "${{ matrix.os }}" in
linux) vsce package --target linux-${{ matrix.arch }} ;;
darwin) vsce package --target darwin-${{ matrix.arch }} ;;
win32) vsce package --target win32-${{ matrix.arch }} ;;
esac
- name: Capture VSIX Filename
id: capture_vsix_file
run: |
VSIX_FILE=$(ls *.vsix)
echo "VSIX_FILE=$VSIX_FILE" >> $GITHUB_ENV
shell: bash

- name: Print VSIX Filename
id: print_vsix_file
run: |
echo "Generated package for OS ${{ matrix.os }} and architecture ${{ matrix.arch }}:"
ls *.vsix

- name: Publish to Visual Studio Marketplace
uses: HaaLeo/publish-vscode-extension@v1
with:
pat: ${{ secrets.VS_MARKETPLACE_TOKEN }}
packagePath: ${{ env.VSIX_FILE }}
registryUrl: https://marketplace.visualstudio.com
skipDuplicate: true
skipDuplicate: true
2 changes: 1 addition & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
files: 'out/*.test.js',
});
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ First Release for Vs Code Extension.
## [1.0.14]

- Back button refactored for better User Experience

## [1.0.15]

- Reverting to universal release
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "keployio",
"displayName": "Keploy",
"description": "Streamline testing with the power of Keploy, directly in your favorite IDE.",
"version": "1.0.14",
"version": "1.0.15",
"publisher": "Keploy",
"icon": "media/logo.png",
"pricing": "Free",
Expand Down
141 changes: 130 additions & 11 deletions src/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,134 @@
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 assert = require('assert');
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
import sinon from 'sinon';
import { SidebarProvider } from './SidebarProvider';

const createMockExtensionContext = (): vscode.ExtensionContext => ({
subscriptions: [],
extensionPath: '/mock/path',
extensionUri: vscode.Uri.parse('file:///mock/path'),
globalState: {
get: sinon.stub(),
update: sinon.stub(),
},
workspaceState: {
get: sinon.stub(),
update: sinon.stub(),
},
asAbsolutePath: sinon.stub().returns('/mock/absolute/path'),
storagePath: '/mock/storage/path',
globalStoragePath: '/mock/global/storage/path',
logPath: '/mock/log/path',
} as unknown as vscode.ExtensionContext);

// Mock classes for FakeWebview and FakeWebviewView to simulate behavior
class FakeWebview implements vscode.Webview {
public html = '';
public options = {};
public cspSource = '';
public onDidReceiveMessage = sinon.spy();
public asWebviewUri(uri: vscode.Uri): vscode.Uri {
return uri;
}
public postMessage(message: any): Thenable<boolean> {
this.onDidReceiveMessage(message); // Trigger the spy with the message
return Promise.resolve(true);
}
}

class FakeWebviewView implements vscode.WebviewView {
constructor(public webview: vscode.Webview) {}
viewType: any;
badge?: vscode.ViewBadge | undefined;
show(preserveFocus?: boolean): void {
throw new Error('Method not implemented.');
}
public title = '';
public description = '';
public onDidDispose = sinon.spy();
public onDidChangeVisibility = sinon.spy();
public onDidChangeViewState = sinon.spy();
public visible = true;
public dispose() {}
}

suite('Sidebar Test Suite', () => {

let mockContext: vscode.ExtensionContext;
let extensionUri: vscode.Uri;

setup(() => {
mockContext = createMockExtensionContext();
extensionUri = vscode.Uri.parse('http://www.example.com/some/path');
});

test('Sidebar Provider Registration', () => {
const sidebarProvider = new SidebarProvider(extensionUri, mockContext);

const registerWebviewViewProviderSpy = sinon.spy(vscode.window, 'registerWebviewViewProvider');

vscode.window.registerWebviewViewProvider('Test-Sidebar', sidebarProvider);

assert(registerWebviewViewProviderSpy.calledOnce);
assert(
registerWebviewViewProviderSpy.calledWith(
'Test-Sidebar',
sinon.match.instanceOf(SidebarProvider)
)
);

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
registerWebviewViewProviderSpy.restore();
});


test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
test('Sidebar Content Rendering', async () => {
const sidebarProvider = new SidebarProvider(extensionUri, mockContext);
const webview = new FakeWebview() as vscode.Webview;
const view = new FakeWebviewView(webview) as vscode.WebviewView;

await sidebarProvider.resolveWebviewView(view);

assert.strictEqual(
webview.html.includes('<link href="http://www.example.com/some/path/media/vscode.css" rel="stylesheet">'),
true
);
// Clean up

});

test('Sidebar Comprehensive Functionality', async () => {
const sidebarProvider = new SidebarProvider(extensionUri, mockContext);
const webview = new FakeWebview() as vscode.Webview;
const view = new FakeWebviewView(webview) as unknown as vscode.WebviewView;

await sidebarProvider.resolveWebviewView(view);

// Simulate the creation of the webview panel
assert.strictEqual(webview.html.includes('<!DOCTYPE html>'), true, 'DOCTYPE is missing');
assert.strictEqual(webview.html.includes('<html lang="en">'), true, 'HTML tag is missing');
assert.strictEqual(webview.html.includes('<head>'), true, 'Head tag is missing');
assert.strictEqual(webview.html.includes('<meta charset="UTF-8">'), true, 'UTF-8 charset meta tag is missing');
assert.strictEqual(webview.html.includes('<meta http-equiv="Content-Security-Policy"'), true, 'Content Security Policy meta tag is missing');
assert.strictEqual(webview.html.includes('<meta name="viewport"'), true, 'Viewport meta tag is missing');

// Test if all required stylesheets are being loaded
assert.strictEqual(webview.html.includes('http://www.example.com/some/path/media/reset.css'), true, 'Reset CSS is missing');
assert.strictEqual(webview.html.includes('http://www.example.com/some/path/media/vscode.css'), true, 'VS Code CSS is missing');
assert.strictEqual(webview.html.includes('http://www.example.com/some/path/sidebar/sidebar.css'), true, 'Sidebar CSS is missing');
assert.strictEqual(webview.html.includes('http://www.example.com/some/path/out/compiled/Config.css'), true, 'Config CSS is missing');

// Test if Google Fonts are being loaded
assert.strictEqual(webview.html.includes('https://fonts.googleapis.com'), true, 'Google Fonts preconnect is missing');
assert.strictEqual(webview.html.includes('https://fonts.gstatic.com'), true, 'Google Fonts static preconnect is missing');
assert.strictEqual(webview.html.includes('https://fonts.googleapis.com/css2?family=Baloo+2:[email protected]&display=swap'), true, 'Baloo 2 font is missing');

// Clean up

});


});
function expect(count: any) {
throw new Error('Function not implemented.');
}

0 comments on commit 3cd9089

Please sign in to comment.