@testomatio/reporter 2.1.3-beta.2-xml-import → 2.1.3-beta.2-multi-links

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.
@@ -1,69 +0,0 @@
1
- import createDebugMessages from 'debug';
2
- import { dataStorage } from '../data-storage.js';
3
-
4
- const debug = createDebugMessages('@testomatio/reporter:services-links');
5
-
6
- class LinkStorage {
7
- static #instance;
8
-
9
- /**
10
- *
11
- * @returns {LinkStorage}
12
- */
13
- static getInstance() {
14
- if (!this.#instance) {
15
- this.#instance = new LinkStorage();
16
- }
17
- return this.#instance;
18
- }
19
-
20
- /**
21
- * Stores links array and passes it to reporter
22
- * @param {object[]} links - array of link objects
23
- * @param {*} context - full test title
24
- */
25
- put(links, context = null) {
26
- if (!links || !Array.isArray(links)) return;
27
- dataStorage.putData('links', links, context);
28
- }
29
-
30
- /**
31
- * Returns links array for the test
32
- * @param {*} context testId or test context from test runner
33
- * @returns {object[]} links array, e.g. [{test: 'TEST-123'}, {jira: 'JIRA-456'}]
34
- */
35
- get(context = null) {
36
- const linksList = dataStorage.getData('links', context);
37
- if (!linksList || !linksList?.length) return [];
38
-
39
- const allLinks = [];
40
- for (const links of linksList) {
41
- if (Array.isArray(links)) {
42
- allLinks.push(...links);
43
- } else if (typeof links === 'string') {
44
- try {
45
- const parsedLinks = JSON.parse(links);
46
- if (Array.isArray(parsedLinks)) {
47
- allLinks.push(...parsedLinks);
48
- }
49
- } catch (e) {
50
- debug(`Error parsing links for test ${context}`, links);
51
- }
52
- }
53
- }
54
-
55
- // Remove duplicates based on JSON string comparison
56
- const uniqueLinks = [];
57
- const seen = new Set();
58
- for (const link of allLinks) {
59
- const key = JSON.stringify(link);
60
- if (!seen.has(key)) {
61
- seen.add(key);
62
- uniqueLinks.push(link);
63
- }
64
- }
65
- return uniqueLinks;
66
- }
67
- }
68
-
69
- export const linkStorage = LinkStorage.getInstance();