Skip to content

Commit

Permalink
perform minimal structural improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Brugarolas <[email protected]>
  • Loading branch information
Alejandro Brugarolas committed Oct 21, 2024
1 parent 9255d4a commit 9293e89
Show file tree
Hide file tree
Showing 9 changed files with 1,284 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,10 @@ Network Trash Folder
Temporary Items
.apdisk

*.icloud
*.icloud

.env

node_modules/
playwright-report/
test-results/
59 changes: 59 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/kai-ci.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions e2e/pages/vscode.pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@ import { _electron as electron, ElectronApplication, Page } from 'playwright';
import { execSync } from 'child_process';
import * as fs from 'fs';

class LaunchVSCodePage {
private vscodeApp?: ElectronApplication;
private window?: Page;
class VSCode {
private readonly vscodeApp?: ElectronApplication;
private readonly window?: Page;

private constructor(vscodeApp: ElectronApplication, window: Page) {
this.vscodeApp = vscodeApp;
this.window = window;
}

public static async launchVSCode(
executablePath: string
): Promise<LaunchVSCodePage> {
/**
* Installs kai extensions from the VSIX path configured in the .env file and
* launches VSCode
* @param executablePath path to the vscode binary
*/
public static async init(
executablePath: string,
): Promise<VSCode> {
try {
const vsixFilePath = process.env.VSIX_FILE_PATH;
if (vsixFilePath) {
console.log(`Installing extension from VSIX file: ${vsixFilePath}`);
await LaunchVSCodePage.installExtensionFromVSIX(vsixFilePath);
await VSCode.installExtensionFromVSIX(vsixFilePath);
} else {
console.warn(
'VSIX_FILE_PATH environment variable is not set. Skipping extension installation.'
'VSIX_FILE_PATH environment variable is not set. Skipping extension installation.',
);
}

Expand All @@ -30,11 +35,9 @@ class LaunchVSCodePage {
executablePath: executablePath,
});

// Get the main window
const window = await vscodeApp.firstWindow();

// Return an instance of LaunchVSCodePage
return new LaunchVSCodePage(vscodeApp, window);
return new VSCode(vscodeApp, window);
} catch (error) {
console.error('Error launching VSCode:', error);
throw error;
Expand All @@ -46,7 +49,7 @@ class LaunchVSCodePage {
* This method is static because it is independent of the instance.
*/
private static async installExtensionFromVSIX(
vsixFilePath: string
vsixFilePath: string,
): Promise<void> {
if (!fs.existsSync(vsixFilePath)) {
throw new Error(`VSIX file not found at path: ${vsixFilePath}`);
Expand All @@ -55,7 +58,7 @@ class LaunchVSCodePage {
try {
// Execute command to install VSIX file using VSCode CLI
console.log(`Installing extension from ${vsixFilePath}...`);
execSync(`code --install-extension ${vsixFilePath}`, {
execSync(`code --install-extension '${vsixFilePath}'`, {
stdio: 'inherit',
});
console.log('Extension installed successfully.');
Expand Down Expand Up @@ -90,4 +93,4 @@ class LaunchVSCodePage {
}
}

export { LaunchVSCodePage };
export { VSCode };
18 changes: 7 additions & 11 deletions e2e/tests/vscode.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import { test, expect } from '@playwright/test';
import { LaunchVSCodePage } from '../pages/vscode.pages';
import { VSCode } from '../pages/vscode.pages';

test.describe('VSCode Tests', () => {
let vscodeApp: LaunchVSCodePage;
let vscodeApp: VSCode;

test.beforeAll(async () => {
const executablePath =
process.env.VSCODE_EXECUTABLE_PATH || '/usr/share/code/code';
vscodeApp = await LaunchVSCodePage.launchVSCode(executablePath);
vscodeApp = await VSCode.init(executablePath);
});

test.afterAll(async () => {
await vscodeApp.closeVSCode();
});

test('should launch VSCode and check window title', async () => {
test('Should launch VSCode and check window title', async () => {
const window = vscodeApp.getWindow();
const title = await window.title();
expect(title).toContain('Visual Studio Code');
});

test('should open Extensions tab and verify installed extension', async () => {
test('Should open Extensions tab and verify installed extension', async () => {
const window = vscodeApp.getWindow();
const kaiTab = await window.getByRole('tab', { name: 'KAI', exact: true });
const kaiTab = window.getByRole('tab', {name: 'KAI', exact: true});
await kaiTab.click();
// Assert if KAI explorer is opened.
const title = await window.getByRole('heading', {
const title = window.getByRole('heading', {
name: 'KAI',
exact: true,
});
Expand Down
Loading

0 comments on commit 9293e89

Please sign in to comment.