@luigi-project/testing-utilities 2.8.1-dev.20240271713 → 2.8.1-dev.20240280024
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.js +7 -33
- package/package.json +13 -3
package/luigi-mock-util.js
CHANGED
|
@@ -5,20 +5,9 @@ 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
|
-
};
|
|
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
|
-
}
|
|
8
|
+
this.browser.executeScript((mockContext) => {
|
|
9
|
+
globalThis.postMessage({ msg: 'luigi.get-context', context: mockContext }, '*');
|
|
10
|
+
}, mockContext);
|
|
22
11
|
};
|
|
23
12
|
/**
|
|
24
13
|
* This method serves as a mock for the luigi client pathExists() function.
|
|
@@ -37,7 +26,7 @@ export class LuigiMockUtil {
|
|
|
37
26
|
*
|
|
38
27
|
*/
|
|
39
28
|
this.mockPathExists = (path, exists) => {
|
|
40
|
-
|
|
29
|
+
this.browser.executeScript((path, exists) => {
|
|
41
30
|
globalThis.sessionStorage.clear();
|
|
42
31
|
let pathExistsMockData = {
|
|
43
32
|
pathExists: {
|
|
@@ -45,19 +34,7 @@ export class LuigiMockUtil {
|
|
|
45
34
|
}
|
|
46
35
|
};
|
|
47
36
|
globalThis.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
|
|
48
|
-
};
|
|
49
|
-
try {
|
|
50
|
-
if (this.browser.executeScript) {
|
|
51
|
-
this.browser.executeScript(setPathExistsMockData, path, exists);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.browser(setPathExistsMockData, path, exists);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
console.debug('Failed to mock path exists: ', e);
|
|
59
|
-
}
|
|
60
|
-
this.browser.executeScript ? this.browser.executeScript(setPathExistsMockData, path, exists) : this.browser(setPathExistsMockData, path, exists);
|
|
37
|
+
}, path, exists);
|
|
61
38
|
};
|
|
62
39
|
this.messages = [];
|
|
63
40
|
this.browser = browser;
|
|
@@ -67,10 +44,7 @@ export class LuigiMockUtil {
|
|
|
67
44
|
*/
|
|
68
45
|
async parseLuigiMockedMessages() {
|
|
69
46
|
try {
|
|
70
|
-
const
|
|
71
|
-
const textElements = this.browser.executeScript
|
|
72
|
-
? await this.browser.executeScript(getTextNodeValues)
|
|
73
|
-
: await this.browser(getTextNodeValues);
|
|
47
|
+
const textElements = await this.browser.executeScript(() => Array.from(document.getElementById('luigi-debug-vis-cnt').childNodes).map(item => item.textContent));
|
|
74
48
|
this.messages = textElements
|
|
75
49
|
.map((item) => {
|
|
76
50
|
try {
|
|
@@ -80,7 +54,7 @@ export class LuigiMockUtil {
|
|
|
80
54
|
return undefined;
|
|
81
55
|
}
|
|
82
56
|
})
|
|
83
|
-
.filter(
|
|
57
|
+
.filter(item => item !== undefined);
|
|
84
58
|
}
|
|
85
59
|
catch (e) {
|
|
86
60
|
console.debug('Failed to parse luigi mocked messages: ', e);
|
package/package.json
CHANGED
|
@@ -2,11 +2,21 @@
|
|
|
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": "index.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
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",
|
|
7
13
|
"publishConfig": {
|
|
8
14
|
"tag": "testing-utilities"
|
|
9
15
|
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"ncp": "^2.0.0",
|
|
18
|
+
"typescript": "4.8.2"
|
|
19
|
+
},
|
|
10
20
|
"repository": {
|
|
11
21
|
"type": "git",
|
|
12
22
|
"url": "ssh://github.com/SAP/luigi.git"
|
|
@@ -19,7 +29,7 @@
|
|
|
19
29
|
"microfrontends",
|
|
20
30
|
"testing"
|
|
21
31
|
],
|
|
22
|
-
"version": "2.8.1-dev.
|
|
32
|
+
"version": "2.8.1-dev.20240280024",
|
|
23
33
|
"engines": {
|
|
24
34
|
"node": ">=18"
|
|
25
35
|
}
|