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

[RFR] Method to clone coolstore repo and open vscode with it #27

Merged
merged 2 commits into from
Nov 13, 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
20 changes: 16 additions & 4 deletions e2e/pages/vscode.pages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
_electron as electron,
ElectronApplication,
Frame,
FrameLocator,
Page,
} from 'playwright';
import { execSync } from 'child_process';
import { downloadLatestKAIPlugin } from '../utilities/download.utils';
import { getKAIPluginName } from '../utilities/utils';
import * as path from 'path';

class VSCode {
private readonly vscodeApp?: ElectronApplication;
Expand All @@ -19,10 +19,22 @@ class VSCode {
}

/**
* launches VSCode with KAI plugin installed.
* launches VSCode with KAI plugin installed and coolstore app opened.
* @param executablePath path to the vscode binary
* @param repoUrl coolstore app to be cloned
* @param cloneDir path to repo
*/
public static async init(executablePath: string): Promise<VSCode> {
public static async init(
executablePath: string,
repoUrl: string,
cloneDir: string
): Promise<VSCode> {
try {
execSync(`git clone ${repoUrl}`);
} catch (error) {
throw new Error('Failed to clone the repository');
}

try {
const vsixFilePath = getKAIPluginName();
if (vsixFilePath) {
Expand All @@ -37,10 +49,10 @@ class VSCode {
// Launch VSCode as an Electron app
const vscodeApp = await electron.launch({
executablePath: executablePath,
args: [path.resolve(cloneDir)],
});

const window = await vscodeApp.firstWindow();

return new VSCode(vscodeApp, window);
} catch (error) {
console.error('Error launching VSCode:', error);
Expand Down
10 changes: 9 additions & 1 deletion e2e/tests/vscode.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { test, expect } from '@playwright/test';
import { VSCode } from '../pages/vscode.pages';
import { cleanupRepo } from '../utilities/utils';

// TODO : Get repo URL from fixtures
const repoUrl = 'https://github.com/konveyor-ecosystem/coolstore';

test.describe('VSCode Tests', () => {
let vscodeApp: VSCode;
Expand All @@ -8,7 +12,7 @@ test.describe('VSCode Tests', () => {
test.setTimeout(60000);
const executablePath =
process.env.VSCODE_EXECUTABLE_PATH || '/usr/share/code/code';
vscodeApp = await VSCode.init(executablePath);
vscodeApp = await VSCode.init(executablePath, repoUrl, 'coolstore');
});

test('Should launch VSCode and check window title', async () => {
Expand All @@ -28,4 +32,8 @@ test.describe('VSCode Tests', () => {
}
await window.screenshot({ path: 'kai-installed-screenshot.png' });
});

test.afterAll(async () => {
await cleanupRepo();
});
});
19 changes: 19 additions & 0 deletions e2e/utilities/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import * as os from 'os';
import * as fs from 'fs';
import * as util from 'util';
import { exec } from 'child_process';
import * as path from 'path';

const execPromise = util.promisify(exec);
const repoDir = path.resolve('coolstore');

// Function to get OS information
export function getOSInfo(): string {
Expand All @@ -21,3 +28,15 @@ export function getKAIPluginName(): string {
process.env.VSIX_FILE_NAME || 'konveyor-linux-0.0.1.vsix';
return vsixFileName.replace(/(konveyor-)(\w+)(-.*)/, `$1${getOSInfo()}$3`);
}

export async function cleanupRepo() {
if (fs.existsSync(repoDir)) {
try {
await execPromise(`rm -rf "${repoDir}"`);
} catch (error) {
console.error('Error while cleaning up cloned repository:', error);
}
} else {
console.warn(`Directory ${repoDir} does not exist, skipping cleanup.`);
}
}