Skip to content

Commit f9cb1a7

Browse files
committed
fix: resolved issue with attaching screenshots for failed tests in subdirectories
- Added recursive folder search by a specified name. - Screenshots for failed tests are now correctly attached, even if the tests are located in subdirectories.
1 parent 20c04d3 commit f9cb1a7

File tree

6 files changed

+78
-10
lines changed

6 files changed

+78
-10
lines changed

examples/cypressCucumber/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"cypress": "^13.16.0",
99
"cypress-cucumber-preprocessor": "^4.3.1",
1010
"cypress-multi-reporters": "^1.6.3",
11-
"cypress-qase-reporter": "2.2.5"
11+
"cypress-qase-reporter": "^2.2.5"
1212
},
1313
"cypress-cucumber-preprocessor": {
1414
"step_definitions": "cypress/step_definitions/"

package-lock.json

Lines changed: 33 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

qase-cypress/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
3+
## What's new
4+
5+
Fixed an issue where screenshots for failed tests were not attached if the tests were located in subdirectories.
6+
17
28

39
## What's new

qase-cypress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cypress-qase-reporter",
3-
"version": "2.2.5",
3+
"version": "2.2.6",
44
"description": "Qase Cypress Reporter",
55
"homepage": "https://github.com/qase-tms/qase-javascript",
66
"sideEffects": false,

qase-cypress/src/fileSearcher.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ export class FileSearcher {
66
* Finds all files in the given directory and its subdirectories
77
* that were created after the specified time.
88
*
9-
* @param folderPath Relative path to the folder.
9+
* @param screenshotFolderPath Path to the folder with screenshots.
10+
* @param specFileName Name of the spec file.
1011
* @param time Time threshold as a Date object.
1112
* @returns Array of absolute paths to the matching files.
1213
*/
13-
public static findFilesBeforeTime(folderPath: string, time: Date): string[] {
14-
const absolutePath = path.resolve(process.cwd(), folderPath);
14+
public static findFilesBeforeTime(screenshotFolderPath: string, specFileName: string, time: Date): string[] {
15+
const absolutePath = path.resolve(process.cwd(), screenshotFolderPath);
1516
const result: string[] = [];
1617

18+
const paths = this.findFolderByName(absolutePath, specFileName);
19+
if (paths.length === 0) {
20+
return result;
21+
}
22+
1723
const searchFiles = (dir: string) => {
1824
if (!fs.existsSync(dir)) {
1925
return;
@@ -34,7 +40,33 @@ export class FileSearcher {
3440
}
3541
};
3642

37-
searchFiles(absolutePath);
43+
for (const path of paths) {
44+
searchFiles(path);
45+
}
46+
47+
return result;
48+
}
49+
50+
private static findFolderByName(startPath: string, folderName: string): string[] {
51+
const result: string[] = [];
52+
53+
function searchDirectory(currentPath: string): void {
54+
const items = fs.readdirSync(currentPath, { withFileTypes: true });
55+
56+
for (const item of items) {
57+
const itemPath = path.join(currentPath, item.name);
58+
59+
if (item.isDirectory()) {
60+
if (item.name === folderName) {
61+
result.push(itemPath);
62+
} else {
63+
searchDirectory(itemPath);
64+
}
65+
}
66+
}
67+
}
68+
69+
searchDirectory(startPath);
3870
return result;
3971
}
4072
}

qase-cypress/src/reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class CypressQaseReporter extends reporters.Base {
158158

159159
const testFileName = this.getTestFileName(test);
160160
const files = this.screenshotsFolder ?
161-
FileSearcher.findFilesBeforeTime(path.join(this.screenshotsFolder, testFileName), new Date(this.testBeginTime))
161+
FileSearcher.findFilesBeforeTime(this.screenshotsFolder, testFileName, new Date(this.testBeginTime))
162162
: [];
163163

164164
const attachments = files.map((file) => ({

0 commit comments

Comments
 (0)