@testomatio/reporter 2.0.1-beta.4 → 2.0.1-beta.5-timestamp
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 +335 -293
- package/lib/adapter/cucumber/current.js +203 -195
- package/lib/adapter/cucumber/legacy.js +155 -130
- package/lib/adapter/cucumber.js +16 -5
- package/lib/adapter/cypress-plugin/index.js +105 -91
- package/lib/adapter/jasmine.js +53 -54
- package/lib/adapter/jest.js +99 -97
- package/lib/adapter/mocha.js +141 -112
- package/lib/adapter/playwright.js +231 -199
- package/lib/adapter/vitest.js +149 -150
- package/lib/adapter/webdriver.js +121 -144
- package/lib/bin/cli.js +211 -229
- package/lib/bin/reportXml.js +52 -51
- package/lib/bin/startTest.js +95 -83
- package/lib/bin/uploadArtifacts.js +61 -56
- package/lib/client.js +465 -424
- package/lib/config.js +23 -18
- package/lib/constants.js +44 -50
- package/lib/data-storage.js +188 -216
- package/lib/junit-adapter/adapter.js +20 -17
- package/lib/junit-adapter/csharp.js +14 -28
- package/lib/junit-adapter/index.js +25 -27
- package/lib/junit-adapter/java.js +53 -41
- package/lib/junit-adapter/javascript.js +27 -30
- package/lib/junit-adapter/python.js +37 -38
- package/lib/junit-adapter/ruby.js +8 -11
- package/lib/output.js +52 -44
- package/lib/pipe/bitbucket.js +230 -223
- package/lib/pipe/csv.js +126 -113
- package/lib/pipe/debug.js +99 -118
- package/lib/pipe/github.js +213 -218
- package/lib/pipe/gitlab.js +206 -183
- package/lib/pipe/html.js +321 -258
- package/lib/pipe/index.js +66 -94
- package/lib/pipe/testomatio.js +474 -429
- package/lib/reporter-functions.js +26 -28
- package/lib/reporter.js +29 -34
- package/lib/services/artifacts.js +51 -55
- package/lib/services/index.js +12 -14
- package/lib/services/key-values.js +53 -56
- package/lib/services/logger.js +245 -226
- package/lib/template/testomatio.hbs +1366 -1026
- package/lib/uploader.js +364 -295
- package/lib/utils/pipe_utils.js +85 -89
- package/lib/utils/utils.js +307 -398
- package/lib/xmlReader.js +532 -525
- package/package.json +21 -64
- package/lib/adapter/codecept.d.ts +0 -2
- package/lib/adapter/cucumber/current.d.ts +0 -14
- package/lib/adapter/cucumber/legacy.d.ts +0 -0
- package/lib/adapter/cucumber.d.ts +0 -2
- package/lib/adapter/cypress-plugin/index.d.ts +0 -2
- package/lib/adapter/jasmine.d.ts +0 -11
- package/lib/adapter/jest.d.ts +0 -13
- package/lib/adapter/mocha.d.ts +0 -2
- package/lib/adapter/nightwatch.d.ts +0 -4
- package/lib/adapter/nightwatch.js +0 -80
- package/lib/adapter/playwright.d.ts +0 -14
- package/lib/adapter/vitest.d.ts +0 -35
- package/lib/adapter/webdriver.d.ts +0 -24
- package/lib/bin/cli.d.ts +0 -2
- package/lib/bin/reportXml.d.ts +0 -2
- package/lib/bin/startTest.d.ts +0 -2
- package/lib/bin/uploadArtifacts.d.ts +0 -2
- package/lib/client.d.ts +0 -76
- package/lib/config.d.ts +0 -1
- package/lib/constants.d.ts +0 -25
- package/lib/data-storage.d.ts +0 -34
- package/lib/junit-adapter/adapter.d.ts +0 -9
- package/lib/junit-adapter/csharp.d.ts +0 -5
- package/lib/junit-adapter/index.d.ts +0 -3
- package/lib/junit-adapter/java.d.ts +0 -5
- package/lib/junit-adapter/javascript.d.ts +0 -4
- package/lib/junit-adapter/python.d.ts +0 -5
- package/lib/junit-adapter/ruby.d.ts +0 -4
- package/lib/output.d.ts +0 -11
- package/lib/package.json +0 -3
- package/lib/pipe/bitbucket.d.ts +0 -25
- package/lib/pipe/csv.d.ts +0 -47
- package/lib/pipe/debug.d.ts +0 -29
- package/lib/pipe/github.d.ts +0 -30
- package/lib/pipe/gitlab.d.ts +0 -25
- package/lib/pipe/html.d.ts +0 -35
- package/lib/pipe/index.d.ts +0 -1
- package/lib/pipe/testomatio.d.ts +0 -71
- package/lib/replay.d.ts +0 -31
- package/lib/replay.js +0 -237
- package/lib/reporter-functions.d.ts +0 -34
- package/lib/reporter.d.ts +0 -232
- package/lib/services/artifacts.d.ts +0 -33
- package/lib/services/index.d.ts +0 -9
- package/lib/services/key-values.d.ts +0 -27
- package/lib/services/logger.d.ts +0 -64
- package/lib/uploader.d.ts +0 -60
- package/lib/utils/pipe_utils.d.ts +0 -41
- package/lib/utils/utils.d.ts +0 -54
- package/lib/xmlReader.d.ts +0 -92
- package/src/adapter/codecept.js +0 -373
- package/src/adapter/cucumber/current.js +0 -228
- package/src/adapter/cucumber/legacy.js +0 -158
- package/src/adapter/cucumber.js +0 -4
- package/src/adapter/cypress-plugin/index.js +0 -110
- package/src/adapter/jasmine.js +0 -60
- package/src/adapter/jest.js +0 -107
- package/src/adapter/mocha.cjs +0 -2
- package/src/adapter/mocha.js +0 -156
- package/src/adapter/nightwatch.js +0 -88
- package/src/adapter/playwright.js +0 -254
- package/src/adapter/vitest.js +0 -183
- package/src/adapter/webdriver.js +0 -142
- package/src/bin/cli.js +0 -348
- package/src/bin/reportXml.js +0 -77
- package/src/bin/startTest.js +0 -124
- package/src/bin/uploadArtifacts.js +0 -91
- package/src/client.js +0 -508
- package/src/config.js +0 -30
- package/src/constants.js +0 -53
- package/src/data-storage.js +0 -204
- package/src/junit-adapter/adapter.js +0 -23
- package/src/junit-adapter/csharp.js +0 -28
- package/src/junit-adapter/index.js +0 -28
- package/src/junit-adapter/java.js +0 -58
- package/src/junit-adapter/javascript.js +0 -31
- package/src/junit-adapter/python.js +0 -42
- package/src/junit-adapter/ruby.js +0 -10
- package/src/output.js +0 -57
- package/src/pipe/bitbucket.js +0 -252
- package/src/pipe/csv.js +0 -140
- package/src/pipe/debug.js +0 -119
- package/src/pipe/github.js +0 -232
- package/src/pipe/gitlab.js +0 -247
- package/src/pipe/html.js +0 -373
- package/src/pipe/index.js +0 -71
- package/src/pipe/testomatio.js +0 -504
- package/src/replay.js +0 -245
- package/src/reporter-functions.js +0 -55
- package/src/reporter.cjs_decprecated +0 -21
- package/src/reporter.js +0 -33
- package/src/services/artifacts.js +0 -59
- package/src/services/index.js +0 -13
- package/src/services/key-values.js +0 -59
- package/src/services/logger.js +0 -315
- package/src/template/emptyData.svg +0 -23
- package/src/template/testomatio.hbs +0 -1081
- package/src/uploader.js +0 -376
- package/src/utils/pipe_utils.js +0 -119
- package/src/utils/utils.js +0 -416
- package/src/xmlReader.js +0 -614
package/lib/pipe/csv.js
CHANGED
|
@@ -1,126 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
11
|
-
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
12
|
-
const utils_js_1 = require("../utils/utils.js");
|
|
13
|
-
const constants_js_1 = require("../constants.js");
|
|
14
|
-
const debug = (0, debug_1.default)('@testomatio/reporter:pipe:csv');
|
|
1
|
+
const debug = require('debug')('@testomatio/reporter:pipe:csv');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const csvWriter = require('csv-writer');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const merge = require('lodash.merge');
|
|
7
|
+
const { isSameTest, getCurrentDateTime, ansiRegExp } = require('../utils/utils');
|
|
8
|
+
const { CSV_HEADERS } = require('../constants');
|
|
9
|
+
|
|
15
10
|
/**
|
|
16
|
-
* @typedef {import('../../types
|
|
17
|
-
* @typedef {import('../../types
|
|
11
|
+
* @typedef {import('../../types').Pipe} Pipe
|
|
12
|
+
* @typedef {import('../../types').TestData} TestData
|
|
18
13
|
* @class CsvPipe
|
|
19
14
|
* @implements {Pipe}
|
|
20
15
|
*/
|
|
21
16
|
class CsvPipe {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
constructor(params, store) {
|
|
18
|
+
this.store = store || {};
|
|
19
|
+
this.title = params.title || process.env.TESTOMATIO_TITLE;
|
|
20
|
+
this.results = [];
|
|
21
|
+
|
|
22
|
+
this.outputDir = 'export';
|
|
23
|
+
this.defaultReportName = 'report.csv';
|
|
24
|
+
this.csvFilename = process.env.TESTOMATIO_CSV_FILENAME;
|
|
25
|
+
this.isEnabled = false;
|
|
26
|
+
|
|
27
|
+
if (this.csvFilename) {
|
|
28
|
+
const filenameParts = this.csvFilename.split('.');
|
|
29
|
+
|
|
30
|
+
if (filenameParts.length > 0) {
|
|
31
|
+
this.isEnabled = true;
|
|
32
|
+
const baseFilename = filenameParts[0];
|
|
33
|
+
const defaultOutputFile = path.resolve(process.cwd(), this.outputDir, this.defaultReportName);
|
|
34
|
+
|
|
35
|
+
const outputFile =
|
|
36
|
+
baseFilename === this.defaultReportName.split('.')[0] // = 'report'
|
|
37
|
+
? defaultOutputFile
|
|
38
|
+
: path.resolve(process.cwd(), this.outputDir, `${getCurrentDateTime()}_${baseFilename}.csv`);
|
|
39
|
+
|
|
40
|
+
this.outputFile = outputFile;
|
|
41
|
+
}
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// TODO: to using SET opts as argument => prepareRun(opts)
|
|
46
|
+
async prepareRun() {}
|
|
47
|
+
|
|
48
|
+
async createRun() {
|
|
49
|
+
// empty
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
updateRun() {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Create a folder that will contain the exported files
|
|
56
|
+
*/
|
|
57
|
+
checkExportDir() {
|
|
58
|
+
if (!fs.existsSync(this.outputDir)) {
|
|
59
|
+
return fs.mkdirSync(this.outputDir);
|
|
47
60
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Save data to the csv file.
|
|
65
|
+
* @param {Object} data - data that will be added to the CSV file.
|
|
66
|
+
* Example: [{suite_title: "Suite #1", test: "Test-case-1", message: "Test msg"}]
|
|
67
|
+
* @param {Object} headers - csv file headers. Example: [{ id: 'suite_title', title: 'Suite_title' }]
|
|
68
|
+
*/
|
|
69
|
+
async saveToCsv(data, headers) {
|
|
70
|
+
debug('Data', data);
|
|
71
|
+
// First, we check whether the export directory exists: if yes - OK, no - create it.
|
|
72
|
+
this.checkExportDir();
|
|
73
|
+
|
|
74
|
+
if (!this.outputFile) {
|
|
75
|
+
console.log(chalk.yellow(`⚠️ CSV file is not set, ignoring`));
|
|
76
|
+
return;
|
|
56
77
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
console.log(picocolors_1.default.yellow(`⏳ The test results will be added to the csv. It will take some time...`));
|
|
72
|
-
try {
|
|
73
|
-
// Create csv writer object
|
|
74
|
-
const writer = (0, csv_writer_1.createObjectCsvWriter)({
|
|
75
|
-
path: this.outputFile,
|
|
76
|
-
header: headers,
|
|
77
|
-
});
|
|
78
|
-
// Save csv file based on the current data
|
|
79
|
-
return await writer.writeRecords(data);
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
console.log('Unknown csv error: ', e);
|
|
83
|
-
}
|
|
78
|
+
|
|
79
|
+
console.log(chalk.yellow(`⏳ The test results will be added to the csv. It will take some time...`));
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
// Create csv writer object
|
|
83
|
+
const writer = csvWriter.createObjectCsvWriter({
|
|
84
|
+
path: this.outputFile,
|
|
85
|
+
header: headers,
|
|
86
|
+
});
|
|
87
|
+
// Save csv file based on the current data
|
|
88
|
+
return await writer.writeRecords(data);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.log('Unknown csv error: ', e);
|
|
84
91
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.results.push({
|
|
100
|
-
suite_title,
|
|
101
|
-
title,
|
|
102
|
-
status,
|
|
103
|
-
message: message.replace((0, utils_js_1.ansiRegExp)(), ''),
|
|
104
|
-
stack: stack.replace((0, utils_js_1.ansiRegExp)(), ''),
|
|
105
|
-
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Add test data to the result array for saving. As a result of this function, we get a result object to save.
|
|
96
|
+
* @param {Object} test - object which includes each test entry.
|
|
97
|
+
*/
|
|
98
|
+
addTest(test) {
|
|
99
|
+
if (!this.isEnabled) return;
|
|
100
|
+
|
|
101
|
+
const index = this.results.findIndex(t => isSameTest(t, test));
|
|
102
|
+
// update if they were already added
|
|
103
|
+
if (index >= 0) {
|
|
104
|
+
this.results[index] = merge(this.results[index], test);
|
|
105
|
+
return;
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
|
|
108
|
+
const { suite_title, title, status, message, stack } = test;
|
|
109
|
+
|
|
110
|
+
this.results.push({
|
|
111
|
+
suite_title,
|
|
112
|
+
title,
|
|
113
|
+
status,
|
|
114
|
+
message: message.replace(ansiRegExp(), ''),
|
|
115
|
+
stack: stack.replace(ansiRegExp(), ''),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {{ tests?: TestData[] }} runParams
|
|
121
|
+
* @returns {Promise<void>}
|
|
122
|
+
*/
|
|
123
|
+
async finishRun(runParams) {
|
|
124
|
+
if (!this.isEnabled) return;
|
|
125
|
+
|
|
126
|
+
if (runParams.tests) runParams.tests.forEach(t => this.addTest(t));
|
|
127
|
+
// Save results based on the default headers
|
|
128
|
+
if (this.isEnabled) {
|
|
129
|
+
await this.saveToCsv(this.results, CSV_HEADERS);
|
|
130
|
+
console.log(chalk.green(`🗃️ Recording completed! You can check the result in file = ${this.outputFile}`));
|
|
124
131
|
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
toString() {
|
|
135
|
+
return 'csv exporter';
|
|
136
|
+
}
|
|
125
137
|
}
|
|
138
|
+
|
|
126
139
|
module.exports = CsvPipe;
|
package/lib/pipe/debug.js
CHANGED
|
@@ -1,122 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const os_1 = __importDefault(require("os"));
|
|
10
|
-
const debug_1 = __importDefault(require("debug"));
|
|
11
|
-
const constants_js_1 = require("../constants.js");
|
|
12
|
-
const pretty_ms_1 = __importDefault(require("pretty-ms"));
|
|
13
|
-
const debug = (0, debug_1.default)('@testomatio/reporter:pipe:debug');
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { APP_PREFIX } = require('../constants');
|
|
5
|
+
const debug = require('debug')('@testomatio/reporter:pipe:debug');
|
|
6
|
+
// upgrade to latest for ESM
|
|
7
|
+
const prettyMs = require('pretty-ms');
|
|
8
|
+
|
|
14
9
|
class DebugPipe {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
debug('Failed to create symlink:', err.message);
|
|
43
|
-
}
|
|
44
|
-
console.log(constants_js_1.APP_PREFIX, '🪲 Debug file created');
|
|
45
|
-
this.testomatioEnvVars = Object.keys(process.env)
|
|
46
|
-
.filter(key => key.startsWith('TESTOMATIO_'))
|
|
47
|
-
.reduce((acc, key) => {
|
|
48
|
-
acc[key] = process.env[key];
|
|
49
|
-
return acc;
|
|
50
|
-
}, {});
|
|
51
|
-
this.logToFile({ datetime: new Date().toISOString(), timestamp: Date.now() });
|
|
52
|
-
this.logToFile({ data: 'variables', testomatioEnvVars: this.testomatioEnvVars });
|
|
53
|
-
this.logToFile({ data: 'store', store: this.store || {} });
|
|
54
|
-
// Bind batchUpload to the instance
|
|
55
|
-
this.batchUpload = this.batchUpload.bind(this);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Logs data to a file if logging is enabled.
|
|
60
|
-
*
|
|
61
|
-
* @param {Object} logData - The data to be logged.
|
|
62
|
-
* @returns {Promise<void>} A promise that resolves when the log data has been appended to the file.
|
|
63
|
-
*/
|
|
64
|
-
logToFile(logData) {
|
|
65
|
-
if (!this.isEnabled)
|
|
66
|
-
return;
|
|
67
|
-
const timePassedFromLastAction = Date.now() - (this.lastActionTimestamp || Date.now());
|
|
68
|
-
this.lastActionTimestamp = Date.now();
|
|
69
|
-
const logLine = JSON.stringify({ t: `+${(0, pretty_ms_1.default)(timePassedFromLastAction)}`, ...logData });
|
|
70
|
-
fs_1.default.appendFileSync(this.logFilePath, `${logLine}\n`);
|
|
71
|
-
}
|
|
72
|
-
async prepareRun(opts) {
|
|
73
|
-
if (!this.isEnabled)
|
|
74
|
-
return [];
|
|
75
|
-
this.logToFile({ action: 'prepareRun', data: opts });
|
|
76
|
-
}
|
|
77
|
-
async createRun(params = {}) {
|
|
78
|
-
if (!this.isEnabled)
|
|
79
|
-
return;
|
|
80
|
-
if (params.isBatchEnabled === true || params.isBatchEnabled === false)
|
|
81
|
-
this.batch.isEnabled = params.isBatchEnabled;
|
|
82
|
-
if (!this.isEnabled)
|
|
83
|
-
return {};
|
|
84
|
-
if (this.batch.isEnabled)
|
|
85
|
-
this.batch.intervalFunction = setInterval(this.batchUpload, this.batch.intervalTime);
|
|
86
|
-
this.logToFile({ action: 'createRun', params });
|
|
87
|
-
}
|
|
88
|
-
async addTest(data) {
|
|
89
|
-
if (!this.isEnabled)
|
|
90
|
-
return;
|
|
91
|
-
if (!this.batch.isEnabled)
|
|
92
|
-
this.logToFile({ action: 'addTest', testId: data });
|
|
93
|
-
else
|
|
94
|
-
this.batch.tests.push(data);
|
|
95
|
-
if (!this.batch.intervalFunction)
|
|
96
|
-
await this.batchUpload();
|
|
97
|
-
}
|
|
98
|
-
async batchUpload() {
|
|
99
|
-
this.batch.batchIndex++;
|
|
100
|
-
if (!this.batch.isEnabled)
|
|
101
|
-
return;
|
|
102
|
-
if (!this.batch.tests.length)
|
|
103
|
-
return;
|
|
104
|
-
const testsToSend = this.batch.tests.splice(0);
|
|
105
|
-
this.logToFile({ action: 'addTestsBatch', tests: testsToSend });
|
|
106
|
-
}
|
|
107
|
-
async finishRun(params) {
|
|
108
|
-
if (!this.isEnabled)
|
|
109
|
-
return;
|
|
110
|
-
await this.batchUpload();
|
|
111
|
-
if (this.batch.intervalFunction)
|
|
112
|
-
clearInterval(this.batch.intervalFunction);
|
|
113
|
-
this.logToFile({ action: 'finishRun', params });
|
|
114
|
-
console.log(constants_js_1.APP_PREFIX, '🪲 Debug Saved to', this.logFilePath);
|
|
115
|
-
}
|
|
116
|
-
toString() {
|
|
117
|
-
return 'Debug Reporter';
|
|
10
|
+
constructor(params, store) {
|
|
11
|
+
this.isEnabled = !!process.env.TESTOMATIO_DEBUG || !!process.env.DEBUG;
|
|
12
|
+
if (this.isEnabled) {
|
|
13
|
+
this.batch = {
|
|
14
|
+
isEnabled: params.isBatchEnabled ?? !process.env.TESTOMATIO_DISABLE_BATCH_UPLOAD ?? true,
|
|
15
|
+
intervalFunction: null,
|
|
16
|
+
intervalTime: 5000,
|
|
17
|
+
tests: [],
|
|
18
|
+
batchIndex: 0,
|
|
19
|
+
};
|
|
20
|
+
this.logFilePath = path.join(os.tmpdir(), `testomatio.debug.${Date.now()}.json`);
|
|
21
|
+
this.store = store || {};
|
|
22
|
+
|
|
23
|
+
debug('Creating debug file:', this.logFilePath);
|
|
24
|
+
fs.writeFileSync(this.logFilePath, '');
|
|
25
|
+
console.log(APP_PREFIX, '🪲. Debug created:');
|
|
26
|
+
this.testomatioEnvVars = Object.keys(process.env)
|
|
27
|
+
.filter(key => key.startsWith('TESTOMATIO_'))
|
|
28
|
+
.reduce((acc, key) => {
|
|
29
|
+
acc[key] = process.env[key];
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
this.logToFile({ datetime: new Date().toISOString(), timestamp: Date.now() });
|
|
33
|
+
this.logToFile({ data: 'variables', testomatioEnvVars: this.testomatioEnvVars });
|
|
34
|
+
this.logToFile({ data: 'store', store: this.store || {} });
|
|
35
|
+
// Bind batchUpload to the instance
|
|
36
|
+
this.batchUpload = this.batchUpload.bind(this);
|
|
118
37
|
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Logs data to a file if logging is enabled.
|
|
42
|
+
*
|
|
43
|
+
* @param {Object} logData - The data to be logged.
|
|
44
|
+
* @returns {Promise<void>} A promise that resolves when the log data has been appended to the file.
|
|
45
|
+
*/
|
|
46
|
+
logToFile(logData) {
|
|
47
|
+
if (!this.isEnabled) return;
|
|
48
|
+
const timePassedFromLastAction = Date.now() - (this.lastActionTimestamp || Date.now());
|
|
49
|
+
this.lastActionTimestamp = Date.now();
|
|
50
|
+
|
|
51
|
+
const logLine = JSON.stringify({ t: `+${prettyMs(timePassedFromLastAction)}`, ...logData });
|
|
52
|
+
fs.appendFileSync(this.logFilePath, `${logLine}\n`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async prepareRun(opts) {
|
|
56
|
+
if (!this.isEnabled) return [];
|
|
57
|
+
|
|
58
|
+
this.logToFile({ action: 'prepareRun', data: opts });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async createRun(params = {}) {
|
|
62
|
+
if (!this.isEnabled) return;
|
|
63
|
+
if (params.isBatchEnabled === true || params.isBatchEnabled === false) this.batch.isEnabled = params.isBatchEnabled;
|
|
64
|
+
|
|
65
|
+
if (!this.isEnabled) return {};
|
|
66
|
+
if (this.batch.isEnabled) this.batch.intervalFunction = setInterval(this.batchUpload, this.batch.intervalTime);
|
|
67
|
+
|
|
68
|
+
this.logToFile({ action: 'createRun', params });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async addTest(data) {
|
|
72
|
+
if (!this.isEnabled) return;
|
|
73
|
+
|
|
74
|
+
if (!this.batch.isEnabled) this.logToFile({ action: 'addTest', testId: data });
|
|
75
|
+
else this.batch.tests.push(data);
|
|
76
|
+
|
|
77
|
+
if (!this.batch.intervalFunction) await this.batchUpload();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async batchUpload() {
|
|
81
|
+
this.batch.batchIndex++;
|
|
82
|
+
if (!this.batch.isEnabled) return;
|
|
83
|
+
if (!this.batch.tests.length) return;
|
|
84
|
+
|
|
85
|
+
const testsToSend = this.batch.tests.splice(0);
|
|
86
|
+
|
|
87
|
+
this.logToFile({ action: 'addTestsBatch', tests: testsToSend });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async finishRun(params) {
|
|
91
|
+
if (!this.isEnabled) return;
|
|
92
|
+
this.logToFile({ actions: 'finishRun', params });
|
|
93
|
+
await this.batchUpload();
|
|
94
|
+
if (this.batch.intervalFunction) clearInterval(this.batch.intervalFunction);
|
|
95
|
+
console.log(APP_PREFIX, '🪲. Debug Saved to', this.logFilePath);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
toString() {
|
|
99
|
+
return 'Debug Reporter';
|
|
100
|
+
}
|
|
119
101
|
}
|
|
120
|
-
exports.DebugPipe = DebugPipe;
|
|
121
102
|
|
|
122
|
-
module.exports
|
|
103
|
+
module.exports = DebugPipe;
|