@testomatio/reporter 1.1.1-file-upload.1 → 1.1.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/lib/adapter/playwright.js +25 -4
- package/lib/data-storage.js +2 -2
- package/lib/reporter-functions.js +1 -1
- package/lib/reporter.js +3 -3
- package/lib/services/logger.js +2 -3
- package/lib/utils/utils.js +1 -1
- package/package.json +2 -2
|
@@ -7,6 +7,8 @@ const { APP_PREFIX, STATUS: Status, TESTOMAT_TMP_STORAGE_DIR } = require('../con
|
|
|
7
7
|
const TestomatioClient = require('../client');
|
|
8
8
|
const { isArtifactsEnabled } = require('../fileUploader');
|
|
9
9
|
const { parseTest, fileSystem } = require('../utils/utils');
|
|
10
|
+
const { services } = require('../services');
|
|
11
|
+
const { dataStorage } = require('../data-storage');
|
|
10
12
|
|
|
11
13
|
const reportTestPromises = [];
|
|
12
14
|
|
|
@@ -26,6 +28,11 @@ class PlaywrightReporter {
|
|
|
26
28
|
this.client.createRun();
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
onTestBegin(testInfo) {
|
|
32
|
+
const fullTestTitle = getTestContextName(testInfo);
|
|
33
|
+
dataStorage.setContext(fullTestTitle);
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
onTestEnd(test, result) {
|
|
30
37
|
if (!this.client) return;
|
|
31
38
|
|
|
@@ -35,17 +42,22 @@ class PlaywrightReporter {
|
|
|
35
42
|
|
|
36
43
|
const { error, duration } = result;
|
|
37
44
|
|
|
38
|
-
const suite_title = test.parent
|
|
45
|
+
const suite_title = test.parent
|
|
46
|
+
? test.parent?.title
|
|
47
|
+
: path.basename(test?.location?.file);
|
|
39
48
|
|
|
40
49
|
const steps = [];
|
|
41
50
|
for (const step of result.steps) {
|
|
42
51
|
appendStep(step, steps);
|
|
43
52
|
}
|
|
44
53
|
|
|
54
|
+
const fullTestTitle = getTestContextName(test);
|
|
45
55
|
let logs = '';
|
|
46
56
|
if (result.stderr.length || result.stdout.length) {
|
|
47
57
|
logs = `\n\n${chalk.bold('Logs:')}\n${chalk.red(result.stderr.join(''))}\n${result.stdout.join('')}`;
|
|
48
58
|
}
|
|
59
|
+
const manuallyAttachedArtifacts = services.artifacts.get(fullTestTitle);
|
|
60
|
+
const keyValues = services.keyValues.get(fullTestTitle);
|
|
49
61
|
|
|
50
62
|
const reportTestPromise = this.client
|
|
51
63
|
.addTestRun(checkStatus(result.status), {
|
|
@@ -56,7 +68,8 @@ class PlaywrightReporter {
|
|
|
56
68
|
steps: steps.join('\n'),
|
|
57
69
|
time: duration,
|
|
58
70
|
logs,
|
|
59
|
-
|
|
71
|
+
manuallyAttachedArtifacts,
|
|
72
|
+
meta: keyValues,
|
|
60
73
|
})
|
|
61
74
|
.then(pipes => {
|
|
62
75
|
testId = pipes?.filter(p => p.pipe.includes('Testomatio'))[0]?.result?.data?.test_id;
|
|
@@ -153,6 +166,15 @@ function tmpFile(prefix = 'tmp.') {
|
|
|
153
166
|
return path.join(tmpdir, prefix + crypto.randomBytes(16).toString('hex'));
|
|
154
167
|
}
|
|
155
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Returns filename + test title
|
|
171
|
+
* @param {*} test - testInfo object from Playwright
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
function getTestContextName(test) {
|
|
175
|
+
return `${test._requireFile || ''}_${test.title}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
156
178
|
function initPlaywrightForStorage() {
|
|
157
179
|
try {
|
|
158
180
|
// @ts-ignore-next-line
|
|
@@ -160,8 +182,7 @@ function initPlaywrightForStorage() {
|
|
|
160
182
|
const { test } = require('@playwright/test');
|
|
161
183
|
// eslint-disable-next-line no-empty-pattern
|
|
162
184
|
test.beforeEach(async ({}, testInfo) => {
|
|
163
|
-
|
|
164
|
-
global.testomatioTestTitle = fullTestTitle;
|
|
185
|
+
global.testomatioTestTitle = `${testInfo.file || ''}_${testInfo.title}`;
|
|
165
186
|
});
|
|
166
187
|
} catch (e) {
|
|
167
188
|
// ignore
|
package/lib/data-storage.js
CHANGED
|
@@ -59,7 +59,7 @@ class DataStorage {
|
|
|
59
59
|
putData(dataType, data, context = null) {
|
|
60
60
|
if (!dataType || !data) return;
|
|
61
61
|
|
|
62
|
-
context = context || this.context || global.testomatioTestTitle || jestHelpers.
|
|
62
|
+
context = context || this.context || global.testomatioTestTitle || jestHelpers.getNameOfCurrentlyRunningTest();
|
|
63
63
|
if (!context) {
|
|
64
64
|
debug(`No context provided for "${dataType}" data:`, data);
|
|
65
65
|
return;
|
|
@@ -85,7 +85,7 @@ class DataStorage {
|
|
|
85
85
|
*/
|
|
86
86
|
getData(dataType, context) {
|
|
87
87
|
// TODO: think if it could be useful
|
|
88
|
-
// context = context || this.context || global.testomatioTestTitle || jestHelpers.
|
|
88
|
+
// context = context || this.context || global.testomatioTestTitle || jestHelpers.getNameOfCurrentlyRunningTest();
|
|
89
89
|
|
|
90
90
|
if (!context) {
|
|
91
91
|
debug(`Trying to get "${dataType}" data without context`);
|
package/lib/reporter.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
const TestomatClient = require('./client');
|
|
2
2
|
const TRConstants = require('./constants');
|
|
3
|
+
const { services } = require('./services');
|
|
3
4
|
|
|
4
5
|
const reporterFunctions = require('./reporter-functions');
|
|
5
6
|
|
|
6
7
|
module.exports = {
|
|
7
8
|
// TODO: deprecate in future; use log or testomat.log
|
|
8
|
-
|
|
9
|
-
testomatioLogger: reporterFunctions.log,
|
|
9
|
+
testomatioLogger: services.logger,
|
|
10
10
|
|
|
11
11
|
artifact: reporterFunctions.artifact,
|
|
12
12
|
log: reporterFunctions.log,
|
|
13
|
+
logger: services.logger,
|
|
13
14
|
meta: reporterFunctions.keyValue,
|
|
14
15
|
step: reporterFunctions.step,
|
|
15
16
|
|
|
16
17
|
TestomatClient,
|
|
17
18
|
TRConstants,
|
|
18
19
|
};
|
|
19
|
-
|
package/lib/services/logger.js
CHANGED
|
@@ -44,8 +44,7 @@ class Logger {
|
|
|
44
44
|
logLevel = process?.env?.LOG_LEVEL?.toUpperCase() || 'ALL';
|
|
45
45
|
|
|
46
46
|
constructor() {
|
|
47
|
-
|
|
48
|
-
this.intercept(console);
|
|
47
|
+
if (!dataStorage.isFileStorage || process.env.TESTOMATIO_INTERCEPT_CONSOLE_LOGS) this.intercept(console);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/**
|
|
@@ -106,7 +105,7 @@ class Logger {
|
|
|
106
105
|
* 2. Standard: log(`text ${someVar}`)
|
|
107
106
|
* 3. Standard with multiple arguments: log('text', someVar)
|
|
108
107
|
*/
|
|
109
|
-
|
|
108
|
+
_templateLiteralLog(strings, ...args) {
|
|
110
109
|
if (Array.isArray(strings)) strings = strings.filter(item => item !== '').map(item => item.trim());
|
|
111
110
|
if (Array.isArray(args)) args = args.filter(item => item !== '');
|
|
112
111
|
|
package/lib/utils/utils.js
CHANGED
|
@@ -299,7 +299,7 @@ function removeColorCodes(input) {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
const jestHelpers = {
|
|
302
|
-
|
|
302
|
+
getNameOfCurrentlyRunningTest: () => {
|
|
303
303
|
if (!process.env.JEST_WORKER_ID) return null;
|
|
304
304
|
try {
|
|
305
305
|
// TODO: expect?.getState()?.testPath + ' ' + expect?.getState()?.currentTestName
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testomatio/reporter",
|
|
3
|
-
"version": "1.1.1
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Testomatio Reporter Client",
|
|
5
5
|
"main": "./lib/reporter.js",
|
|
6
6
|
"typings": "typings/index.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"test:adapter:jasmine:example": "./tests/adapter/examples/jasmine/passReporterOpts.sh && jasmine './tests/adapter/examples/jasmine/index.test.js' --reporter=./../../../lib/adapter/jasmine.js",
|
|
53
53
|
"test:adapter:codecept:example": "codeceptjs run --config='./tests/adapter/examples/codecept/codecept.conf.js'",
|
|
54
54
|
"test:adapter:cucumber:example": "cd ./tests/adapter/examples/cucumber && npx cucumber-js",
|
|
55
|
-
"test:storage": "npx mocha tests-storage/artifact-storage.test.js && npx mocha tests-storage/data-storage.test.js && npx mocha tests-storage/logger.test.js && npx mocha tests-storage/reporter-functions.test.js"
|
|
55
|
+
"test:storage": "npx mocha tests-storage/artifact-storage.test.js && npx mocha tests-storage/data-storage.test.js && TESTOMATIO_INTERCEPT_CONSOLE_LOGS=true npx mocha tests-storage/logger.test.js && npx mocha tests-storage/reporter-functions.test.js"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@cucumber/cucumber": "^9.3.0",
|