Skip to content

Commit

Permalink
Added code changes for project detection
Browse files Browse the repository at this point in the history
  • Loading branch information
SuparnaSuresh committed Nov 4, 2024
1 parent f062164 commit 33e5f92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
15 changes: 5 additions & 10 deletions src/test/GradleTestDevModeActionsWSProjectNameInit.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { WebDriver, VSBrowser } from 'vscode-extension-tester';
import * as utils from './utils/testUtils';



describe('Open Gradle Project - Project name with space', () => {

let driver: WebDriver;
utils.renameProject();

before(() => {
utils.renameProject();
driver = VSBrowser.instance.driver;

});

it('Open Sample Gradle Project - Project name with space', async () => {

await VSBrowser.instance.openResources(utils.getNewGradleProjectNameWithSpace());

}).timeout(25000);


it('Open Sample Gradle Project - Project name with space', async () => {
await utils.delay(8000);
await VSBrowser.instance.openResources(utils.getNewGradleProjectNameWithSpace());
}).timeout(25000);
});


32 changes: 7 additions & 25 deletions src/test/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ export async function clearCommandPalette() {
* Function return project name with space
*/
export function getNewGradleProjectNameWithSpace(): any {

const gradleProjectPath = path.join(__dirname, "..","..","..","src", "test","resources","gradleproject", "liberty.gradle.te st.wrapper.app");

console.log("Gradle project path is: "+gradleProjectPath);
const gradleProjectPath = path.join(__dirname, "..","..","..","src","test","resources","gradleproject", "liberty.gradle.te st.wrapper.app");

return gradleProjectPath;
}

Expand All @@ -210,48 +208,32 @@ export function getNewGradleProjectNameWithSpace(): any {
*/

export async function renameProject(): Promise<void>{

const currentDir =path.join(__dirname, "..","..","..",'/src/test/resources/gradleproject');
const sourcurrentDir = path.join(__dirname, "..","..","..",'src/test/resources/gradle');

const sourceFilePath = path.join(sourcurrentDir, 'liberty.gradle.test.wrapper.app');
const newFilePath = path.join(currentDir,'liberty.gradle.te st.wrapper.app');

console.log('Source Path:', sourceFilePath);
console.log('Destination Path:', newFilePath);

fsextra.copy(sourceFilePath,newFilePath)
.then(()=> console.log("coppied"))
fsextra.copy(getGradleProjectPath(),getNewGradleProjectNameWithSpace())
.then(()=> console.log("Project renamed., Gradle Project path is :"+getNewGradleProjectNameWithSpace()))
.catch(err => console.log("Error renaming the project"));
}

/**
* Remove newly created Project folder with content
*/

export async function removeProjectFolder(projectPath: string): Promise<void> {
try {
/* Read all files and subdirectories in the folder */
await fs.accessSync(projectPath);
const projectFiles = await fs.readdirSync(projectPath);

/* Remove each file and subdirectory */
await Promise.all(
projectFiles.map(async (projectFile) => {
const projectFilePath = path.join(projectPath, projectFile);
const stats = await fs.lstatSync(projectFilePath); // Use lstat from fs/promises
const stats = await fs.lstatSync(projectFilePath);

if (stats.isDirectory()) {
/* Recursively remove subdirectory */
await removeProjectFolder(projectFilePath);
} else {
/* Remove file */
await fs.unlinkSync(projectFilePath);
}
})
);

/* Remove the now-empty directory */
await fs.rmdirSync(projectPath);
// console.log(`Successfully removed Project folder: ${projectPath}`);
} catch (error) {
console.error(`Error removing project folder: ${error}`);
}
Expand Down

0 comments on commit 33e5f92

Please sign in to comment.