Skip to content

Commit b068feb

Browse files
committed
Add screenshot archiving to Gradle tests, move logic to testUtils
1 parent 671f760 commit b068feb

3 files changed

Lines changed: 50 additions & 28 deletions

File tree

src/test/GradleTestDevModeActions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { InputBox, Workbench, SideBarView, ViewSection, EditorView, DefaultTreeI
77
import * as utils from './utils/testUtils';
88
import * as constants from './definitions/constants';
99
import { logger } from './utils/testLogger';
10+
import * as fs from 'fs';
11+
import { VSBrowser } from 'vscode-extension-tester';
1012
import path = require('path');
1113

1214
describe('Devmode action tests for Gradle Project', () => {
@@ -447,4 +449,11 @@ describe('Devmode action tests for Gradle Project', () => {
447449
throw error;
448450
}
449451
}).timeout(100000);
452+
453+
/**
454+
* The following after hook copies the screenshot from the temporary folder in which it is saved to a known permanent location in the project folder.
455+
*/
456+
after(() => {
457+
utils.copyScreenshotsToProjectFolder('gradle');
458+
});
450459
});

src/test/MavenTestDevModeActions.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -468,36 +468,9 @@ describe('Devmode action tests for Maven Project', () => {
468468

469469
/**
470470
* The following after hook copies the screenshot from the temporary folder in which it is saved to a known permanent location in the project folder.
471-
* The MavenTestDevModeAction is the last test file that will be executed. Hence the after hook placed here
472-
* ensures that all the screenshots will be copied to a known permanent location in the project folder.
473471
*/
474472
after(() => {
475-
const sourcePath = VSBrowser.instance.getScreenshotsDir();
476-
const destinationPath = './screenshots';
477-
478-
copyFolderContents(sourcePath, destinationPath);
473+
utils.copyScreenshotsToProjectFolder('maven');
479474
});
480-
481-
function copyFolderContents(sourceFolder: string, destinationFolder: string): void {
482-
if (!fs.existsSync(sourceFolder)) {
483-
return;
484-
}
485-
486-
if (!fs.existsSync(destinationFolder)) {
487-
fs.mkdirSync(destinationFolder);
488-
}
489-
490-
const files = fs.readdirSync(sourceFolder);
491-
for (const file of files) {
492-
const sourcePath = path.join(sourceFolder, file);
493-
const destinationPath = path.join(destinationFolder, file);
494-
495-
if (fs.statSync(sourcePath).isDirectory()) {
496-
copyFolderContents(sourcePath, destinationPath);
497-
} else {
498-
fs.copyFileSync(sourcePath, destinationPath);
499-
}
500-
}
501-
}
502475
});
503476

src/test/utils/testUtils.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,44 @@ export async function clearCommandPalette() {
182182
const buttons = await dialog.getButtons();
183183
expect(buttons.length).equals(2);
184184
await dialog.pushButton('Clear');
185+
}
186+
187+
/**
188+
* Copies screenshots from the temporary VSCode screenshots directory to a permanent location
189+
* organized by build tool (maven or gradle).
190+
* @param buildTool The build tool name ('maven' or 'gradle') to organize screenshots
191+
*/
192+
export function copyScreenshotsToProjectFolder(buildTool: string): void {
193+
const VSBrowser = require('vscode-extension-tester').VSBrowser;
194+
const sourcePath = VSBrowser.instance.getScreenshotsDir();
195+
const destinationPath = path.join('./screenshots', buildTool);
196+
197+
copyFolderContents(sourcePath, destinationPath);
198+
}
199+
200+
/**
201+
* Recursively copies all files from source folder to destination folder.
202+
* @param sourceFolder Source directory path
203+
* @param destinationFolder Destination directory path
204+
*/
205+
function copyFolderContents(sourceFolder: string, destinationFolder: string): void {
206+
if (!fs.existsSync(sourceFolder)) {
207+
return;
208+
}
209+
210+
if (!fs.existsSync(destinationFolder)) {
211+
fs.mkdirSync(destinationFolder, { recursive: true });
212+
}
213+
214+
const files = fs.readdirSync(sourceFolder);
215+
for (const file of files) {
216+
const sourcePath = path.join(sourceFolder, file);
217+
const destinationPath = path.join(destinationFolder, file);
218+
219+
if (fs.statSync(sourcePath).isDirectory()) {
220+
copyFolderContents(sourcePath, destinationPath);
221+
} else {
222+
fs.copyFileSync(sourcePath, destinationPath);
223+
}
224+
}
185225
}

0 commit comments

Comments
 (0)