@luigi-project/testing-utilities 2.8.1-dev.20240220908 → 2.8.1-dev.20240221227
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-engine.js +2 -0
- package/luigi-mock-util.js +36 -7
- package/package.json +3 -13
package/luigi-mock-engine.js
CHANGED
|
@@ -50,6 +50,7 @@ export class LuigiMockEngine {
|
|
|
50
50
|
},
|
|
51
51
|
mockListeners: {
|
|
52
52
|
'luigi.navigation.pathExists': (event) => {
|
|
53
|
+
console.log('######luigi.navigation.pathExists');
|
|
53
54
|
const mockData = window.sessionStorage.getItem('luigiMockData');
|
|
54
55
|
let mockDataParsed = mockData ? JSON.parse(mockData) : undefined;
|
|
55
56
|
const inputPath = event.data.data.link;
|
|
@@ -136,6 +137,7 @@ export class LuigiMockEngine {
|
|
|
136
137
|
* which holds data that is useful for e2e testing.
|
|
137
138
|
*/
|
|
138
139
|
static visualize(data) {
|
|
140
|
+
console.log('#######testsetset visualize');
|
|
139
141
|
let luigiVisualizationContainer = document.querySelector('#luigi-debug-vis-cnt');
|
|
140
142
|
// Construct element structure if not already constructed
|
|
141
143
|
if (!luigiVisualizationContainer) {
|
package/luigi-mock-util.js
CHANGED
|
@@ -5,9 +5,21 @@ 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
|
+
console.log('mockContext');
|
|
17
|
+
this.browser(postMessageToLuigi, mockContext);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.debug('Failed to mock context: ', e);
|
|
22
|
+
}
|
|
11
23
|
};
|
|
12
24
|
/**
|
|
13
25
|
* This method serves as a mock for the luigi client pathExists() function.
|
|
@@ -26,7 +38,7 @@ export class LuigiMockUtil {
|
|
|
26
38
|
*
|
|
27
39
|
*/
|
|
28
40
|
this.mockPathExists = (path, exists) => {
|
|
29
|
-
|
|
41
|
+
const setPathExistsMockData = (path, exists) => {
|
|
30
42
|
globalThis.sessionStorage.clear();
|
|
31
43
|
let pathExistsMockData = {
|
|
32
44
|
pathExists: {
|
|
@@ -34,7 +46,20 @@ export class LuigiMockUtil {
|
|
|
34
46
|
}
|
|
35
47
|
};
|
|
36
48
|
globalThis.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
|
|
37
|
-
}
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
if (this.browser.executeScript) {
|
|
52
|
+
this.browser.executeScript(setPathExistsMockData, path, exists);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log('mockPathExists');
|
|
56
|
+
this.browser(setPathExistsMockData, path, exists);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.debug('Failed to mock path exists: ', e);
|
|
61
|
+
}
|
|
62
|
+
this.browser.executeScript ? this.browser.executeScript(setPathExistsMockData, path, exists) : this.browser(setPathExistsMockData, path, exists);
|
|
38
63
|
};
|
|
39
64
|
this.messages = [];
|
|
40
65
|
this.browser = browser;
|
|
@@ -44,7 +69,11 @@ export class LuigiMockUtil {
|
|
|
44
69
|
*/
|
|
45
70
|
async parseLuigiMockedMessages() {
|
|
46
71
|
try {
|
|
47
|
-
const
|
|
72
|
+
const getTextNodeValues = async () => Array.from(document.getElementById('luigi-debug-vis-cnt').childNodes).map((item) => item.textContent);
|
|
73
|
+
console.log('parseLuigiMockedMessages');
|
|
74
|
+
const textElements = this.browser.executeScript
|
|
75
|
+
? await this.browser.executeScript(getTextNodeValues)
|
|
76
|
+
: await this.browser(getTextNodeValues);
|
|
48
77
|
this.messages = textElements
|
|
49
78
|
.map((item) => {
|
|
50
79
|
try {
|
|
@@ -54,7 +83,7 @@ export class LuigiMockUtil {
|
|
|
54
83
|
return undefined;
|
|
55
84
|
}
|
|
56
85
|
})
|
|
57
|
-
.filter(item => item !== undefined);
|
|
86
|
+
.filter((item) => item !== undefined);
|
|
58
87
|
}
|
|
59
88
|
catch (e) {
|
|
60
89
|
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.8.1-dev.
|
|
22
|
+
"version": "2.8.1-dev.20240221227",
|
|
33
23
|
"engines": {
|
|
34
24
|
"node": ">=18"
|
|
35
25
|
}
|