@testomatio/reporter 2.3.0-beta.5-links → 2.3.0
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/lib/adapter/codecept.js +2 -0
- package/lib/adapter/cucumber/current.js +2 -0
- package/lib/adapter/jest.js +2 -0
- package/lib/adapter/playwright.js +2 -0
- package/lib/adapter/webdriver.js +7 -8
- package/lib/client.js +1 -32
- package/lib/data-storage.js +5 -5
- package/lib/reporter-functions.d.ts +10 -3
- package/lib/reporter-functions.js +13 -4
- package/lib/reporter.d.ts +16 -14
- package/lib/reporter.js +3 -1
- package/lib/services/artifacts.d.ts +1 -1
- package/lib/services/key-values.d.ts +1 -1
- package/lib/services/labels.d.ts +0 -22
- package/lib/services/labels.js +0 -62
- package/lib/services/links.d.ts +1 -1
- package/lib/services/logger.d.ts +1 -1
- package/package.json +1 -1
- package/src/adapter/codecept.js +3 -0
- package/src/adapter/cucumber/current.js +2 -0
- package/src/adapter/jest.js +2 -0
- package/src/adapter/playwright.js +2 -0
- package/src/adapter/webdriver.js +8 -8
- package/src/client.js +1 -31
- package/src/data-storage.js +5 -6
- package/src/reporter-functions.js +16 -8
- package/src/reporter.js +2 -0
- package/src/services/labels.js +0 -58
package/lib/adapter/codecept.js
CHANGED
|
@@ -26,6 +26,8 @@ const HOOK_EXECUTION_ORDER = {
|
|
|
26
26
|
PRE_TEST: ['BeforeSuiteHook', 'BeforeHook'],
|
|
27
27
|
POST_TEST: ['AfterHook', 'AfterSuiteHook']
|
|
28
28
|
};
|
|
29
|
+
// codeceptjs workers are self-contained
|
|
30
|
+
data_storage_js_1.dataStorage.isFileStorage = false;
|
|
29
31
|
const DATA_REGEXP = /[|\s]+?(\{".*\}|\[.*\])/;
|
|
30
32
|
if (MAJOR_VERSION < 3) {
|
|
31
33
|
console.log('🔴 This reporter works with CodeceptJS 3+, please update your tests');
|
|
@@ -105,6 +105,7 @@ class CucumberReporter extends cucumber_1.Formatter {
|
|
|
105
105
|
const logs = index_js_1.services.logger.getLogs(testTitle).join('\n');
|
|
106
106
|
const artifacts = index_js_1.services.artifacts.get(testTitle);
|
|
107
107
|
const keyValues = index_js_1.services.keyValues.get(testTitle);
|
|
108
|
+
const links = index_js_1.services.links.get(testTitle);
|
|
108
109
|
this.client.addTestRun(status, {
|
|
109
110
|
// error: testCaseAttempt.worstTestStepResult.message,
|
|
110
111
|
message,
|
|
@@ -114,6 +115,7 @@ class CucumberReporter extends cucumber_1.Formatter {
|
|
|
114
115
|
.trim(),
|
|
115
116
|
example: { ...example },
|
|
116
117
|
logs,
|
|
118
|
+
links,
|
|
117
119
|
manuallyAttachedArtifacts: artifacts,
|
|
118
120
|
meta: keyValues,
|
|
119
121
|
title: scenario,
|
package/lib/adapter/jest.js
CHANGED
|
@@ -57,6 +57,7 @@ class JestReporter {
|
|
|
57
57
|
const logs = getTestLogs(result);
|
|
58
58
|
const artifacts = index_js_1.services.artifacts.get(result.fullName);
|
|
59
59
|
const keyValues = index_js_1.services.keyValues.get(result.fullName);
|
|
60
|
+
const links = index_js_1.services.links.get(result.fullName);
|
|
60
61
|
const deducedStatus = status === 'pending' ? 'skipped' : status;
|
|
61
62
|
// In jest if test is not matched with test name pattern it is considered as skipped.
|
|
62
63
|
// So adding a check if it is skipped for real or because of test pattern
|
|
@@ -69,6 +70,7 @@ class JestReporter {
|
|
|
69
70
|
title,
|
|
70
71
|
time: duration,
|
|
71
72
|
logs,
|
|
73
|
+
links,
|
|
72
74
|
manuallyAttachedArtifacts: artifacts,
|
|
73
75
|
meta: keyValues,
|
|
74
76
|
});
|
|
@@ -57,6 +57,7 @@ class PlaywrightReporter {
|
|
|
57
57
|
}
|
|
58
58
|
const manuallyAttachedArtifacts = index_js_1.services.artifacts.get(fullTestTitle);
|
|
59
59
|
const testMeta = index_js_1.services.keyValues.get(fullTestTitle);
|
|
60
|
+
const links = index_js_1.services.links.get(fullTestTitle);
|
|
60
61
|
const rid = test.id || test.testId || (0, uuid_1.v4)();
|
|
61
62
|
/**
|
|
62
63
|
* @type {{
|
|
@@ -94,6 +95,7 @@ class PlaywrightReporter {
|
|
|
94
95
|
steps: steps.length ? steps : undefined,
|
|
95
96
|
time: duration,
|
|
96
97
|
logs,
|
|
98
|
+
links,
|
|
97
99
|
manuallyAttachedArtifacts,
|
|
98
100
|
meta: {
|
|
99
101
|
browser: project.browser,
|
package/lib/adapter/webdriver.js
CHANGED
|
@@ -78,12 +78,10 @@ class WebdriverReporter extends reporter_1.default {
|
|
|
78
78
|
onTestEnd(test) {
|
|
79
79
|
test.suite = test.parent;
|
|
80
80
|
const logs = getTestLogs(test.fullTitle);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
test.artifacts = index_js_1.services.artifacts.get(test.fullTitle);
|
|
82
|
+
test.meta = index_js_1.services.keyValues.get(test.fullTitle);
|
|
83
|
+
test.links = index_js_1.services.links.get(test.fullTitle);
|
|
84
84
|
test.logs = logs;
|
|
85
|
-
test.artifacts = artifacts;
|
|
86
|
-
test.meta = keyValues;
|
|
87
85
|
this._addTestPromises.push(this.addTest(test));
|
|
88
86
|
}
|
|
89
87
|
// wdio-cucumber does not trigger onTestEnd hook, thus, using this one
|
|
@@ -95,7 +93,7 @@ class WebdriverReporter extends reporter_1.default {
|
|
|
95
93
|
async addTest(test) {
|
|
96
94
|
if (!this.client)
|
|
97
95
|
return;
|
|
98
|
-
const { title, _duration: duration, state, error, output } = test;
|
|
96
|
+
const { title, _duration: duration, state, error, output, links, artifacts, meta, logs } = test;
|
|
99
97
|
const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(title);
|
|
100
98
|
const screenshotEndpoint = '/session/:sessionId/screenshot';
|
|
101
99
|
const screenshotsBuffers = output
|
|
@@ -106,8 +104,9 @@ class WebdriverReporter extends reporter_1.default {
|
|
|
106
104
|
rid,
|
|
107
105
|
manuallyAttachedArtifacts: test.artifacts,
|
|
108
106
|
error,
|
|
109
|
-
logs
|
|
110
|
-
meta
|
|
107
|
+
logs,
|
|
108
|
+
meta,
|
|
109
|
+
links,
|
|
111
110
|
title,
|
|
112
111
|
test_id: testId,
|
|
113
112
|
time: duration,
|
package/lib/client.js
CHANGED
|
@@ -50,7 +50,6 @@ const path_1 = __importStar(require("path"));
|
|
|
50
50
|
const node_url_1 = require("node:url");
|
|
51
51
|
const uploader_js_1 = require("./uploader.js");
|
|
52
52
|
const utils_js_1 = require("./utils/utils.js");
|
|
53
|
-
const links_js_1 = require("./services/links.js");
|
|
54
53
|
const filesize_1 = require("filesize");
|
|
55
54
|
const debug = (0, debug_1.default)('@testomatio/reporter:client');
|
|
56
55
|
// removed __dirname usage, because:
|
|
@@ -182,40 +181,11 @@ class Client {
|
|
|
182
181
|
/**
|
|
183
182
|
* @type {TestData}
|
|
184
183
|
*/
|
|
185
|
-
const { rid, error = null, time = 0, example = null, files = [], filesBuffers = [], steps, code = null, title, file, suite_title, suite_id, test_id, timestamp, manuallyAttachedArtifacts, overwrite, tags, } = testData;
|
|
184
|
+
const { rid, error = null, time = 0, example = null, files = [], filesBuffers = [], steps, code = null, title, file, suite_title, suite_id, test_id, timestamp, links, manuallyAttachedArtifacts, overwrite, tags, } = testData;
|
|
186
185
|
let { message = '', meta = {} } = testData;
|
|
187
186
|
// stringify meta values and limit keys and values length to 255
|
|
188
187
|
meta = Object.entries(meta)
|
|
189
188
|
.filter(([, value]) => value !== null && value !== undefined)
|
|
190
|
-
.map(([key, value]) => {
|
|
191
|
-
try {
|
|
192
|
-
if (typeof value === 'object') {
|
|
193
|
-
value = JSON.stringify(value);
|
|
194
|
-
}
|
|
195
|
-
else if (typeof value !== 'string') {
|
|
196
|
-
try {
|
|
197
|
-
value = value.toString();
|
|
198
|
-
}
|
|
199
|
-
catch (err) {
|
|
200
|
-
console.warn(constants_js_1.APP_PREFIX, `Can't convert meta value to string`, err);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (value?.length > 255) {
|
|
204
|
-
value = value.substring(0, 255);
|
|
205
|
-
debug(constants_js_1.APP_PREFIX, `Meta info value "${value}" is too long, trimmed to 255 characters`);
|
|
206
|
-
}
|
|
207
|
-
if (key?.length > 255) {
|
|
208
|
-
const newKey = key.substring(0, 255);
|
|
209
|
-
debug(constants_js_1.APP_PREFIX, `Meta info key "${key}" is too long, trimmed to 255 characters`);
|
|
210
|
-
return [newKey, value];
|
|
211
|
-
}
|
|
212
|
-
return [key, value];
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
debug(constants_js_1.APP_PREFIX, `Error while processing meta info key ${key}`, err);
|
|
216
|
-
return [null, null];
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
189
|
.reduce((acc, [key, value]) => {
|
|
220
190
|
if (key)
|
|
221
191
|
acc[key] = value;
|
|
@@ -223,7 +193,6 @@ class Client {
|
|
|
223
193
|
}, {});
|
|
224
194
|
// Get links from storage using the test context
|
|
225
195
|
const testContext = suite_title ? `${suite_title} ${title}` : title;
|
|
226
|
-
const links = links_js_1.linkStorage.get(testContext) || [];
|
|
227
196
|
let errorFormatted = '';
|
|
228
197
|
if (error) {
|
|
229
198
|
errorFormatted += this.formatError(error) || '';
|
package/lib/data-storage.js
CHANGED
|
@@ -143,7 +143,7 @@ class DataStorage {
|
|
|
143
143
|
if (global?.testomatioDataStore[dataType]) {
|
|
144
144
|
const testData = global.testomatioDataStore[dataType][context];
|
|
145
145
|
if (testData)
|
|
146
|
-
debug(
|
|
146
|
+
debug('<=', dataType, 'global', context, testData);
|
|
147
147
|
return testData || [];
|
|
148
148
|
}
|
|
149
149
|
// debug(`No ${this.dataType} data for context ${context} in <global> storage`);
|
|
@@ -165,7 +165,7 @@ class DataStorage {
|
|
|
165
165
|
if (fs_1.default.existsSync(filepath)) {
|
|
166
166
|
const testDataAsText = fs_1.default.readFileSync(filepath, 'utf-8');
|
|
167
167
|
if (testDataAsText)
|
|
168
|
-
debug(
|
|
168
|
+
debug('<=', dataType, 'file', context, testDataAsText);
|
|
169
169
|
const testDataArr = testDataAsText?.split(os_1.default.EOL) || [];
|
|
170
170
|
return testDataArr;
|
|
171
171
|
}
|
|
@@ -184,7 +184,7 @@ class DataStorage {
|
|
|
184
184
|
* @param {*} context
|
|
185
185
|
*/
|
|
186
186
|
#putDataToGlobalVar(dataType, data, context) {
|
|
187
|
-
debug('
|
|
187
|
+
debug('=>', dataType, 'global', context, data);
|
|
188
188
|
if (!global.testomatioDataStore)
|
|
189
189
|
global.testomatioDataStore = {};
|
|
190
190
|
if (!global.testomatioDataStore?.[dataType])
|
|
@@ -208,7 +208,7 @@ class DataStorage {
|
|
|
208
208
|
const filepath = (0, path_1.join)(dataDirPath, filename);
|
|
209
209
|
if (!fs_1.default.existsSync(dataDirPath))
|
|
210
210
|
utils_js_1.fileSystem.createDir(dataDirPath);
|
|
211
|
-
debug(
|
|
211
|
+
debug('=>', dataType, 'file', context, data);
|
|
212
212
|
// append new line if file already exists (in this case its definitely includes some data)
|
|
213
213
|
if (fs_1.default.existsSync(filepath)) {
|
|
214
214
|
fs_1.default.appendFileSync(filepath, os_1.default.EOL + data, 'utf-8');
|
|
@@ -222,7 +222,7 @@ function stringToMD5Hash(str) {
|
|
|
222
222
|
const md5 = crypto_1.default.createHash('md5');
|
|
223
223
|
md5.update(str);
|
|
224
224
|
const hash = md5.digest('hex');
|
|
225
|
-
return hash
|
|
225
|
+
return `${process.env.runId || 'run'}_${hash}`;
|
|
226
226
|
}
|
|
227
227
|
exports.dataStorage = DataStorage.getInstance();
|
|
228
228
|
// TODO: consider using fs promises instead of writeSync/appendFileSync to
|
|
@@ -5,6 +5,7 @@ declare namespace _default {
|
|
|
5
5
|
export { setKeyValue as keyValue };
|
|
6
6
|
export { setLabel as label };
|
|
7
7
|
export { linkTest };
|
|
8
|
+
export { linkJira };
|
|
8
9
|
}
|
|
9
10
|
export default _default;
|
|
10
11
|
/**
|
|
@@ -40,15 +41,21 @@ declare function setKeyValue(keyValue: {
|
|
|
40
41
|
[key: string]: string;
|
|
41
42
|
} | string, value?: string | null): void;
|
|
42
43
|
/**
|
|
43
|
-
* Add label
|
|
44
|
+
* Add a single label to the test report
|
|
44
45
|
* @param {string} key - label key (e.g. 'severity', 'feature', or just 'smoke' for labels without values)
|
|
45
|
-
* @param {string|
|
|
46
|
+
* @param {string|null} [value=null] - optional label value (e.g. 'high', 'login')
|
|
46
47
|
* @returns {void}
|
|
47
48
|
*/
|
|
48
|
-
declare function setLabel(key: string, value?: string |
|
|
49
|
+
declare function setLabel(key: string, value?: string | null): void;
|
|
49
50
|
/**
|
|
50
51
|
* Add link(s) to the test report
|
|
51
52
|
* @param {...string} testIds - test IDs to link
|
|
52
53
|
* @returns {void}
|
|
53
54
|
*/
|
|
54
55
|
declare function linkTest(...testIds: string[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* Add JIRA issue link(s) to the test report
|
|
58
|
+
* @param {...string} jiraIds - JIRA issue IDs to link
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
declare function linkJira(...jiraIds: string[]): void;
|
|
@@ -50,15 +50,14 @@ function setKeyValue(keyValue, value = null) {
|
|
|
50
50
|
index_js_1.services.keyValues.put(keyValue);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Add label
|
|
53
|
+
* Add a single label to the test report
|
|
54
54
|
* @param {string} key - label key (e.g. 'severity', 'feature', or just 'smoke' for labels without values)
|
|
55
|
-
* @param {string|
|
|
55
|
+
* @param {string|null} [value=null] - optional label value (e.g. 'high', 'login')
|
|
56
56
|
* @returns {void}
|
|
57
57
|
*/
|
|
58
58
|
function setLabel(key, value = null) {
|
|
59
59
|
if (Array.isArray(value)) {
|
|
60
|
-
value.forEach(
|
|
61
|
-
return;
|
|
60
|
+
return value.forEach(label => setLabel(key, label));
|
|
62
61
|
}
|
|
63
62
|
const labelObject = value !== null && value !== undefined && value !== ''
|
|
64
63
|
? { label: `${key}:${value}` }
|
|
@@ -74,6 +73,15 @@ function linkTest(...testIds) {
|
|
|
74
73
|
const links = testIds.map(testId => ({ test: testId }));
|
|
75
74
|
index_js_1.services.links.put(links);
|
|
76
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Add JIRA issue link(s) to the test report
|
|
78
|
+
* @param {...string} jiraIds - JIRA issue IDs to link
|
|
79
|
+
* @returns {void}
|
|
80
|
+
*/
|
|
81
|
+
function linkJira(...jiraIds) {
|
|
82
|
+
const links = jiraIds.map(jiraId => ({ jira: jiraId }));
|
|
83
|
+
index_js_1.services.links.put(links);
|
|
84
|
+
}
|
|
77
85
|
module.exports = {
|
|
78
86
|
artifact: saveArtifact,
|
|
79
87
|
log: logMessage,
|
|
@@ -81,4 +89,5 @@ module.exports = {
|
|
|
81
89
|
keyValue: setKeyValue,
|
|
82
90
|
label: setLabel,
|
|
83
91
|
linkTest,
|
|
92
|
+
linkJira,
|
|
84
93
|
};
|
package/lib/reporter.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export const artifact: (data: string | {
|
|
|
5
5
|
}, context?: any) => void;
|
|
6
6
|
export const log: (...args: any[]) => void;
|
|
7
7
|
export const logger: {
|
|
8
|
-
"__#
|
|
8
|
+
"__#13@#originalUserLogger": {
|
|
9
9
|
assert(condition?: boolean, ...data: any[]): void;
|
|
10
10
|
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
|
11
11
|
clear(): void;
|
|
@@ -50,13 +50,13 @@ export const logger: {
|
|
|
50
50
|
profile(label?: string): void;
|
|
51
51
|
profileEnd(label?: string): void;
|
|
52
52
|
};
|
|
53
|
-
"__#
|
|
53
|
+
"__#13@#userLoggerWithOverridenMethods": any;
|
|
54
54
|
logLevel: string;
|
|
55
55
|
step(strings: any, ...values: any[]): void;
|
|
56
56
|
getLogs(context: string): string[];
|
|
57
|
-
"__#
|
|
57
|
+
"__#13@#stringifyLogs"(...args: any[]): string;
|
|
58
58
|
_templateLiteralLog(strings: any, ...args: any[]): void;
|
|
59
|
-
"__#
|
|
59
|
+
"__#13@#logWrapper"(argsArray: any, level: any): void;
|
|
60
60
|
assert(...args: any[]): void;
|
|
61
61
|
debug(...args: any[]): void;
|
|
62
62
|
error(...args: any[]): void;
|
|
@@ -76,11 +76,12 @@ export const meta: (keyValue: {
|
|
|
76
76
|
[key: string]: string;
|
|
77
77
|
} | string, value?: string | null) => void;
|
|
78
78
|
export const step: (message: string) => void;
|
|
79
|
-
export const label: (key: string, value?: string |
|
|
79
|
+
export const label: (key: string, value?: string | null) => void;
|
|
80
80
|
export const linkTest: (...testIds: string[]) => void;
|
|
81
|
+
export const linkJira: (...jiraIds: string[]) => void;
|
|
81
82
|
declare namespace _default {
|
|
82
83
|
let testomatioLogger: {
|
|
83
|
-
"__#
|
|
84
|
+
"__#13@#originalUserLogger": {
|
|
84
85
|
assert(condition?: boolean, ...data: any[]): void;
|
|
85
86
|
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
|
86
87
|
clear(): void;
|
|
@@ -125,13 +126,13 @@ declare namespace _default {
|
|
|
125
126
|
profile(label?: string): void;
|
|
126
127
|
profileEnd(label?: string): void;
|
|
127
128
|
};
|
|
128
|
-
"__#
|
|
129
|
+
"__#13@#userLoggerWithOverridenMethods": any;
|
|
129
130
|
logLevel: string;
|
|
130
131
|
step(strings: any, ...values: any[]): void;
|
|
131
132
|
getLogs(context: string): string[];
|
|
132
|
-
"__#
|
|
133
|
+
"__#13@#stringifyLogs"(...args: any[]): string;
|
|
133
134
|
_templateLiteralLog(strings: any, ...args: any[]): void;
|
|
134
|
-
"__#
|
|
135
|
+
"__#13@#logWrapper"(argsArray: any, level: any): void;
|
|
135
136
|
assert(...args: any[]): void;
|
|
136
137
|
debug(...args: any[]): void;
|
|
137
138
|
error(...args: any[]): void;
|
|
@@ -154,7 +155,7 @@ declare namespace _default {
|
|
|
154
155
|
}, context?: any) => void;
|
|
155
156
|
let log: (...args: any[]) => void;
|
|
156
157
|
let logger: {
|
|
157
|
-
"__#
|
|
158
|
+
"__#13@#originalUserLogger": {
|
|
158
159
|
assert(condition?: boolean, ...data: any[]): void;
|
|
159
160
|
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
|
160
161
|
clear(): void;
|
|
@@ -199,13 +200,13 @@ declare namespace _default {
|
|
|
199
200
|
profile(label?: string): void;
|
|
200
201
|
profileEnd(label?: string): void;
|
|
201
202
|
};
|
|
202
|
-
"__#
|
|
203
|
+
"__#13@#userLoggerWithOverridenMethods": any;
|
|
203
204
|
logLevel: string;
|
|
204
205
|
step(strings: any, ...values: any[]): void;
|
|
205
206
|
getLogs(context: string): string[];
|
|
206
|
-
"__#
|
|
207
|
+
"__#13@#stringifyLogs"(...args: any[]): string;
|
|
207
208
|
_templateLiteralLog(strings: any, ...args: any[]): void;
|
|
208
|
-
"__#
|
|
209
|
+
"__#13@#logWrapper"(argsArray: any, level: any): void;
|
|
209
210
|
assert(...args: any[]): void;
|
|
210
211
|
debug(...args: any[]): void;
|
|
211
212
|
error(...args: any[]): void;
|
|
@@ -225,8 +226,9 @@ declare namespace _default {
|
|
|
225
226
|
[key: string]: string;
|
|
226
227
|
} | string, value?: string | null) => void;
|
|
227
228
|
let step: (message: string) => void;
|
|
228
|
-
let label: (key: string, value?: string |
|
|
229
|
+
let label: (key: string, value?: string | null) => void;
|
|
229
230
|
let linkTest: (...testIds: string[]) => void;
|
|
231
|
+
let linkJira: (...jiraIds: string[]) => void;
|
|
230
232
|
}
|
|
231
233
|
export default _default;
|
|
232
234
|
export type ArtifactFunction = typeof import("./reporter-functions.js").default.artifact;
|
package/lib/reporter.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.linkTest = exports.label = exports.step = exports.meta = exports.logger = exports.log = exports.artifact = void 0;
|
|
6
|
+
exports.linkJira = exports.linkTest = exports.label = exports.step = exports.meta = exports.logger = exports.log = exports.artifact = void 0;
|
|
7
7
|
// import TestomatClient from './client.js';
|
|
8
8
|
// import * as TRConstants from './constants.js';
|
|
9
9
|
const index_js_1 = require("./services/index.js");
|
|
@@ -15,6 +15,7 @@ exports.meta = reporter_functions_js_1.default.keyValue;
|
|
|
15
15
|
exports.step = reporter_functions_js_1.default.step;
|
|
16
16
|
exports.label = reporter_functions_js_1.default.label;
|
|
17
17
|
exports.linkTest = reporter_functions_js_1.default.linkTest;
|
|
18
|
+
exports.linkJira = reporter_functions_js_1.default.linkJira;
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {typeof import('./reporter-functions.js').default.artifact} ArtifactFunction
|
|
20
21
|
* @typedef {typeof import('./reporter-functions.js').default.log} LogFunction
|
|
@@ -35,6 +36,7 @@ module.exports = {
|
|
|
35
36
|
step: reporter_functions_js_1.default.step,
|
|
36
37
|
label: reporter_functions_js_1.default.label,
|
|
37
38
|
linkTest: reporter_functions_js_1.default.linkTest,
|
|
39
|
+
linkJira: reporter_functions_js_1.default.linkJira,
|
|
38
40
|
// TestomatClient,
|
|
39
41
|
// TRConstants,
|
|
40
42
|
};
|
package/lib/services/labels.d.ts
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const labelStorage: LabelStorage;
|
|
2
|
-
declare class LabelStorage {
|
|
3
|
-
static "__#19@#instance": any;
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @returns {LabelStorage}
|
|
7
|
-
*/
|
|
8
|
-
static getInstance(): LabelStorage;
|
|
9
|
-
/**
|
|
10
|
-
* Stores labels array and passes it to reporter
|
|
11
|
-
* @param {string[]} labels - array of label strings
|
|
12
|
-
* @param {*} context - full test title
|
|
13
|
-
*/
|
|
14
|
-
put(labels: string[], context?: any): void;
|
|
15
|
-
/**
|
|
16
|
-
* Returns labels array for the test
|
|
17
|
-
* @param {*} context testId or test context from test runner
|
|
18
|
-
* @returns {string[]} labels array, e.g. ['smoke', 'severity:high', 'feature:user_account']
|
|
19
|
-
*/
|
|
20
|
-
get(context?: any): string[];
|
|
21
|
-
}
|
|
22
|
-
export {};
|
package/lib/services/labels.js
CHANGED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.labelStorage = void 0;
|
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
const data_storage_js_1 = require("../data-storage.js");
|
|
9
|
-
const debug = (0, debug_1.default)('@testomatio/reporter:services-labels');
|
|
10
|
-
class LabelStorage {
|
|
11
|
-
static #instance;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @returns {LabelStorage}
|
|
15
|
-
*/
|
|
16
|
-
static getInstance() {
|
|
17
|
-
if (!this.#instance) {
|
|
18
|
-
this.#instance = new LabelStorage();
|
|
19
|
-
}
|
|
20
|
-
return this.#instance;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Stores labels array and passes it to reporter
|
|
24
|
-
* @param {string[]} labels - array of label strings
|
|
25
|
-
* @param {*} context - full test title
|
|
26
|
-
*/
|
|
27
|
-
put(labels, context = null) {
|
|
28
|
-
if (!labels || !Array.isArray(labels))
|
|
29
|
-
return;
|
|
30
|
-
data_storage_js_1.dataStorage.putData('links', labels, context);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns labels array for the test
|
|
34
|
-
* @param {*} context testId or test context from test runner
|
|
35
|
-
* @returns {string[]} labels array, e.g. ['smoke', 'severity:high', 'feature:user_account']
|
|
36
|
-
*/
|
|
37
|
-
get(context = null) {
|
|
38
|
-
const labelsList = data_storage_js_1.dataStorage.getData('links', context);
|
|
39
|
-
if (!labelsList || !labelsList?.length)
|
|
40
|
-
return [];
|
|
41
|
-
const allLabels = [];
|
|
42
|
-
for (const labels of labelsList) {
|
|
43
|
-
if (Array.isArray(labels)) {
|
|
44
|
-
allLabels.push(...labels);
|
|
45
|
-
}
|
|
46
|
-
else if (typeof labels === 'string') {
|
|
47
|
-
try {
|
|
48
|
-
const parsedLabels = JSON.parse(labels);
|
|
49
|
-
if (Array.isArray(parsedLabels)) {
|
|
50
|
-
allLabels.push(...parsedLabels);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
debug(`Error parsing labels for test ${context}`, labels);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Remove duplicates
|
|
59
|
-
return [...new Set(allLabels)];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.labelStorage = LabelStorage.getInstance();
|
package/lib/services/links.d.ts
CHANGED
package/lib/services/logger.d.ts
CHANGED
package/package.json
CHANGED
package/src/adapter/codecept.js
CHANGED
|
@@ -113,6 +113,7 @@ class CucumberReporter extends Formatter {
|
|
|
113
113
|
const logs = services.logger.getLogs(testTitle).join('\n');
|
|
114
114
|
const artifacts = services.artifacts.get(testTitle);
|
|
115
115
|
const keyValues = services.keyValues.get(testTitle);
|
|
116
|
+
const links = services.links.get(testTitle);
|
|
116
117
|
|
|
117
118
|
this.client.addTestRun(status, {
|
|
118
119
|
// error: testCaseAttempt.worstTestStepResult.message,
|
|
@@ -123,6 +124,7 @@ class CucumberReporter extends Formatter {
|
|
|
123
124
|
.trim(),
|
|
124
125
|
example: { ...example },
|
|
125
126
|
logs,
|
|
127
|
+
links,
|
|
126
128
|
manuallyAttachedArtifacts: artifacts,
|
|
127
129
|
meta: keyValues,
|
|
128
130
|
title: scenario,
|
package/src/adapter/jest.js
CHANGED
|
@@ -59,6 +59,7 @@ export class JestReporter {
|
|
|
59
59
|
const logs = getTestLogs(result);
|
|
60
60
|
const artifacts = services.artifacts.get(result.fullName);
|
|
61
61
|
const keyValues = services.keyValues.get(result.fullName);
|
|
62
|
+
const links = services.links.get(result.fullName);
|
|
62
63
|
|
|
63
64
|
const deducedStatus = status === 'pending' ? 'skipped' : status;
|
|
64
65
|
// In jest if test is not matched with test name pattern it is considered as skipped.
|
|
@@ -72,6 +73,7 @@ export class JestReporter {
|
|
|
72
73
|
title,
|
|
73
74
|
time: duration,
|
|
74
75
|
logs,
|
|
76
|
+
links,
|
|
75
77
|
manuallyAttachedArtifacts: artifacts,
|
|
76
78
|
meta: keyValues,
|
|
77
79
|
});
|
|
@@ -61,6 +61,7 @@ class PlaywrightReporter {
|
|
|
61
61
|
}
|
|
62
62
|
const manuallyAttachedArtifacts = services.artifacts.get(fullTestTitle);
|
|
63
63
|
const testMeta = services.keyValues.get(fullTestTitle);
|
|
64
|
+
const links = services.links.get(fullTestTitle);
|
|
64
65
|
const rid = test.id || test.testId || uuidv4();
|
|
65
66
|
|
|
66
67
|
/**
|
|
@@ -99,6 +100,7 @@ class PlaywrightReporter {
|
|
|
99
100
|
steps: steps.length ? steps : undefined,
|
|
100
101
|
time: duration,
|
|
101
102
|
logs,
|
|
103
|
+
links,
|
|
102
104
|
manuallyAttachedArtifacts,
|
|
103
105
|
meta: {
|
|
104
106
|
browser: project.browser,
|
package/src/adapter/webdriver.js
CHANGED
|
@@ -53,12 +53,11 @@ class WebdriverReporter extends WDIOReporter {
|
|
|
53
53
|
onTestEnd(test) {
|
|
54
54
|
test.suite = test.parent;
|
|
55
55
|
const logs = getTestLogs(test.fullTitle);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
|
|
57
|
+
test.artifacts = services.artifacts.get(test.fullTitle);
|
|
58
|
+
test.meta = services.keyValues.get(test.fullTitle);
|
|
59
|
+
test.links = services.links.get(test.fullTitle);
|
|
59
60
|
test.logs = logs;
|
|
60
|
-
test.artifacts = artifacts;
|
|
61
|
-
test.meta = keyValues;
|
|
62
61
|
|
|
63
62
|
this._addTestPromises.push(this.addTest(test));
|
|
64
63
|
}
|
|
@@ -73,7 +72,7 @@ class WebdriverReporter extends WDIOReporter {
|
|
|
73
72
|
async addTest(test) {
|
|
74
73
|
if (!this.client) return;
|
|
75
74
|
|
|
76
|
-
const { title, _duration: duration, state, error, output } = test;
|
|
75
|
+
const { title, _duration: duration, state, error, output, links, artifacts, meta, logs } = test;
|
|
77
76
|
|
|
78
77
|
const testId = getTestomatIdFromTestTitle(title);
|
|
79
78
|
|
|
@@ -88,8 +87,9 @@ class WebdriverReporter extends WDIOReporter {
|
|
|
88
87
|
rid,
|
|
89
88
|
manuallyAttachedArtifacts: test.artifacts,
|
|
90
89
|
error,
|
|
91
|
-
logs
|
|
92
|
-
meta
|
|
90
|
+
logs,
|
|
91
|
+
meta,
|
|
92
|
+
links,
|
|
93
93
|
title,
|
|
94
94
|
test_id: testId,
|
|
95
95
|
time: duration,
|
package/src/client.js
CHANGED
|
@@ -11,7 +11,6 @@ import path, { sep } from 'path';
|
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import { S3Uploader } from './uploader.js';
|
|
13
13
|
import { formatStep, readLatestRunId, storeRunId, validateSuiteId } from './utils/utils.js';
|
|
14
|
-
import { linkStorage } from './services/links.js';
|
|
15
14
|
import { filesize as prettyBytes } from 'filesize';
|
|
16
15
|
|
|
17
16
|
const debug = createDebugMessages('@testomatio/reporter:client');
|
|
@@ -182,6 +181,7 @@ class Client {
|
|
|
182
181
|
suite_id,
|
|
183
182
|
test_id,
|
|
184
183
|
timestamp,
|
|
184
|
+
links,
|
|
185
185
|
manuallyAttachedArtifacts,
|
|
186
186
|
overwrite,
|
|
187
187
|
tags,
|
|
@@ -191,35 +191,6 @@ class Client {
|
|
|
191
191
|
// stringify meta values and limit keys and values length to 255
|
|
192
192
|
meta = Object.entries(meta)
|
|
193
193
|
.filter(([, value]) => value !== null && value !== undefined)
|
|
194
|
-
.map(([key, value]) => {
|
|
195
|
-
try {
|
|
196
|
-
if (typeof value === 'object') {
|
|
197
|
-
value = JSON.stringify(value);
|
|
198
|
-
} else if (typeof value !== 'string') {
|
|
199
|
-
try {
|
|
200
|
-
value = value.toString();
|
|
201
|
-
} catch (err) {
|
|
202
|
-
console.warn(APP_PREFIX, `Can't convert meta value to string`, err);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (value?.length > 255) {
|
|
207
|
-
value = value.substring(0, 255);
|
|
208
|
-
debug(APP_PREFIX, `Meta info value "${value}" is too long, trimmed to 255 characters`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (key?.length > 255) {
|
|
212
|
-
const newKey = key.substring(0, 255);
|
|
213
|
-
debug(APP_PREFIX, `Meta info key "${key}" is too long, trimmed to 255 characters`);
|
|
214
|
-
return [newKey, value];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return [key, value];
|
|
218
|
-
} catch (err) {
|
|
219
|
-
debug(APP_PREFIX, `Error while processing meta info key ${key}`, err);
|
|
220
|
-
return [null, null];
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
194
|
.reduce((acc, [key, value]) => {
|
|
224
195
|
if (key) acc[key] = value;
|
|
225
196
|
return acc;
|
|
@@ -227,7 +198,6 @@ class Client {
|
|
|
227
198
|
|
|
228
199
|
// Get links from storage using the test context
|
|
229
200
|
const testContext = suite_title ? `${suite_title} ${title}` : title;
|
|
230
|
-
const links = linkStorage.get(testContext) || [];
|
|
231
201
|
|
|
232
202
|
let errorFormatted = '';
|
|
233
203
|
if (error) {
|
package/src/data-storage.js
CHANGED
|
@@ -116,7 +116,7 @@ class DataStorage {
|
|
|
116
116
|
try {
|
|
117
117
|
if (global?.testomatioDataStore[dataType]) {
|
|
118
118
|
const testData = global.testomatioDataStore[dataType][context];
|
|
119
|
-
if (testData) debug(
|
|
119
|
+
if (testData) debug('<=', dataType, 'global', context, testData);
|
|
120
120
|
return testData || [];
|
|
121
121
|
}
|
|
122
122
|
// debug(`No ${this.dataType} data for context ${context} in <global> storage`);
|
|
@@ -137,7 +137,7 @@ class DataStorage {
|
|
|
137
137
|
const filepath = join(dataDirPath, `${dataType}_${context}`);
|
|
138
138
|
if (fs.existsSync(filepath)) {
|
|
139
139
|
const testDataAsText = fs.readFileSync(filepath, 'utf-8');
|
|
140
|
-
if (testDataAsText) debug(
|
|
140
|
+
if (testDataAsText) debug('<=', dataType, 'file', context, testDataAsText);
|
|
141
141
|
const testDataArr = testDataAsText?.split(os.EOL) || [];
|
|
142
142
|
return testDataArr;
|
|
143
143
|
}
|
|
@@ -156,7 +156,7 @@ class DataStorage {
|
|
|
156
156
|
* @param {*} context
|
|
157
157
|
*/
|
|
158
158
|
#putDataToGlobalVar(dataType, data, context) {
|
|
159
|
-
debug('
|
|
159
|
+
debug('=>', dataType, 'global', context, data);
|
|
160
160
|
if (!global.testomatioDataStore) global.testomatioDataStore = {};
|
|
161
161
|
if (!global.testomatioDataStore?.[dataType]) global.testomatioDataStore[dataType] = {};
|
|
162
162
|
|
|
@@ -177,7 +177,7 @@ class DataStorage {
|
|
|
177
177
|
const filename = `${dataType}_${context}`;
|
|
178
178
|
const filepath = join(dataDirPath, filename);
|
|
179
179
|
if (!fs.existsSync(dataDirPath)) fileSystem.createDir(dataDirPath);
|
|
180
|
-
debug(
|
|
180
|
+
debug('=>', dataType, 'file', context, data);
|
|
181
181
|
|
|
182
182
|
// append new line if file already exists (in this case its definitely includes some data)
|
|
183
183
|
if (fs.existsSync(filepath)) {
|
|
@@ -192,8 +192,7 @@ function stringToMD5Hash(str) {
|
|
|
192
192
|
const md5 = crypto.createHash('md5');
|
|
193
193
|
md5.update(str);
|
|
194
194
|
const hash = md5.digest('hex');
|
|
195
|
-
|
|
196
|
-
return hash;
|
|
195
|
+
return `${process.env.runId || 'run'}_${hash}`;
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
export const dataStorage = DataStorage.getInstance();
|
|
@@ -53,24 +53,21 @@ function setKeyValue(keyValue, value = null) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Add label
|
|
56
|
+
* Add a single label to the test report
|
|
57
57
|
* @param {string} key - label key (e.g. 'severity', 'feature', or just 'smoke' for labels without values)
|
|
58
|
-
* @param {string|
|
|
58
|
+
* @param {string|null} [value=null] - optional label value (e.g. 'high', 'login')
|
|
59
59
|
* @returns {void}
|
|
60
60
|
*/
|
|
61
61
|
function setLabel(key, value = null) {
|
|
62
62
|
if (Array.isArray(value)) {
|
|
63
|
-
value.forEach(
|
|
64
|
-
return;
|
|
63
|
+
return value.forEach(label => setLabel(key, label));
|
|
65
64
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
? { label: `${key}:${value}` }
|
|
65
|
+
const labelObject = value !== null && value !== undefined && value !== ''
|
|
66
|
+
? { label: `${key}:${value}` }
|
|
69
67
|
: { label: key };
|
|
70
68
|
services.links.put([labelObject]);
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
|
|
74
71
|
/**
|
|
75
72
|
* Add link(s) to the test report
|
|
76
73
|
* @param {...string} testIds - test IDs to link
|
|
@@ -81,6 +78,16 @@ function linkTest(...testIds) {
|
|
|
81
78
|
services.links.put(links);
|
|
82
79
|
}
|
|
83
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Add JIRA issue link(s) to the test report
|
|
83
|
+
* @param {...string} jiraIds - JIRA issue IDs to link
|
|
84
|
+
* @returns {void}
|
|
85
|
+
*/
|
|
86
|
+
function linkJira(...jiraIds) {
|
|
87
|
+
const links = jiraIds.map(jiraId => ({ jira: jiraId }));
|
|
88
|
+
services.links.put(links);
|
|
89
|
+
}
|
|
90
|
+
|
|
84
91
|
export default {
|
|
85
92
|
artifact: saveArtifact,
|
|
86
93
|
log: logMessage,
|
|
@@ -88,4 +95,5 @@ export default {
|
|
|
88
95
|
keyValue: setKeyValue,
|
|
89
96
|
label: setLabel,
|
|
90
97
|
linkTest,
|
|
98
|
+
linkJira,
|
|
91
99
|
};
|
package/src/reporter.js
CHANGED
|
@@ -10,6 +10,7 @@ export const meta = reporterFunctions.keyValue;
|
|
|
10
10
|
export const step = reporterFunctions.step;
|
|
11
11
|
export const label = reporterFunctions.label;
|
|
12
12
|
export const linkTest = reporterFunctions.linkTest;
|
|
13
|
+
export const linkJira = reporterFunctions.linkJira;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @typedef {typeof import('./reporter-functions.js').default.artifact} ArtifactFunction
|
|
@@ -32,6 +33,7 @@ export default {
|
|
|
32
33
|
step: reporterFunctions.step,
|
|
33
34
|
label: reporterFunctions.label,
|
|
34
35
|
linkTest: reporterFunctions.linkTest,
|
|
36
|
+
linkJira: reporterFunctions.linkJira,
|
|
35
37
|
|
|
36
38
|
// TestomatClient,
|
|
37
39
|
// TRConstants,
|
package/src/services/labels.js
CHANGED
|
@@ -1,59 +1 @@
|
|
|
1
|
-
import createDebugMessages from 'debug';
|
|
2
|
-
import { dataStorage } from '../data-storage.js';
|
|
3
1
|
|
|
4
|
-
const debug = createDebugMessages('@testomatio/reporter:services-labels');
|
|
5
|
-
class LabelStorage {
|
|
6
|
-
static #instance;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @returns {LabelStorage}
|
|
11
|
-
*/
|
|
12
|
-
static getInstance() {
|
|
13
|
-
if (!this.#instance) {
|
|
14
|
-
this.#instance = new LabelStorage();
|
|
15
|
-
}
|
|
16
|
-
return this.#instance;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Stores labels array and passes it to reporter
|
|
21
|
-
* @param {string[]} labels - array of label strings
|
|
22
|
-
* @param {*} context - full test title
|
|
23
|
-
*/
|
|
24
|
-
put(labels, context = null) {
|
|
25
|
-
if (!labels || !Array.isArray(labels)) return;
|
|
26
|
-
dataStorage.putData('links', labels, context);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Returns labels array for the test
|
|
31
|
-
* @param {*} context testId or test context from test runner
|
|
32
|
-
* @returns {string[]} labels array, e.g. ['smoke', 'severity:high', 'feature:user_account']
|
|
33
|
-
*/
|
|
34
|
-
get(context = null) {
|
|
35
|
-
const labelsList = dataStorage.getData('links', context);
|
|
36
|
-
if (!labelsList || !labelsList?.length) return [];
|
|
37
|
-
|
|
38
|
-
const allLabels = [];
|
|
39
|
-
for (const labels of labelsList) {
|
|
40
|
-
if (Array.isArray(labels)) {
|
|
41
|
-
allLabels.push(...labels);
|
|
42
|
-
} else if (typeof labels === 'string') {
|
|
43
|
-
try {
|
|
44
|
-
const parsedLabels = JSON.parse(labels);
|
|
45
|
-
if (Array.isArray(parsedLabels)) {
|
|
46
|
-
allLabels.push(...parsedLabels);
|
|
47
|
-
}
|
|
48
|
-
} catch (e) {
|
|
49
|
-
debug(`Error parsing labels for test ${context}`, labels);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Remove duplicates
|
|
55
|
-
return [...new Set(allLabels)];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const labelStorage = LabelStorage.getInstance();
|