cypress-qase-reporter 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +6 -0
- package/dist/fileSearcher.d.ts +11 -0
- package/dist/fileSearcher.js +63 -0
- package/dist/reporter.d.ts +2 -7
- package/dist/reporter.js +31 -32
- package/package.json +1 -1
package/changelog.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class FileSearcher {
|
|
2
|
+
/**
|
|
3
|
+
* Finds all files in the given directory and its subdirectories
|
|
4
|
+
* that were created after the specified time.
|
|
5
|
+
*
|
|
6
|
+
* @param folderPath Relative path to the folder.
|
|
7
|
+
* @param time Time threshold as a Date object.
|
|
8
|
+
* @returns Array of absolute paths to the matching files.
|
|
9
|
+
*/
|
|
10
|
+
static findFilesBeforeTime(folderPath: string, time: Date): string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.FileSearcher = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
class FileSearcher {
|
|
30
|
+
/**
|
|
31
|
+
* Finds all files in the given directory and its subdirectories
|
|
32
|
+
* that were created after the specified time.
|
|
33
|
+
*
|
|
34
|
+
* @param folderPath Relative path to the folder.
|
|
35
|
+
* @param time Time threshold as a Date object.
|
|
36
|
+
* @returns Array of absolute paths to the matching files.
|
|
37
|
+
*/
|
|
38
|
+
static findFilesBeforeTime(folderPath, time) {
|
|
39
|
+
const absolutePath = path.resolve(process.cwd(), folderPath);
|
|
40
|
+
const result = [];
|
|
41
|
+
const searchFiles = (dir) => {
|
|
42
|
+
if (!fs.existsSync(dir)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
const entryPath = path.join(dir, entry.name);
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
searchFiles(entryPath);
|
|
50
|
+
}
|
|
51
|
+
else if (entry.isFile()) {
|
|
52
|
+
const stats = fs.statSync(entryPath);
|
|
53
|
+
if (stats.birthtime > time) {
|
|
54
|
+
result.push(entryPath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
searchFiles(absolutePath);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.FileSearcher = FileSearcher;
|
package/dist/reporter.d.ts
CHANGED
|
@@ -25,13 +25,6 @@ export declare class CypressQaseReporter extends reporters.Base {
|
|
|
25
25
|
* @private
|
|
26
26
|
*/
|
|
27
27
|
private static getCaseId;
|
|
28
|
-
/**
|
|
29
|
-
* @param {number[]} ids
|
|
30
|
-
* @param {string} dir
|
|
31
|
-
* @returns {Attachment[]}
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
private static findAttachments;
|
|
35
28
|
/**
|
|
36
29
|
* @type {string | undefined}
|
|
37
30
|
* @private
|
|
@@ -42,6 +35,7 @@ export declare class CypressQaseReporter extends reporters.Base {
|
|
|
42
35
|
* @private
|
|
43
36
|
*/
|
|
44
37
|
private reporter;
|
|
38
|
+
private testBeginTime;
|
|
45
39
|
private options;
|
|
46
40
|
/**
|
|
47
41
|
* @param {Runner} runner
|
|
@@ -65,6 +59,7 @@ export declare class CypressQaseReporter extends reporters.Base {
|
|
|
65
59
|
* @private
|
|
66
60
|
*/
|
|
67
61
|
private getSignature;
|
|
62
|
+
private getTestFileName;
|
|
68
63
|
/**
|
|
69
64
|
* @param {Suite} suite
|
|
70
65
|
* @private
|
package/dist/reporter.js
CHANGED
|
@@ -9,10 +9,10 @@ const uuid_1 = require("uuid");
|
|
|
9
9
|
const child_process_1 = require("child_process");
|
|
10
10
|
const mocha_1 = require("mocha");
|
|
11
11
|
const qase_javascript_commons_1 = require("qase-javascript-commons");
|
|
12
|
-
const traverse_dir_1 = require("./utils/traverse-dir");
|
|
13
12
|
const configSchema_1 = require("./configSchema");
|
|
14
13
|
const manager_1 = require("./metadata/manager");
|
|
15
|
-
const
|
|
14
|
+
const fileSearcher_1 = require("./fileSearcher");
|
|
15
|
+
const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING, EVENT_RUN_END, EVENT_TEST_BEGIN, } = mocha_1.Runner.constants;
|
|
16
16
|
/**
|
|
17
17
|
* @class CypressQaseReporter
|
|
18
18
|
* @extends reporters.Base
|
|
@@ -27,32 +27,6 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
|
|
|
27
27
|
const [, ids] = title.match(CypressQaseReporter.qaseIdRegExp) ?? [];
|
|
28
28
|
return ids ? ids.split(',').map((id) => Number(id)) : [];
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
31
|
-
* @param {number[]} ids
|
|
32
|
-
* @param {string} dir
|
|
33
|
-
* @returns {Attachment[]}
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
static findAttachments(ids, dir) {
|
|
37
|
-
const idSet = new Set(ids);
|
|
38
|
-
const attachments = [];
|
|
39
|
-
try {
|
|
40
|
-
(0, traverse_dir_1.traverseDir)(path_1.default.join(process.cwd(), dir), (filePath) => {
|
|
41
|
-
if (CypressQaseReporter.getCaseId(filePath).some((item) => idSet.has(item))) {
|
|
42
|
-
attachments.push({
|
|
43
|
-
content: '',
|
|
44
|
-
id: (0, uuid_1.v4)(),
|
|
45
|
-
mime_type: '', size: 0,
|
|
46
|
-
file_name: path_1.default.basename(filePath),
|
|
47
|
-
file_path: filePath,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
catch (error) { /* ignore */
|
|
53
|
-
}
|
|
54
|
-
return attachments;
|
|
55
|
-
}
|
|
56
30
|
/**
|
|
57
31
|
* @param {Runner} runner
|
|
58
32
|
* @param {CypressQaseOptionsType} options
|
|
@@ -60,6 +34,7 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
|
|
|
60
34
|
*/
|
|
61
35
|
constructor(runner, options, configLoader = new qase_javascript_commons_1.ConfigLoader(configSchema_1.configSchema)) {
|
|
62
36
|
super(runner, options);
|
|
37
|
+
this.testBeginTime = Date.now();
|
|
63
38
|
const { reporterOptions } = options;
|
|
64
39
|
const config = configLoader.load();
|
|
65
40
|
const { framework, ...composedOptions } = (0, qase_javascript_commons_1.composeOptions)(reporterOptions, config);
|
|
@@ -81,6 +56,9 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
|
|
|
81
56
|
runner.on(EVENT_TEST_PASS, (test) => this.addTestResult(test));
|
|
82
57
|
runner.on(EVENT_TEST_PENDING, (test) => this.addTestResult(test));
|
|
83
58
|
runner.on(EVENT_TEST_FAIL, (test) => this.addTestResult(test));
|
|
59
|
+
runner.on(EVENT_TEST_BEGIN, () => {
|
|
60
|
+
this.testBeginTime = Date.now();
|
|
61
|
+
});
|
|
84
62
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
85
63
|
runner.once(EVENT_RUN_END, () => {
|
|
86
64
|
const results = this.reporter.getResults();
|
|
@@ -104,10 +82,19 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
|
|
|
104
82
|
return;
|
|
105
83
|
}
|
|
106
84
|
const ids = CypressQaseReporter.getCaseId(test.title);
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
85
|
+
const testFile = this.getTestFileName(test);
|
|
86
|
+
const files = this.screenshotsFolder ?
|
|
87
|
+
fileSearcher_1.FileSearcher.findFilesBeforeTime(path_1.default.join(this.screenshotsFolder, testFile), new Date(this.testBeginTime))
|
|
88
|
+
: [];
|
|
89
|
+
const attachments = files.map((file) => ({
|
|
90
|
+
content: '',
|
|
91
|
+
id: (0, uuid_1.v4)(),
|
|
92
|
+
mime_type: 'image/png',
|
|
93
|
+
size: 0,
|
|
94
|
+
file_name: path_1.default.basename(file),
|
|
95
|
+
file_path: file,
|
|
96
|
+
}));
|
|
97
|
+
attachments.push(...(metadata?.attachments ?? []));
|
|
111
98
|
let relations = {};
|
|
112
99
|
if (test.parent !== undefined) {
|
|
113
100
|
const data = [];
|
|
@@ -196,6 +183,18 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
|
|
|
196
183
|
}
|
|
197
184
|
return signature;
|
|
198
185
|
}
|
|
186
|
+
getTestFileName(test) {
|
|
187
|
+
if (!test.parent) {
|
|
188
|
+
return '';
|
|
189
|
+
}
|
|
190
|
+
const file = this.getFile(test.parent);
|
|
191
|
+
if (!file) {
|
|
192
|
+
return '';
|
|
193
|
+
}
|
|
194
|
+
const pathParts = file.split('/');
|
|
195
|
+
const fileName = pathParts[pathParts.length - 1];
|
|
196
|
+
return fileName ? fileName : '';
|
|
197
|
+
}
|
|
199
198
|
/**
|
|
200
199
|
* @param {Suite} suite
|
|
201
200
|
* @private
|