@luigi-project/testing-utilities 2.8.1-dev.20240290024 → 2.9.0
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/luigi-mock-util.d.ts +1 -0
- package/luigi-mock-util.js +39 -7
- package/package.json +3 -13
package/luigi-mock-util.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class LuigiMockUtil {
|
|
|
4
4
|
constructor(browser: any);
|
|
5
5
|
/**
|
|
6
6
|
* Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
|
|
7
|
+
* @returns {Promise<void>} - A Promise that resolves when parsing is complete.
|
|
7
8
|
*/
|
|
8
9
|
parseLuigiMockedMessages(): Promise<void>;
|
|
9
10
|
/**
|
package/luigi-mock-util.js
CHANGED
|
@@ -5,9 +5,20 @@ export class LuigiMockUtil {
|
|
|
5
5
|
* @param mockContext an object representing the context to be mocked
|
|
6
6
|
*/
|
|
7
7
|
this.mockContext = (mockContext) => {
|
|
8
|
-
|
|
9
|
-
globalThis.postMessage({ msg: 'luigi.get-context', context
|
|
10
|
-
}
|
|
8
|
+
const postMessageToLuigi = (context) => {
|
|
9
|
+
globalThis.postMessage({ msg: 'luigi.get-context', context }, '*');
|
|
10
|
+
};
|
|
11
|
+
try {
|
|
12
|
+
if (this.browser.executeScript) {
|
|
13
|
+
this.browser.executeScript(postMessageToLuigi, mockContext);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.browser(postMessageToLuigi, mockContext);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.debug('Failed to mock context: ', e);
|
|
21
|
+
}
|
|
11
22
|
};
|
|
12
23
|
/**
|
|
13
24
|
* This method serves as a mock for the luigi client pathExists() function.
|
|
@@ -26,7 +37,13 @@ export class LuigiMockUtil {
|
|
|
26
37
|
*
|
|
27
38
|
*/
|
|
28
39
|
this.mockPathExists = (path, exists) => {
|
|
29
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Sets the path exists mock data in sessionStorage.
|
|
42
|
+
* @param {string} path - The path for which mock data is to be set.
|
|
43
|
+
* @param {boolean} exists - Boolean indicating whether the path exists.
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
const setPathExistsMockData = (path, exists) => {
|
|
30
47
|
globalThis.sessionStorage.clear();
|
|
31
48
|
let pathExistsMockData = {
|
|
32
49
|
pathExists: {
|
|
@@ -34,17 +51,32 @@ export class LuigiMockUtil {
|
|
|
34
51
|
}
|
|
35
52
|
};
|
|
36
53
|
globalThis.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
|
|
37
|
-
}
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
if (this.browser.executeScript) {
|
|
57
|
+
this.browser.executeScript(setPathExistsMockData, path, exists);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.browser(setPathExistsMockData, path, exists);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.debug('Failed to mock path exists: ', e);
|
|
65
|
+
}
|
|
38
66
|
};
|
|
39
67
|
this.messages = [];
|
|
40
68
|
this.browser = browser;
|
|
41
69
|
}
|
|
42
70
|
/**
|
|
43
71
|
* Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
|
|
72
|
+
* @returns {Promise<void>} - A Promise that resolves when parsing is complete.
|
|
44
73
|
*/
|
|
45
74
|
async parseLuigiMockedMessages() {
|
|
46
75
|
try {
|
|
47
|
-
const
|
|
76
|
+
const getTextNodeValues = async () => Array.from(document.getElementById('luigi-debug-vis-cnt').childNodes).map((item) => item.textContent);
|
|
77
|
+
const textElements = this.browser.executeScript
|
|
78
|
+
? await this.browser.executeScript(getTextNodeValues)
|
|
79
|
+
: await this.browser(getTextNodeValues);
|
|
48
80
|
this.messages = textElements
|
|
49
81
|
.map((item) => {
|
|
50
82
|
try {
|
|
@@ -54,7 +86,7 @@ export class LuigiMockUtil {
|
|
|
54
86
|
return undefined;
|
|
55
87
|
}
|
|
56
88
|
})
|
|
57
|
-
.filter(item => item !== undefined);
|
|
89
|
+
.filter((item) => item !== undefined);
|
|
58
90
|
}
|
|
59
91
|
catch (e) {
|
|
60
92
|
console.debug('Failed to parse luigi mocked messages: ', e);
|
package/package.json
CHANGED
|
@@ -2,21 +2,11 @@
|
|
|
2
2
|
"name": "@luigi-project/testing-utilities",
|
|
3
3
|
"description": "Luigi testing utilities for standalone testing of microfrontends",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"build": "tsc && npm run copy",
|
|
9
|
-
"copy": "ncp package.json ./dist/package.json && ncp README.md ./dist/README.md",
|
|
10
|
-
"bundle": "npm run build"
|
|
11
|
-
},
|
|
12
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
13
7
|
"publishConfig": {
|
|
14
8
|
"tag": "testing-utilities"
|
|
15
9
|
},
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"ncp": "^2.0.0",
|
|
18
|
-
"typescript": "4.8.2"
|
|
19
|
-
},
|
|
20
10
|
"repository": {
|
|
21
11
|
"type": "git",
|
|
22
12
|
"url": "ssh://github.com/SAP/luigi.git"
|
|
@@ -29,7 +19,7 @@
|
|
|
29
19
|
"microfrontends",
|
|
30
20
|
"testing"
|
|
31
21
|
],
|
|
32
|
-
"version": "2.
|
|
22
|
+
"version": "2.9.0",
|
|
33
23
|
"engines": {
|
|
34
24
|
"node": ">=18"
|
|
35
25
|
}
|