Skip to content

Commit

Permalink
Merge pull request konveyor#27 from sshveta/start_analyzer
Browse files Browse the repository at this point in the history
[RFR] Method to clone coolstore repo and open vscode with it

Signed-off-by: midays <[email protected]>
  • Loading branch information
midays committed Nov 13, 2024
2 parents f1e3793 + 94c9c00 commit 3a33be2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
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.`);
}
}
Empty file added kai-client-ci/report/index.css
Empty file.
Empty file added kai-client-ci/report/index.html
Empty file.
Empty file.

0 comments on commit 3a33be2

Please sign in to comment.