From aee0663da267c45722552a0b4991fccfbc35273e Mon Sep 17 00:00:00 2001 From: Shveta Sachdeva Date: Mon, 11 Nov 2024 15:40:48 -0800 Subject: [PATCH 1/2] Method to clone coolstore repo and open vscode with it Signed-off-by: Shveta Sachdeva --- e2e/pages/vscode.pages.ts | 20 ++++++++++++++++---- e2e/tests/vscode.test.ts | 10 +++++++++- e2e/utilities/utils.ts | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/e2e/pages/vscode.pages.ts b/e2e/pages/vscode.pages.ts index 9e4420a..dfc1bee 100644 --- a/e2e/pages/vscode.pages.ts +++ b/e2e/pages/vscode.pages.ts @@ -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; @@ -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 { + public static async init( + executablePath: string, + repoUrl: string, + cloneDir: string + ): Promise { + try { + execSync(`git clone ${repoUrl}`); + } catch (error) { + throw new Error('Failed to clone the repository'); + } + try { const vsixFilePath = getKAIPluginName(); if (vsixFilePath) { @@ -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); diff --git a/e2e/tests/vscode.test.ts b/e2e/tests/vscode.test.ts index 37f04f6..672f13b 100644 --- a/e2e/tests/vscode.test.ts +++ b/e2e/tests/vscode.test.ts @@ -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; @@ -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 () => { @@ -28,4 +32,8 @@ test.describe('VSCode Tests', () => { } await window.screenshot({ path: 'kai-installed-screenshot.png' }); }); + + test.afterAll(async () => { + cleanupRepo(); + }); }); diff --git a/e2e/utilities/utils.ts b/e2e/utilities/utils.ts index 4e07181..0862980 100644 --- a/e2e/utilities/utils.ts +++ b/e2e/utilities/utils.ts @@ -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 { @@ -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.`); + } +} From 94c9c0011b8097a5c77f32e3a365b204af8d3739 Mon Sep 17 00:00:00 2001 From: Shveta Sachdeva Date: Mon, 11 Nov 2024 15:47:49 -0800 Subject: [PATCH 2/2] Method to clone coolstore repo and open vscode with it Signed-off-by: Shveta Sachdeva --- e2e/tests/vscode.test.ts | 2 +- e2e/utilities/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/tests/vscode.test.ts b/e2e/tests/vscode.test.ts index 672f13b..85280aa 100644 --- a/e2e/tests/vscode.test.ts +++ b/e2e/tests/vscode.test.ts @@ -34,6 +34,6 @@ test.describe('VSCode Tests', () => { }); test.afterAll(async () => { - cleanupRepo(); + await cleanupRepo(); }); }); diff --git a/e2e/utilities/utils.ts b/e2e/utilities/utils.ts index 0862980..5a0b940 100644 --- a/e2e/utilities/utils.ts +++ b/e2e/utilities/utils.ts @@ -32,7 +32,7 @@ export function getKAIPluginName(): string { export async function cleanupRepo() { if (fs.existsSync(repoDir)) { try { - await execPromise("rm -rf '${repoDir}'"); + await execPromise(`rm -rf "${repoDir}"`); } catch (error) { console.error('Error while cleaning up cloned repository:', error); }