@testomatio/reporter 1.1.0-beta.mocha-create.8 → 1.1.0-rc.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 +1 -0
- package/lib/adapter/codecept.js +81 -6
- package/lib/adapter/cucumber/current.js +15 -8
- package/lib/adapter/cucumber/legacy.js +2 -1
- package/lib/adapter/cypress-plugin/index.js +46 -26
- package/lib/adapter/jest.js +39 -0
- package/lib/adapter/mocha.js +59 -7
- package/lib/adapter/playwright.js +21 -9
- package/lib/bin/startTest.js +2 -1
- package/lib/client.js +46 -44
- package/lib/config.js +5 -0
- package/lib/data-storage.js +203 -0
- package/lib/junit-adapter/index.js +3 -2
- package/lib/pipe/testomatio.js +2 -1
- package/lib/reporter-functions.js +21 -9
- package/lib/reporter.js +8 -1
- package/lib/{storages/artifact-storage.js → services/artifacts.js} +17 -30
- package/lib/services/index.js +13 -0
- package/lib/{storages/key-value-storage.js → services/key-values.js} +18 -18
- package/lib/{storages → services}/logger.js +32 -20
- package/lib/utils/utils.js +13 -4
- package/lib/xmlReader.js +106 -104
- package/package.json +2 -2
- package/Changelog.md +0 -367
- package/lib/storages/data-storage.js +0 -307
package/Changelog.md
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
<!-- pending release updates -->
|
|
2
|
-
# 1.1.0
|
|
3
|
-
|
|
4
|
-
* Assign Run by label:
|
|
5
|
-
|
|
6
|
-
```
|
|
7
|
-
TESTOMATIO={API_KEY} TESTOMATIO_LABEL="release,module:checkout" <actual run command>
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
# 1.0.18
|
|
11
|
-
|
|
12
|
-
* Fixed stack traces for CodeceptJS
|
|
13
|
-
|
|
14
|
-
# 1.0.17
|
|
15
|
-
|
|
16
|
-
Renamed `TESTOMATIO_STACK_FILTER` to `TESTOMATIO_STACK_IGNORE`
|
|
17
|
-
|
|
18
|
-
# 1.0.16
|
|
19
|
-
|
|
20
|
-
* Addded [stack trace configuration](./docs/stacktrace.md) and documentation:
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
TESTOMATIO_STACK_IGNORE="tests/support/**.js" <actual-run-command>
|
|
24
|
-
```
|
|
25
|
-
* Jest: fixed reporting tests without a suite title
|
|
26
|
-
|
|
27
|
-
# 1.0.15
|
|
28
|
-
|
|
29
|
-
* Attach Run to Jira Issue via `TESTOMATIO_JIRA_ID` env variable:
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
TESTOMATIO_JIRA_ID=TST-12 <actual run command>
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
* Mocha - removed requirement of TESTOMATIO API Key
|
|
36
|
-
|
|
37
|
-
# 1.0.14
|
|
38
|
-
|
|
39
|
-
* Execute tests by tag names. Use this filter to select tests associated with specific tags.
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
TESTOMATIO={API_KEY} npx start-test-run -c 'actual run command' --filter 'testomatio:tag-name=smoke'
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
* more instruction you can find in docs/pipes/testomatio.md
|
|
46
|
-
|
|
47
|
-
# 1.0.13
|
|
48
|
-
|
|
49
|
-
* JUnit improvements
|
|
50
|
-
* Match test from source code by adding Test ID as a comment:
|
|
51
|
-
|
|
52
|
-
```java
|
|
53
|
-
// @T8acca9eb
|
|
54
|
-
```
|
|
55
|
-
* Match test from output by adding Test ID as output:
|
|
56
|
-
|
|
57
|
-
```java
|
|
58
|
-
System.out.println("tid://@T8acca9eb");
|
|
59
|
-
```
|
|
60
|
-
* Support for suite before and after output
|
|
61
|
-
* Improved support for artifacts
|
|
62
|
-
|
|
63
|
-
# 1.0.12
|
|
64
|
-
|
|
65
|
-
& Logger refactoring by @olexandr13 in #208
|
|
66
|
-
* fix undefined logs by @olexandr13 in #210
|
|
67
|
-
|
|
68
|
-
# 1.0.11
|
|
69
|
-
|
|
70
|
-
* fix steps duplication for codecept report by @olexandr13 in #209
|
|
71
|
-
|
|
72
|
-
# 1.0.10
|
|
73
|
-
|
|
74
|
-
* Added `TESTOMATIO_PUBLISH=1` variable to automatically publish run report
|
|
75
|
-
|
|
76
|
-
# 1.0.9
|
|
77
|
-
|
|
78
|
-
* Support XUnit format
|
|
79
|
-
* Improved support for parametrized Java tests
|
|
80
|
-
|
|
81
|
-
# 1.0.8
|
|
82
|
-
|
|
83
|
-
* Fixed `Can't read push of undefined` when logging steps
|
|
84
|
-
|
|
85
|
-
# 1.0.6
|
|
86
|
-
|
|
87
|
-
* Testomat.io. Auto-detect current build url and report it to Testomat.io. Manually url can be set with `BUILD_URL` variable:
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
BUILD_URL=https://.... TESTOMATIO=apiKey <actual test command>
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
# 1.0.5
|
|
94
|
-
|
|
95
|
-
* Fix "create tests" params processing for testomatio pipe
|
|
96
|
-
|
|
97
|
-
# 1.0.4
|
|
98
|
-
|
|
99
|
-
* Fixed parallel run
|
|
100
|
-
|
|
101
|
-
# 1.0.3
|
|
102
|
-
|
|
103
|
-
* Fixed reporting parallel runs
|
|
104
|
-
|
|
105
|
-
# 1.0.0
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* Added [`TESTOMATIO_SHARED_RUN` option](https://github.com/testomatio/reporter/blob/master/docs/pipes.md#reporting-parallel-execution-to-to-same-run) to use a shared run for parallel executions
|
|
109
|
-
* Reworked [documentation](https://github.com/testomatio/reporter/tree/master#readme).
|
|
110
|
-
* Added an option to obtain [S3 configuration](https://github.com/testomatio/reporter/blob/master/docs/artifacts.md#configuration) from Testomat.io
|
|
111
|
-
* Introduced [pipes](https://github.com/testomatio/reporter/blob/master/docs/pipes.md):
|
|
112
|
-
* GitHub
|
|
113
|
-
* GitLab
|
|
114
|
-
* CSV Pipe
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
# 0.7.6
|
|
118
|
-
|
|
119
|
-
* Updated to use AWS S3 3.0 SDK for uploading
|
|
120
|
-
|
|
121
|
-
# 0.7.5
|
|
122
|
-
|
|
123
|
-
* Fixed reporting skipped tests in mocha
|
|
124
|
-
|
|
125
|
-
# 0.7.4
|
|
126
|
-
|
|
127
|
-
* Fixed parsing source code in JUnit files
|
|
128
|
-
|
|
129
|
-
# 0.7.3
|
|
130
|
-
|
|
131
|
-
* CodeceptJS: Upload all traces and videos from artifacts
|
|
132
|
-
* Fixed reporting skipped test in XML
|
|
133
|
-
* added `--timelimit` option to `report-xml` command line
|
|
134
|
-
|
|
135
|
-
# 0.7.2
|
|
136
|
-
|
|
137
|
-
* Fixed uploading non-existing file
|
|
138
|
-
|
|
139
|
-
# 0.7.1
|
|
140
|
-
|
|
141
|
-
* Support for NUnit XML v3 format
|
|
142
|
-
|
|
143
|
-
# 0.7.0
|
|
144
|
-
|
|
145
|
-
* Support for `@cucumber/cucumber` (>= 7.0) added
|
|
146
|
-
* Initial support for C# and NUnit
|
|
147
|
-
|
|
148
|
-
# 0.6.10
|
|
149
|
-
|
|
150
|
-
* Fixed uploading multilpe artifacts in Playwright
|
|
151
|
-
|
|
152
|
-
# 0.6.9
|
|
153
|
-
|
|
154
|
-
* Fixed pending tests reports for Cypress
|
|
155
|
-
|
|
156
|
-
# 0.6.8
|
|
157
|
-
# 0.6.7
|
|
158
|
-
|
|
159
|
-
* Pytest: fixed creating suites from reports
|
|
160
|
-
|
|
161
|
-
# 0.6.6
|
|
162
|
-
|
|
163
|
-
* JUnit reporter: prefer suite title over testcase classname in a report
|
|
164
|
-
|
|
165
|
-
# 0.6.5
|
|
166
|
-
|
|
167
|
-
* Fixed test statuses for runs in JUnit reporter
|
|
168
|
-
|
|
169
|
-
# 0.6.4
|
|
170
|
-
|
|
171
|
-
* Added `TESTOMATIO_PROCEED=1` param to not close current run
|
|
172
|
-
* Fixed priority of commands from `npx @testomatio/reporter`
|
|
173
|
-
|
|
174
|
-
# 0.6.3
|
|
175
|
-
|
|
176
|
-
* Fixed `npx start-test-run` to launch commands
|
|
177
|
-
|
|
178
|
-
# 0.6.2
|
|
179
|
-
|
|
180
|
-
* Added `--env-file` option to load env variables from env file
|
|
181
|
-
|
|
182
|
-
# 0.6.1
|
|
183
|
-
|
|
184
|
-
* Fixed creating RunGroup with JUnit reporter
|
|
185
|
-
|
|
186
|
-
# 0.6.0
|
|
187
|
-
|
|
188
|
-
* JUnit reporter support
|
|
189
|
-
|
|
190
|
-
# 0.5.10
|
|
191
|
-
|
|
192
|
-
* Fixed reporting Scenario Outline in Cypress-Cucumber
|
|
193
|
-
* Fixed error reports for Cypress when running in Chrome
|
|
194
|
-
|
|
195
|
-
# 0.5.9
|
|
196
|
-
|
|
197
|
-
* Added environment on Cypress report
|
|
198
|
-
|
|
199
|
-
# 0.5.8
|
|
200
|
-
|
|
201
|
-
* Fixed Cypress.io reporting
|
|
202
|
-
|
|
203
|
-
# 0.5.7
|
|
204
|
-
|
|
205
|
-
* Fixed webdriverio artifacts
|
|
206
|
-
|
|
207
|
-
# 0.5.6
|
|
208
|
-
|
|
209
|
-
* Unmark failed CodeceptJS tests as skipped
|
|
210
|
-
|
|
211
|
-
# 0.5.5
|
|
212
|
-
|
|
213
|
-
* Fixed `BeforeSuite` failures in CodeceptJS
|
|
214
|
-
|
|
215
|
-
# 0.5.4
|
|
216
|
-
|
|
217
|
-
Added `TESTOMATIO_CREATE=1` option to create unmatched tests on report
|
|
218
|
-
|
|
219
|
-
```
|
|
220
|
-
TESTOMATIO_CREATE=1 TESTOMATIO=apiKey npx codeceptjs run
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
# 0.5.3
|
|
224
|
-
|
|
225
|
-
* Fixed parsing suites
|
|
226
|
-
|
|
227
|
-
# 0.5.2
|
|
228
|
-
|
|
229
|
-
* Fixed multiple upload of artifacts in Cypress.io
|
|
230
|
-
|
|
231
|
-
# 0.5.1
|
|
232
|
-
|
|
233
|
-
* Fixed Cypress.io to report tests inside nested suites
|
|
234
|
-
|
|
235
|
-
# 0.5.0
|
|
236
|
-
|
|
237
|
-
* Added Cypress.io plugin
|
|
238
|
-
* Added artifacts upload to webdriverio
|
|
239
|
-
|
|
240
|
-
# 0.4.6
|
|
241
|
-
|
|
242
|
-
- Fixed CodeceptJS reporter to report tests failed in hooks
|
|
243
|
-
|
|
244
|
-
# 0.4.5
|
|
245
|
-
|
|
246
|
-
- Fixed "Total XX artifacts publicly uploaded to S3 bucket" when no S3 bucket is configured
|
|
247
|
-
- Improved S3 connection error messages
|
|
248
|
-
|
|
249
|
-
# 0.4.4
|
|
250
|
-
|
|
251
|
-
- Fixed returning 0 exit code when a process fails when running tests in parallel via `start-test-run`. Previously was using the last exit code returned by a process. Currently prefers the highest exit code that was returned by a process.
|
|
252
|
-
|
|
253
|
-
# 0.4.3
|
|
254
|
-
|
|
255
|
-
- Added `TESTOMATIO_DISABLE_ARTIFACTS` env variable to disable publishing artifacts.
|
|
256
|
-
|
|
257
|
-
# 0.4.2
|
|
258
|
-
|
|
259
|
-
- print version of reporter
|
|
260
|
-
- print number of uploaded artifacts
|
|
261
|
-
- print access mode for uploaded artifacts
|
|
262
|
-
|
|
263
|
-
# 0.4.1
|
|
264
|
-
|
|
265
|
-
Added `global.testomatioArtifacts = []` array which can be used to add arbitrary artifacts to a report.
|
|
266
|
-
|
|
267
|
-
```js
|
|
268
|
-
// inside a running test:
|
|
269
|
-
global.testomatioArtifacts.push('file/to/upload.png');
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
# 0.4.0
|
|
273
|
-
|
|
274
|
-
- Playwright: Introduced playwright/test support with screenshots and video artifacts
|
|
275
|
-
|
|
276
|
-
> Known issues: reporting using projects configured in Playwright does not work yet
|
|
277
|
-
|
|
278
|
-
- CodeceptJS: added video uploads
|
|
279
|
-
|
|
280
|
-
# 0.3.16
|
|
281
|
-
|
|
282
|
-
- CodeceptJS: fixed reporting tests with empty steps (on retry)
|
|
283
|
-
|
|
284
|
-
# 0.3.15
|
|
285
|
-
|
|
286
|
-
- Finish Run via API:
|
|
287
|
-
|
|
288
|
-
```
|
|
289
|
-
TESTOMATIO={apiKey} TESTOMATIO_RUN={runId} npx @testomatio/reporter@latest --finish
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
# 0.3.14
|
|
293
|
-
|
|
294
|
-
- Create an empty Run via API:
|
|
295
|
-
|
|
296
|
-
```
|
|
297
|
-
TESTOMATIO={apiKey} npx @testomatio/reporter@latest --launch
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
# 0.3.13
|
|
301
|
-
|
|
302
|
-
- Checking for a valid report URL
|
|
303
|
-
- Sending unlimited data on test report
|
|
304
|
-
|
|
305
|
-
# 0.3.12
|
|
306
|
-
|
|
307
|
-
- Fixed submitting arbitrary data on a test run
|
|
308
|
-
- Jest: fixed sending errors with stack traces
|
|
309
|
-
- Cypress: fixed sending reports
|
|
310
|
-
|
|
311
|
-
# 0.3.11
|
|
312
|
-
|
|
313
|
-
- Fixed circular JSON reference when submitting data to Testomatio
|
|
314
|
-
|
|
315
|
-
# 0.3.10
|
|
316
|
-
|
|
317
|
-
- Minor fixes
|
|
318
|
-
|
|
319
|
-
# 0.3.9
|
|
320
|
-
|
|
321
|
-
- Making all reporters to run without API key
|
|
322
|
-
|
|
323
|
-
# 0.3.8
|
|
324
|
-
|
|
325
|
-
- Fixed `npx start-test-run` to work with empty API keys
|
|
326
|
-
|
|
327
|
-
# 0.3.7
|
|
328
|
-
|
|
329
|
-
- Fixed release
|
|
330
|
-
|
|
331
|
-
# 0.3.6
|
|
332
|
-
|
|
333
|
-
- Update title and rungroup on start for scheduled runs.
|
|
334
|
-
|
|
335
|
-
# 0.3.5
|
|
336
|
-
|
|
337
|
-
- Added `TESTOMATIO_RUN` environment variable to pass id of a specific run to report
|
|
338
|
-
|
|
339
|
-
# 0.3.4
|
|
340
|
-
|
|
341
|
-
- Minor fixes
|
|
342
|
-
|
|
343
|
-
# 0.3.3
|
|
344
|
-
|
|
345
|
-
- [CodeceptJS] Fixed stack trace reporting
|
|
346
|
-
- [CodeceptJS] Fixed displaying of nested steps
|
|
347
|
-
- [CodeceptJS][mocha] Added assertion diff to report
|
|
348
|
-
|
|
349
|
-
# 0.3.2
|
|
350
|
-
|
|
351
|
-
- Fixed error message for S3 uploading
|
|
352
|
-
|
|
353
|
-
# 0.3.1
|
|
354
|
-
|
|
355
|
-
- [CodeceptJS] Better formatter for nested structures and BDD tests
|
|
356
|
-
|
|
357
|
-
# 0.3.0
|
|
358
|
-
|
|
359
|
-
- Added `TESTOMATIO_TITLE` env variable to set a name for Run
|
|
360
|
-
- Added `TESTOMATIO_RUNGROUP_TITLE` env variable to attach Run to RunGroup
|
|
361
|
-
- Added `TESTOMATIO_ENV` env variable to attach additional env values to report
|
|
362
|
-
- [CodeceptJS] **CodeceptJS v3 support**
|
|
363
|
-
- [CodeceptJS] Dropped support for CodeceptJS 2
|
|
364
|
-
- [CodeceptJS] Added support for before hooks
|
|
365
|
-
- [CodeceptJS] Log of steps
|
|
366
|
-
- [CodeceptJS] Upload screenshots of failed tests to S3
|
|
367
|
-
- [CodeceptJS] Updated to use with parallel execution
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
const debug = require('debug')('@testomatio/reporter:storage');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const { join } = require('path');
|
|
6
|
-
const { TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
|
|
7
|
-
const { fileSystem, jestHelpers, parseTest } = require('../utils/utils');
|
|
8
|
-
|
|
9
|
-
const getTestIdFromTestTitle = parseTest;
|
|
10
|
-
|
|
11
|
-
class DataStorage {
|
|
12
|
-
/**
|
|
13
|
-
* Creates data storage instance for specific data type.
|
|
14
|
-
* Stores data to global variable or to file depending on what is applicable for current test runner
|
|
15
|
-
* (running environment).
|
|
16
|
-
* Recommend to use composition while using this class (instead of inheritance).
|
|
17
|
-
* ! Also the class which will use data storage should be singleton (to avoid data loss).
|
|
18
|
-
* @param {*} dataType storage type (like 'log', 'artifact'); could be any string, used only to define file path
|
|
19
|
-
*/
|
|
20
|
-
constructor(dataType) {
|
|
21
|
-
this.dataType = dataType || 'data';
|
|
22
|
-
this.isFileStorage = true;
|
|
23
|
-
this.#refreshStorageType();
|
|
24
|
-
|
|
25
|
-
this.dataDirPath = path.join(TESTOMAT_TMP_STORAGE_DIR, this.dataType);
|
|
26
|
-
|
|
27
|
-
// set test title for mocha (could not be moved to adapter)
|
|
28
|
-
// it does not override existing hook, just add new one
|
|
29
|
-
try {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
if (!beforeEach) return;
|
|
32
|
-
// @ts-ignore-next-line
|
|
33
|
-
beforeEach(function () {
|
|
34
|
-
if (this.currentTest?.__mocha_id__) {
|
|
35
|
-
global.testTitle = this.currentTest.fullTitle();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
} catch (e) {
|
|
39
|
-
// ignore
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// set test title for playwright
|
|
43
|
-
try {
|
|
44
|
-
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved
|
|
45
|
-
const { test } = require('@playwright/test');
|
|
46
|
-
// eslint-disable-next-line no-empty-pattern
|
|
47
|
-
test.beforeEach(async ({}, testInfo) => {
|
|
48
|
-
global.testTitle = testInfo.title;
|
|
49
|
-
global.testomatioRunningEnvironment = 'playwright';
|
|
50
|
-
});
|
|
51
|
-
} catch (e) {
|
|
52
|
-
// ignore
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Try to define the running environment. Not 100% reliable and used as additional check
|
|
58
|
-
* @returns jest | mocha | ...
|
|
59
|
-
*/
|
|
60
|
-
getRunningEnviroment() {
|
|
61
|
-
// jest
|
|
62
|
-
if (process.env.JEST_WORKER_ID) return 'jest';
|
|
63
|
-
|
|
64
|
-
if (global.codeceptjs) return 'codeceptjs';
|
|
65
|
-
|
|
66
|
-
// 'cucumber:current', 'cucumber:legacy'
|
|
67
|
-
if (global.testomatioRunningEnvironment) return global.testomatioRunningEnvironment;
|
|
68
|
-
|
|
69
|
-
if (process.env.PLAYWRIGHT_TEST_BASE_URL || process.env.TEST_WORKER_INDEX) return 'playwright';
|
|
70
|
-
|
|
71
|
-
// mocha - can't detect
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Puts any data to storage (file or global variable).
|
|
77
|
-
* If file: stores data as text, if global variable – stores as array of data.
|
|
78
|
-
* @param {*} data anything you want to store (string, object, array, etc)
|
|
79
|
-
* @param {*} context could be testId or any context (test, suite, etc) which is used to define testId
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
putData(data, context = null) {
|
|
83
|
-
fileSystem.createDir(this.dataDirPath);
|
|
84
|
-
|
|
85
|
-
this.#refreshStorageType();
|
|
86
|
-
context = context ?? global.testTitle ?? null;
|
|
87
|
-
let testId = this.#tryToRetrieveTestId(context) || context || null;
|
|
88
|
-
|
|
89
|
-
if (this.runningEnvironment === 'codeceptjs') {
|
|
90
|
-
this.isFileStorage = false;
|
|
91
|
-
testId = testId ?? global.testomatioDataStore?.currentlyRunningTestId;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (this.runningEnvironment === 'jest') {
|
|
95
|
-
testId = testId ?? jestHelpers.getIdOfCurrentlyRunningTest();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// logs in playwright are gathered by pw framework itself
|
|
99
|
-
if (this.runningEnvironment === 'playwright' && this.dataType === 'log') return;
|
|
100
|
-
|
|
101
|
-
// get id from global store
|
|
102
|
-
if (global.testomatioDataStore && global.testomatioDataStore.currentlyRunningTestId)
|
|
103
|
-
testId = testId ?? global.testomatioDataStore?.currentlyRunningTestId;
|
|
104
|
-
|
|
105
|
-
if (!testId && global?.currentlyRunningTestTitle)
|
|
106
|
-
testId = this.#tryToRetrieveTestId(global.currentlyRunningTestTitle);
|
|
107
|
-
|
|
108
|
-
if (!testId) {
|
|
109
|
-
debug(`No test id provided for "${this.dataType}" data:`, data);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (this.isFileStorage) {
|
|
114
|
-
this.#putDataToFile(data, testId);
|
|
115
|
-
} else {
|
|
116
|
-
this.#putDataToGlobalVar(data, testId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Returns data, stored for specific testId (or data which was stored without test id specified).
|
|
122
|
-
* This method will get data from global variable and/or from from file (previosly saved with put method).
|
|
123
|
-
*
|
|
124
|
-
* @param {*} context could be testId or any context (test title, suite, etc) which is used to define testId
|
|
125
|
-
* @returns array of data (any type), null (if no data found for test) or string (if data type is log)
|
|
126
|
-
*/
|
|
127
|
-
getData(context) {
|
|
128
|
-
this.#refreshStorageType();
|
|
129
|
-
|
|
130
|
-
let testId = null;
|
|
131
|
-
if (typeof context === 'string') {
|
|
132
|
-
testId = this.#tryToRetrieveTestId(context) || context;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!testId) {
|
|
136
|
-
debug(`Cannot get test id from passed context:`, context);
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let testDataFromFile = [];
|
|
141
|
-
let testDataFromGlobalVar = [];
|
|
142
|
-
|
|
143
|
-
if (global?.testomatioDataStore) {
|
|
144
|
-
testDataFromGlobalVar = this.#getDataFromGlobalVar(testId);
|
|
145
|
-
// these frameworks use global variable storage
|
|
146
|
-
// if (testDataFromGlobalVar && ['cucumber', 'codeceptjs'].includes(this.runningEnvironment)) {
|
|
147
|
-
if (testDataFromGlobalVar) {
|
|
148
|
-
// return as string if its log data
|
|
149
|
-
if (this.dataType === 'log' && testDataFromGlobalVar.length) return testDataFromGlobalVar.join('\n');
|
|
150
|
-
// return as array for other data types
|
|
151
|
-
if (testDataFromGlobalVar.length) return testDataFromGlobalVar;
|
|
152
|
-
}
|
|
153
|
-
// don't return nothing if no data in global variable
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/* condition is removed for mocha
|
|
157
|
-
mocha has created a global storage, but just in some cases, generally it is not available
|
|
158
|
-
*/
|
|
159
|
-
// if (this.isFileStorage || !testData) {
|
|
160
|
-
// testData = this.#getDataFromFile(testId);
|
|
161
|
-
// if (testData) return testData;
|
|
162
|
-
// }
|
|
163
|
-
|
|
164
|
-
testDataFromFile = this.#getDataFromFile(testId);
|
|
165
|
-
|
|
166
|
-
if (testDataFromFile.length) {
|
|
167
|
-
if (this.dataType === 'log') return testDataFromFile.join('\n');
|
|
168
|
-
return testDataFromFile;
|
|
169
|
-
}
|
|
170
|
-
debug(`No "${this.dataType}" data for test id ${testId} in both file and global variable`);
|
|
171
|
-
|
|
172
|
-
// in case no data found for test
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* This method is named as "try" because it does not guarantee that test id could be retrieved.
|
|
178
|
-
* Context could be anything (test, suite, string, etc) which is used to define testId.
|
|
179
|
-
* Or it could represent any other entity (which does not contain test id).
|
|
180
|
-
* @param {*} context
|
|
181
|
-
*/
|
|
182
|
-
#tryToRetrieveTestId(context) {
|
|
183
|
-
if (!context) return null;
|
|
184
|
-
this.#refreshStorageType();
|
|
185
|
-
|
|
186
|
-
if (this.runningEnvironment === 'playwright' || context?.title) {
|
|
187
|
-
// context is testInfo
|
|
188
|
-
const testId = getTestIdFromTestTitle(context.title);
|
|
189
|
-
if (testId) return testId;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (typeof context === 'string') {
|
|
193
|
-
const testId = getTestIdFromTestTitle(context);
|
|
194
|
-
if (testId) return testId;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Refreshes storage type (file or global variable) depending on current environment
|
|
202
|
-
* This method should be run on each attempt to put or get data from/to storage
|
|
203
|
-
* Because storage instance is created before the test runner is started. And storage type could be changed
|
|
204
|
-
*/
|
|
205
|
-
#refreshStorageType() {
|
|
206
|
-
this.runningEnvironment = this.getRunningEnviroment();
|
|
207
|
-
|
|
208
|
-
// some test frameworks do not persist global variables, thus file storage is used for them (by default)
|
|
209
|
-
if (this.runningEnvironment === 'codeceptjs') this.isFileStorage = false;
|
|
210
|
-
// playwrigth stores logs by itself; but file storage is used for other data types for playwright
|
|
211
|
-
if (this.runningEnvironment === 'playwright' && this.dataType === 'log') this.isFileStorage = false;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* @param {*} testId
|
|
216
|
-
* @returns aray of data (any type)
|
|
217
|
-
*/
|
|
218
|
-
#getDataFromGlobalVar(testId) {
|
|
219
|
-
try {
|
|
220
|
-
if (global?.testomatioDataStore[this.dataType]) {
|
|
221
|
-
const testData = global.testomatioDataStore[this.dataType][testId];
|
|
222
|
-
if (testData) debug(`"${this.dataType}" data for test id ${testId}:`, testData.join(', '));
|
|
223
|
-
return testData || [];
|
|
224
|
-
}
|
|
225
|
-
// debug(`No ${this.dataType} data for test id ${testId} in <global> storage`);
|
|
226
|
-
return [];
|
|
227
|
-
} catch (e) {
|
|
228
|
-
// there could be no data, ignore
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
* @param {*} testId
|
|
235
|
-
* @returns array of data (any type)
|
|
236
|
-
*/
|
|
237
|
-
#getDataFromFile(testId) {
|
|
238
|
-
try {
|
|
239
|
-
const filepath = join(this.dataDirPath, `${this.dataType}_${testId}`);
|
|
240
|
-
if (fs.existsSync(filepath)) {
|
|
241
|
-
const testDataAsText = fs.readFileSync(filepath, 'utf-8');
|
|
242
|
-
if (testDataAsText) debug(`"${this.dataType}" data for test id ${testId}:`, testDataAsText);
|
|
243
|
-
const testDataArr = testDataAsText?.split(os.EOL) || [];
|
|
244
|
-
return testDataArr;
|
|
245
|
-
}
|
|
246
|
-
// debug(`No ${this.dataType} data for test id ${testId} in <file> storage`);
|
|
247
|
-
return [];
|
|
248
|
-
} catch (e) {
|
|
249
|
-
// there could be no data, ignore
|
|
250
|
-
}
|
|
251
|
-
return [];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Puts data to global variable. Unlike the file storage, stores data in array (file storage just append as string).
|
|
256
|
-
* @param {*} data
|
|
257
|
-
* @param {*} testId
|
|
258
|
-
*/
|
|
259
|
-
#putDataToGlobalVar(data, testId) {
|
|
260
|
-
debug(`Saving data to global variable for test ${testId}:`, data);
|
|
261
|
-
if (!global.testomatioDataStore) global.testomatioDataStore = {};
|
|
262
|
-
if (!global.testomatioDataStore?.[this.dataType]) global.testomatioDataStore[this.dataType] = {};
|
|
263
|
-
|
|
264
|
-
if (!global.testomatioDataStore?.[this.dataType][testId]) global.testomatioDataStore[this.dataType][testId] = [];
|
|
265
|
-
global.testomatioDataStore[this.dataType][testId].push(data);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
#putDataToFile(data, testId) {
|
|
269
|
-
if (typeof data !== 'string') data = JSON.stringify(data);
|
|
270
|
-
const filename = `${this.dataType}_${testId}`;
|
|
271
|
-
const filepath = join(this.dataDirPath, filename);
|
|
272
|
-
if (!fs.existsSync(this.dataDirPath)) fileSystem.createDir(this.dataDirPath);
|
|
273
|
-
debug('Saving data to file for test', testId, 'to', filepath, ':\n', data, '\n');
|
|
274
|
-
|
|
275
|
-
// append new line if file already exists (in this case its definitely includes some data)
|
|
276
|
-
if (fs.existsSync(filepath)) {
|
|
277
|
-
fs.appendFileSync(filepath, os.EOL + data, 'utf-8');
|
|
278
|
-
} else {
|
|
279
|
-
fs.writeFileSync(filepath, data, 'utf-8');
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
module.exports = DataStorage;
|
|
285
|
-
|
|
286
|
-
// TODO: consider using fs promises instead of writeSync/appendFileSync to
|
|
287
|
-
// prevent blocking and improve performance (probably queue usage will be required)
|
|
288
|
-
|
|
289
|
-
// TODO: rewrite client - everything regarding storing artifacts
|
|
290
|
-
// TODO: try to define adapter inside client
|
|
291
|
-
// TODO: ability to intercept multiple loggers (upd: no need)
|
|
292
|
-
|
|
293
|
-
/* does not work for Playwright
|
|
294
|
-
try {
|
|
295
|
-
const { test } = require('@playwright/test');
|
|
296
|
-
test.beforeEach(async ({}, testInfo) => {
|
|
297
|
-
global.testTitle = testInfo.title;
|
|
298
|
-
global.testomatioRunningEnvironment = 'playwright';
|
|
299
|
-
});
|
|
300
|
-
} catch (e) {
|
|
301
|
-
// ignore
|
|
302
|
-
}
|
|
303
|
-
// Playwright storage works fine only when running tests from a single file;
|
|
304
|
-
// otherwise it is not possible to define test id/title, it is overwritten
|
|
305
|
-
TODO: the only way implementation for Pw for now is to pass testInfo inside test
|
|
306
|
-
// (and process this testInfo inside "put" function)
|
|
307
|
-
*/
|