Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Perform minimal structural improvements #17

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

37 changes: 23 additions & 14 deletions e2e/pages/vscode.pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@ import { execSync } from 'child_process';
import { downloadLatestKAIPlugin } from '../utilities/download.utils';
import { getKAIPluginPath } from '../utilities/utils';

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 = getKAIPluginPath();
console.log(`Installing extension from VSIX file: ${vsixFilePath}`);
await LaunchVSCodePage.installExtensionFromVSIX(vsixFilePath);
if (vsixFilePath) {
console.log(`Installing extension from VSIX file: ${vsixFilePath}`);
await VSCode.installExtensionFromVSIX(vsixFilePath);
} else {
console.warn(
'VSIX_FILE_PATH environment variable is not set. Skipping extension installation.',
);
}

// Launch VSCode as an Electron app
const vscodeApp = await electron.launch({
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 @@ -41,14 +50,14 @@ class LaunchVSCodePage {
* This method is static because it is independent of the instance.
*/
private static async installExtensionFromVSIX(
vsixFilePath: string
vsixFilePath: string,
): Promise<void> {
await downloadLatestKAIPlugin();

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 @@ -83,4 +92,4 @@ class LaunchVSCodePage {
}
}

export { LaunchVSCodePage };
export { VSCode };
16 changes: 6 additions & 10 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: 'Konveyor' });
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
Loading