@luigi-project/testing-utilities 2.9.1-dev.202402191437 → 2.9.1-dev.202402280955

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,14 +1,20 @@
1
1
  export declare class LuigiMockUtil {
2
2
  private messages;
3
3
  private browser;
4
- constructor(browser: any);
4
+ private win;
5
+ constructor(browser: any, win: any);
6
+ /**
7
+ * Returns the global window object.
8
+ * @returns the glboal win object
9
+ */
10
+ private getGlobalThis;
5
11
  /**
6
12
  * Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
7
13
  * @returns {Promise<void>} - A Promise that resolves when parsing is complete.
8
14
  */
9
15
  parseLuigiMockedMessages(): Promise<void>;
10
16
  /**
11
- * Mocks the context by sending luigi context messegaes with the desired mocked context as parameter.
17
+ * Mocks the context by sending luigi context messages with the desired mocked context as parameter.
12
18
  * @param mockContext an object representing the context to be mocked
13
19
  */
14
20
  mockContext: (mockContext: any) => void;
@@ -1,19 +1,21 @@
1
1
  export class LuigiMockUtil {
2
- constructor(browser) {
2
+ constructor(browser, win) {
3
3
  /**
4
- * Mocks the context by sending luigi context messegaes with the desired mocked context as parameter.
4
+ * Mocks the context by sending luigi context messages with the desired mocked context as parameter.
5
5
  * @param mockContext an object representing the context to be mocked
6
6
  */
7
7
  this.mockContext = (mockContext) => {
8
- const postMessageToLuigi = (context) => {
9
- globalThis.postMessage({ msg: 'luigi.get-context', context }, '*');
8
+ const context = mockContext;
9
+ const targetDocument = this.getGlobalThis();
10
+ const postMessageToLuigi = () => {
11
+ targetDocument.postMessage({ msg: 'luigi.get-context', context }, '*');
10
12
  };
11
13
  try {
12
14
  if (this.browser.executeScript) {
13
- this.browser.executeScript(postMessageToLuigi, mockContext);
15
+ this.browser.executeScript(postMessageToLuigi, context);
14
16
  }
15
17
  else {
16
- this.browser(postMessageToLuigi, mockContext);
18
+ this.browser(postMessageToLuigi);
17
19
  }
18
20
  }
19
21
  catch (e) {
@@ -37,20 +39,21 @@ export class LuigiMockUtil {
37
39
  *
38
40
  */
39
41
  this.mockPathExists = (path, exists) => {
42
+ const targetDocument = this.getGlobalThis();
40
43
  /**
41
44
  * Sets the path exists mock data in sessionStorage.
42
45
  * @param {string} path - The path for which mock data is to be set.
43
46
  * @param {boolean} exists - Boolean indicating whether the path exists.
44
47
  * @returns {void}
45
48
  */
46
- const setPathExistsMockData = (path, exists) => {
47
- globalThis.sessionStorage.clear();
49
+ const setPathExistsMockData = () => {
50
+ targetDocument.sessionStorage.clear();
48
51
  let pathExistsMockData = {
49
52
  pathExists: {
50
53
  [path]: exists
51
54
  }
52
55
  };
53
- globalThis.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
56
+ targetDocument.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
54
57
  };
55
58
  try {
56
59
  if (this.browser.executeScript) {
@@ -66,6 +69,14 @@ export class LuigiMockUtil {
66
69
  };
67
70
  this.messages = [];
68
71
  this.browser = browser;
72
+ this.win = win;
73
+ }
74
+ /**
75
+ * Returns the global window object.
76
+ * @returns the glboal win object
77
+ */
78
+ getGlobalThis() {
79
+ return this.win || globalThis;
69
80
  }
70
81
  /**
71
82
  * Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
@@ -73,7 +84,11 @@ export class LuigiMockUtil {
73
84
  */
74
85
  async parseLuigiMockedMessages() {
75
86
  try {
76
- const getTextNodeValues = async () => Array.from(document.getElementById('luigi-debug-vis-cnt').childNodes).map((item) => item.textContent);
87
+ const getTextNodeValues = () => {
88
+ const targetDocument = this.getGlobalThis();
89
+ const debugCtn = targetDocument.getElementById('luigi-debug-vis-cnt');
90
+ return Array.from((debugCtn === null || debugCtn === void 0 ? void 0 : debugCtn.childNodes) || []).map((item) => item.textContent || '');
91
+ };
77
92
  const textElements = this.browser.executeScript
78
93
  ? await this.browser.executeScript(getTextNodeValues)
79
94
  : await this.browser(getTextNodeValues);
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "microfrontends",
20
20
  "testing"
21
21
  ],
22
- "version": "2.9.1-dev.202402191437",
22
+ "version": "2.9.1-dev.202402280955",
23
23
  "engines": {
24
24
  "node": ">=18"
25
25
  }