@testomatio/reporter 2.7.0 → 2.7.2-beta.1
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/README.md +2 -1
- package/lib/adapter/codecept.js +81 -26
- package/lib/adapter/playwright.d.ts +1 -1
- package/lib/adapter/playwright.js +54 -34
- package/lib/adapter/utils/step-formatter.d.ts +134 -0
- package/lib/adapter/utils/step-formatter.js +237 -0
- package/lib/bin/cli.js +28 -31
- package/lib/bin/reportXml.js +5 -6
- package/lib/bin/startTest.js +2 -1
- package/lib/bin/uploadArtifacts.js +6 -6
- package/lib/client.d.ts +8 -0
- package/lib/client.js +71 -10
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +7 -1
- package/lib/pipe/bitbucket.js +2 -1
- package/lib/pipe/coverage.js +16 -15
- package/lib/pipe/debug.js +3 -3
- package/lib/pipe/github.js +3 -2
- package/lib/pipe/gitlab.js +2 -1
- package/lib/pipe/index.js +5 -5
- package/lib/pipe/testomatio.js +21 -24
- package/lib/uploader.js +3 -2
- package/lib/utils/log.d.ts +45 -0
- package/lib/utils/log.js +98 -0
- package/lib/utils/pipe_utils.js +5 -5
- package/lib/utils/utils.d.ts +10 -0
- package/lib/utils/utils.js +16 -1
- package/lib/xmlReader.js +5 -4
- package/package.json +1 -1
- package/src/adapter/codecept.js +99 -29
- package/src/adapter/playwright.js +64 -39
- package/src/adapter/utils/step-formatter.js +232 -0
- package/src/bin/cli.js +34 -31
- package/src/bin/reportXml.js +5 -6
- package/src/bin/startTest.js +3 -2
- package/src/bin/uploadArtifacts.js +6 -6
- package/src/client.js +76 -26
- package/src/constants.js +4 -0
- package/src/pipe/bitbucket.js +2 -1
- package/src/pipe/coverage.js +16 -15
- package/src/pipe/debug.js +3 -3
- package/src/pipe/github.js +4 -3
- package/src/pipe/gitlab.js +2 -1
- package/src/pipe/index.js +5 -7
- package/src/pipe/testomatio.js +32 -25
- package/src/uploader.js +3 -2
- package/src/utils/log.js +87 -0
- package/src/utils/pipe_utils.js +5 -5
- package/src/utils/utils.js +14 -0
- package/src/xmlReader.js +5 -4
- package/types/types.d.ts +3 -0
package/src/utils/log.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { APP_PREFIX } from '../constants.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Log levels for the Testomat.io reporter.
|
|
5
|
+
* A message is logged if its level is <= the current log level.
|
|
6
|
+
* @example
|
|
7
|
+
* TESTOMATIO_LOG_LEVEL=ERROR npx codeceptjs run // Only errors
|
|
8
|
+
* TESTOMATIO_LOG_LEVEL=WARN npx codeceptjs run // Warnings and errors
|
|
9
|
+
* TESTOMATIO_LOG_LEVEL=INFO npx codeceptjs run // Info, warnings, errors (default)
|
|
10
|
+
*/
|
|
11
|
+
export const LOG_LEVELS = {
|
|
12
|
+
ERROR: 0,
|
|
13
|
+
WARN: 1,
|
|
14
|
+
INFO: 2,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the current log level from TESTOMATIO_LOG_LEVEL environment variable.
|
|
19
|
+
* Defaults to INFO (info, warn, and error messages).
|
|
20
|
+
* @returns {number} Numeric log level (0-2)
|
|
21
|
+
*/
|
|
22
|
+
export function getLogLevel() {
|
|
23
|
+
const envLevel = process.env.TESTOMATIO_LOG_LEVEL?.toUpperCase();
|
|
24
|
+
return LOG_LEVELS[envLevel] ?? LOG_LEVELS.INFO;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Check if a message should be logged based on its level.
|
|
29
|
+
* A message is logged if its level is <= the current log level,
|
|
30
|
+
* or if TESTOMATIO_DEBUG is set (for debugging with the debug package).
|
|
31
|
+
* @param {number} messageLevel - Message level (LOG_LEVELS value)
|
|
32
|
+
* @returns {boolean} True if the message should be logged
|
|
33
|
+
*/
|
|
34
|
+
export function shouldLog(messageLevel) {
|
|
35
|
+
return messageLevel <= getLogLevel() || !!process.env.TESTOMATIO_DEBUG;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Log an info message with [TESTOMATIO] prefix.
|
|
40
|
+
* Only logs when TESTOMATIO_LOG_LEVEL is INFO.
|
|
41
|
+
* @param {...any} args - Arguments to log
|
|
42
|
+
*/
|
|
43
|
+
export function info(...args) {
|
|
44
|
+
if (shouldLog(LOG_LEVELS.INFO)) {
|
|
45
|
+
console.log(APP_PREFIX, ...args);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Log a warning message with [TESTOMATIO] prefix.
|
|
51
|
+
* Only logs when TESTOMATIO_LOG_LEVEL is WARN or INFO.
|
|
52
|
+
* @param {...any} args - Arguments to log
|
|
53
|
+
*/
|
|
54
|
+
export function warn(...args) {
|
|
55
|
+
if (shouldLog(LOG_LEVELS.WARN)) {
|
|
56
|
+
console.warn(APP_PREFIX, ...args);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Log an error message with [TESTOMATIO] prefix.
|
|
62
|
+
* Logs for all TESTOMATIO_LOG_LEVEL values.
|
|
63
|
+
* @param {...any} args - Arguments to log
|
|
64
|
+
*/
|
|
65
|
+
export function error(...args) {
|
|
66
|
+
if (shouldLog(LOG_LEVELS.ERROR)) {
|
|
67
|
+
console.error(APP_PREFIX, ...args);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Logging utility for Testomat.io reporter.
|
|
73
|
+
* All messages are prefixed with [TESTOMATIO] and respect TESTOMATIO_LOG_LEVEL.
|
|
74
|
+
* @example
|
|
75
|
+
* import { log } from './utils/log.js';
|
|
76
|
+
* log.info('Test started');
|
|
77
|
+
* log.warn('This is a warning');
|
|
78
|
+
* log.error('Something went wrong');
|
|
79
|
+
*/
|
|
80
|
+
export const log = {
|
|
81
|
+
info,
|
|
82
|
+
warn,
|
|
83
|
+
error,
|
|
84
|
+
getLogLevel,
|
|
85
|
+
shouldLog,
|
|
86
|
+
LOG_LEVELS,
|
|
87
|
+
};
|
package/src/utils/pipe_utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { log } from './log.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Set S3 credentials from the provided artifacts object.
|
|
@@ -7,7 +7,7 @@ import { APP_PREFIX } from '../constants.js';
|
|
|
7
7
|
function setS3Credentials(artifacts) {
|
|
8
8
|
if (!Object.keys(artifacts).length) return;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
log.info( 'S3 credentials obtained from Testomat.io...');
|
|
11
11
|
|
|
12
12
|
if (artifacts.ACCESS_KEY_ID) process.env.S3_ACCESS_KEY_ID = artifacts.ACCESS_KEY_ID;
|
|
13
13
|
if (artifacts.SECRET_ACCESS_KEY) process.env.S3_SECRET_ACCESS_KEY = artifacts.SECRET_ACCESS_KEY;
|
|
@@ -28,7 +28,7 @@ function setS3Credentials(artifacts) {
|
|
|
28
28
|
function generateFilterRequestParams(params) {
|
|
29
29
|
// Defensive check: ensure params is an object
|
|
30
30
|
if (!params || typeof params !== 'object') {
|
|
31
|
-
|
|
31
|
+
log.error( `Invalid parameters provided. Expected an object, got: ${typeof params}`);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ function generateFilterRequestParams(params) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (!id) {
|
|
42
|
-
|
|
42
|
+
log.error( `Please make sure your settings "${type.toUpperCase()}"= "${id}" is correct!`);
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -99,7 +99,7 @@ function updateFilterType(type) {
|
|
|
99
99
|
];
|
|
100
100
|
|
|
101
101
|
if (!filterTypes.includes(typeLowerCase)) {
|
|
102
|
-
|
|
102
|
+
log.error( `❗ Invalid filter: "${type}" start settings! Available option list: ${filterTypes}`);
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
|
package/src/utils/utils.js
CHANGED
|
@@ -92,6 +92,19 @@ const isValidUrl = s => {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Checks whether a value is an HTTP(S) URL.
|
|
97
|
+
*
|
|
98
|
+
* Used for artifact handling: if a step artifact is already a remote URL,
|
|
99
|
+
* it should not be uploaded again as a local file path.
|
|
100
|
+
*
|
|
101
|
+
* @param {*} value - Artifact value to validate
|
|
102
|
+
* @returns {boolean} true when value starts with http:// or https://
|
|
103
|
+
*/
|
|
104
|
+
const isHttpUrl = value => {
|
|
105
|
+
return /^https?:\/\//i.test(String(value || ''));
|
|
106
|
+
};
|
|
107
|
+
|
|
95
108
|
const fileMatchRegex = /file:(\/*)([A-Za-z]:[\\/].*?|\/.*?)\.(png|avi|webm|jpg|html|txt)/gi;
|
|
96
109
|
|
|
97
110
|
const fetchFilesFromStackTrace = (stack = '', checkExists = true) => {
|
|
@@ -705,6 +718,7 @@ export {
|
|
|
705
718
|
getGitCommitSha,
|
|
706
719
|
getTestomatIdFromTestTitle,
|
|
707
720
|
humanize,
|
|
721
|
+
isHttpUrl,
|
|
708
722
|
isValidUrl,
|
|
709
723
|
parseSuite,
|
|
710
724
|
readLatestRunId,
|
package/src/xmlReader.js
CHANGED
|
@@ -21,6 +21,7 @@ import { pipesFactory } from './pipe/index.js';
|
|
|
21
21
|
import adapterFactory from './junit-adapter/index.js';
|
|
22
22
|
import { config } from './config.js';
|
|
23
23
|
import { S3Uploader } from './uploader.js';
|
|
24
|
+
import { log } from './utils/log.js';
|
|
24
25
|
|
|
25
26
|
// @ts-ignore this line will be removed in compiled code, because __dirname is defined in commonjs
|
|
26
27
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -86,7 +87,7 @@ class XmlReader {
|
|
|
86
87
|
// @ts-ignore
|
|
87
88
|
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
|
|
88
89
|
this.version = JSON.parse(fs.readFileSync(packageJsonPath).toString()).version;
|
|
89
|
-
|
|
90
|
+
log.info(`Testomatio Reporter v${this.version}`);
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
connectAdapter() {
|
|
@@ -508,7 +509,7 @@ class XmlReader {
|
|
|
508
509
|
|
|
509
510
|
const runId = this.runId || this.store.runId || Date.now().toString();
|
|
510
511
|
test.artifacts = await Promise.all(files.map(f => this.uploader.uploadFileByPath(f, [runId, path.basename(f)])));
|
|
511
|
-
|
|
512
|
+
log.info(`🗄️ Uploaded ${pc.bold(`${files.length} artifacts`)} for test ${test.title}`);
|
|
512
513
|
}
|
|
513
514
|
}
|
|
514
515
|
|
|
@@ -626,9 +627,9 @@ class XmlReader {
|
|
|
626
627
|
}
|
|
627
628
|
|
|
628
629
|
if (totalChunks > 1) {
|
|
629
|
-
|
|
630
|
+
log.info(`✅ Successfully uploaded ${uploadedTests} tests in ${totalChunks} chunks`);
|
|
630
631
|
} else {
|
|
631
|
-
|
|
632
|
+
log.info(`✅ Successfully uploaded ${uploadedTests} tests`);
|
|
632
633
|
}
|
|
633
634
|
|
|
634
635
|
const finishData = {
|