Skip to content

Commit

Permalink
Merge pull request #465 from gilbysunil14/archive-screenshots-gha
Browse files Browse the repository at this point in the history
Archive screenshots in GHA
  • Loading branch information
gilbysunil14 authored Feb 4, 2025
2 parents 8e8bf85 + 435a09c commit 7233e87
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/run-regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ jobs:
# Build the plugin.
- name: 'Test: RunTests'
run: bash ./src/test/resources/ci/scripts/exec.sh TEST ${{ matrix.targetVSCode }}

# Archive screenshots
- name: Archive screenshots
if: always()
uses: actions/[email protected]
with:
name: liberty-run-tests-screenshots-${{ runner.os }}-${{ matrix.targetVSCode }}
path: ./screenshots/*.png
if-no-files-found: warn
retention-days: 7
35 changes: 34 additions & 1 deletion src/test/MavenTestDevModeActions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect } from 'chai';
import { InputBox, Workbench,SideBarView, ViewItem, ViewSection,EditorView, DefaultTreeItem , DebugView } from 'vscode-extension-tester';
import { InputBox, Workbench,SideBarView, ViewItem, ViewSection,EditorView, DefaultTreeItem , DebugView, VSBrowser } from 'vscode-extension-tester';
import * as utils from './utils/testUtils';
import * as constants from './definitions/constants';
import path = require('path');
import * as fs from 'fs';

describe('Devmode action tests for Maven Project', () => {
let sidebar: SideBarView;
Expand Down Expand Up @@ -273,6 +274,38 @@ it('attach debugger for start with custom parameter event', async () => {
expect(attachStatus).to.be.true;
}).timeout(350000);

/**
* 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.
* The MavenTestDevModeAction is the last test file that will be executed. Hence the after hook placed here
* ensures that all the screenshots will be copied to a known permanent location in the project folder.
*/
after(() => {
const sourcePath = VSBrowser.instance.getScreenshotsDir();
const destinationPath = './screenshots';

copyFolderContents(sourcePath, destinationPath);
});

function copyFolderContents(sourceFolder: string, destinationFolder: string): void {
if (!fs.existsSync(sourceFolder)) {
return;
}

if (!fs.existsSync(destinationFolder)) {
fs.mkdirSync(destinationFolder);
}

const files = fs.readdirSync(sourceFolder);
for (const file of files) {
const sourcePath = path.join(sourceFolder, file);
const destinationPath = path.join(destinationFolder, file);

if (fs.statSync(sourcePath).isDirectory()) {
copyFolderContents(sourcePath, destinationPath);
} else {
fs.copyFileSync(sourcePath, destinationPath);
}
}
}
});

6 changes: 4 additions & 2 deletions src/test/resources/ci/scripts/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ main() {
if [ $OS = "Darwin" ]; then
chown -R runner src/test/resources/maven
chown -R runner src/test/resources/gradle
npm run test-mac-maven -- -u
# Gradle tests should be run before Maven tests because the after hook for copying the screeshots from temporary to a permananet location is written in the Maven tests so that the copying will be done at the end of every test cases.
npm run test-mac-gradle -- -u
npm run test-mac-maven -- -u
else
npm run test -- -u
fi
Expand All @@ -75,8 +76,9 @@ main() {
if [ $OS = "Darwin" ]; then
chown -R runner src/test/resources/maven
chown -R runner src/test/resources/gradle
npm run test-mac-maven -- -u -c $VSCODE_VERSION_TO_RUN
# Gradle tests should be run before Maven tests because the after hook for copying the screeshots from temporary to a permananet location is written in the Maven tests so that the copying will be done at the end of every test cases.
npm run test-mac-gradle -- -u -c $VSCODE_VERSION_TO_RUN
npm run test-mac-maven -- -u -c $VSCODE_VERSION_TO_RUN

else
npm run test -- -u -c $VSCODE_VERSION_TO_RUN
Expand Down

0 comments on commit 7233e87

Please sign in to comment.