@sap-ux/jest-environment-ui5 5.3.7 → 5.3.9
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/package.json +12 -13
- package/src/env/mockXHR.js +2 -2
- package/src/env/ui5loader.js +13 -14
- package/src/index.js +32 -4
- package/src/utils/ui5MappingStrategy.js +56 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/jest-environment-ui5",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.9",
|
|
4
4
|
"description": "Jest matchers for files and folders",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@ui5/cli": "^3",
|
|
27
27
|
"@ui5/project": "^3.9.0",
|
|
28
|
-
"cross-env": "^7.0.3"
|
|
29
|
-
"jest": "^29.7.0"
|
|
28
|
+
"cross-env": "^7.0.3"
|
|
30
29
|
},
|
|
31
30
|
"scripts": {
|
|
32
31
|
"clean": "rimraf --glob dist coverage *.tsbuildinfo",
|
|
@@ -34,18 +33,18 @@
|
|
|
34
33
|
"lint": "eslint . --ext .js",
|
|
35
34
|
"lint:fix": "eslint . --ext .js --fix",
|
|
36
35
|
"test": "pnpm run test-ut && pnpm run testlatest",
|
|
37
|
-
"test-ut": "cross-env NODE_OPTIONS='--experimental-vm-modules' npx jest --ci --forceExit --detectOpenHandles --colors
|
|
36
|
+
"test-ut": "cross-env NODE_OPTIONS='--experimental-vm-modules' npx jest --ci --forceExit --detectOpenHandles --colors --runInBand ",
|
|
38
37
|
"test-e2e": "pnpm run testlatest && pnpm run test71 && pnpm run test84 && pnpm run test96 && pnpm run test108 && pnpm run test120 && pnpm run test124 && pnpm run test127",
|
|
39
38
|
"link": "pnpm link --global",
|
|
40
39
|
"unlink": "pnpm unlink --global",
|
|
41
|
-
"test71": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.71.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
42
|
-
"test84": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.84.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
43
|
-
"test96": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.96.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
44
|
-
"test108": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.108.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
45
|
-
"test120": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.120.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
46
|
-
"test124": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.124.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
47
|
-
"test127": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.127.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
48
|
-
"testlatest": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
49
|
-
"test20": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-2.0.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors
|
|
40
|
+
"test71": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.71.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
41
|
+
"test84": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.84.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
42
|
+
"test96": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.96.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
43
|
+
"test108": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.108.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
44
|
+
"test120": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.120.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
45
|
+
"test124": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.124.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
46
|
+
"test127": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-1.127.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
47
|
+
"testlatest": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors",
|
|
48
|
+
"test20": "cross-env UI5_JEST_CONFIG=test/fixtures/ui5-2.0.yaml jest --config jest-ui5.config.js --ci --forceExit --detectOpenHandles --colors"
|
|
50
49
|
}
|
|
51
50
|
}
|
package/src/env/mockXHR.js
CHANGED
|
@@ -15,8 +15,8 @@ function createMockXHR(globalWindow, pathMappingFn, shimmedFilePath, mockData, X
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Handles the real XHR send.
|
|
18
|
-
* @param mockXHR The mock XHR object.
|
|
19
|
-
* @param data The data to send.
|
|
18
|
+
* @param {object} mockXHR The mock XHR object.
|
|
19
|
+
* @param {object} data The data to send.
|
|
20
20
|
*/
|
|
21
21
|
function handleRealXHRSend(mockXHR, data) {
|
|
22
22
|
realXhr.addEventListener('load', function () {
|
package/src/env/ui5loader.js
CHANGED
|
@@ -599,6 +599,7 @@
|
|
|
599
599
|
* @param {string} sUrlPrefix path to the resource
|
|
600
600
|
*/
|
|
601
601
|
function registerResourcePath(sResourceNamePrefix, sUrlPrefix) {
|
|
602
|
+
|
|
602
603
|
sResourceNamePrefix = String(sResourceNamePrefix || "");
|
|
603
604
|
|
|
604
605
|
if ( sUrlPrefix == null ) {
|
|
@@ -625,7 +626,9 @@
|
|
|
625
626
|
if ( sUrlPrefix.slice(-1) !== '/' ) {
|
|
626
627
|
sUrlPrefix += '/';
|
|
627
628
|
}
|
|
628
|
-
|
|
629
|
+
if(sUrlPrefix === "./" && sResourceNamePrefix === "") {
|
|
630
|
+
sUrlPrefix = "";
|
|
631
|
+
}
|
|
629
632
|
mUrlPrefixes[sResourceNamePrefix] = {
|
|
630
633
|
url: sUrlPrefix,
|
|
631
634
|
// calculate absolute URL, only to be used by 'guessResourceName'
|
|
@@ -995,12 +998,7 @@
|
|
|
995
998
|
const oShim = mShims[this.name],
|
|
996
999
|
sExport = oShim && (Array.isArray(oShim.exports) ? oShim.exports[0] : oShim.exports);
|
|
997
1000
|
// best guess for thirdparty modules or legacy modules that don't use sap.ui.define
|
|
998
|
-
|
|
999
|
-
this.content = window.crossroads;
|
|
1000
|
-
} else {
|
|
1001
|
-
this.content = getGlobalProperty( sExport || urnToUI5(this.name) );
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1001
|
+
this.content = getGlobalProperty(sExport || urnToUI5(this.name));
|
|
1004
1002
|
}
|
|
1005
1003
|
return this.content;
|
|
1006
1004
|
}
|
|
@@ -1765,13 +1763,14 @@
|
|
|
1765
1763
|
})
|
|
1766
1764
|
}
|
|
1767
1765
|
const output = oModule.data.call(__global);
|
|
1768
|
-
if(output && mShims[oModule.name] && mShims[oModule.name].exports && Object.keys(output).length > 0
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1766
|
+
if(output && mShims[oModule.name] && mShims[oModule.name].exports && Object.keys(output).length > 0) {
|
|
1767
|
+
if(global[mShims[oModule.name].exports] ) {
|
|
1768
|
+
global[mShims[oModule.name].exports] = {...global[mShims[oModule.name].exports], ...output}
|
|
1769
|
+
} else if(output[mShims[oModule.name].exports] !== undefined) {
|
|
1770
|
+
global[mShims[oModule.name].exports] = output[mShims[oModule.name].exports];
|
|
1771
|
+
} else {
|
|
1772
|
+
global[mShims[oModule.name].exports] = output;
|
|
1773
|
+
}
|
|
1775
1774
|
}
|
|
1776
1775
|
else if(output && Object.keys(output).length > 0) {
|
|
1777
1776
|
if( Object.keys(oModule.content).length === 0) {
|
package/src/index.js
CHANGED
|
@@ -89,9 +89,7 @@ class UI5DOMEnvironment extends JSDOMEnvironment {
|
|
|
89
89
|
window['sap-ui-no-preload'] = !this.useOptimized;
|
|
90
90
|
window.requireFn(path.join(__dirname, 'env', 'ui5loader'));
|
|
91
91
|
if (this.testEnvironmentOptions.isV2) {
|
|
92
|
-
|
|
93
|
-
scriptTag.setAttribute('src', './ui5loader-autoconfig.js');
|
|
94
|
-
window.document.head.appendChild(scriptTag);
|
|
92
|
+
window.requireFn(window.jestUI5.resolvePath('ui5loader-autoconfig.js'));
|
|
95
93
|
} else {
|
|
96
94
|
window['sap-ui-config'].excludejquerycompat = true;
|
|
97
95
|
sap.ui.requireSync('ui5loader-autoconfig');
|
|
@@ -111,7 +109,6 @@ class UI5DOMEnvironment extends JSDOMEnvironment {
|
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
sap.ui.loader.config({ async: true });
|
|
114
|
-
delete window['sap-ui-config'].resourceRoots;
|
|
115
112
|
|
|
116
113
|
if (!this.testEnvironmentOptions.isV2) {
|
|
117
114
|
this.core = sap.ui.requireSync('sap/ui/core/Core');
|
|
@@ -146,11 +143,25 @@ class UI5DOMEnvironment extends JSDOMEnvironment {
|
|
|
146
143
|
* @param {boolean} allowCSS Whether to allow the UI5 CSS to be loaded
|
|
147
144
|
*/
|
|
148
145
|
overwriteUi5Lib(resolve, allowCSS) {
|
|
146
|
+
const that = this;
|
|
149
147
|
sap.ui.require(
|
|
150
148
|
['sap/ui/core/Lib'],
|
|
151
149
|
function (Lib) {
|
|
152
150
|
const fnInit = Lib.init;
|
|
151
|
+
const fnLoad = Lib._load;
|
|
152
|
+
Lib._load = function (mSettings) {
|
|
153
|
+
if (that.testEnvironmentOptions.shimManifests) {
|
|
154
|
+
const name = typeof mSettings === 'string' ? mSettings : mSettings.name;
|
|
155
|
+
that.shimManifestFile(name);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return fnLoad.call(this, mSettings);
|
|
159
|
+
};
|
|
153
160
|
Lib.init = function (mSettings) {
|
|
161
|
+
if (that.testEnvironmentOptions.shimManifests) {
|
|
162
|
+
that.shimManifestFile(mSettings.name);
|
|
163
|
+
}
|
|
164
|
+
|
|
154
165
|
mSettings.noLibraryCSS = !allowCSS;
|
|
155
166
|
return fnInit.call(this, mSettings);
|
|
156
167
|
};
|
|
@@ -162,6 +173,23 @@ class UI5DOMEnvironment extends JSDOMEnvironment {
|
|
|
162
173
|
);
|
|
163
174
|
}
|
|
164
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Register a shimmed manifest file for the given name.
|
|
178
|
+
* @param name The name of the library to shim
|
|
179
|
+
*/
|
|
180
|
+
shimManifestFile(name) {
|
|
181
|
+
window.jestUI5.mockUrl(
|
|
182
|
+
name.replaceAll('.', '/') + '/' + 'manifest.json',
|
|
183
|
+
JSON.stringify({
|
|
184
|
+
'sap.ui5': {
|
|
185
|
+
library: {
|
|
186
|
+
css: false
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
165
193
|
/**
|
|
166
194
|
* @returns {object} The VM Context for the current environment
|
|
167
195
|
*/
|
|
@@ -2,6 +2,52 @@ const path = require('path');
|
|
|
2
2
|
let pathMappingFn = null;
|
|
3
3
|
let ui5VersionCache = null;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Processes the resources of a UI5 project and updates the path mapping.
|
|
7
|
+
* @param {object} resources The resources to process.
|
|
8
|
+
* @param {object} ui5PathMapping The mapping object to update.
|
|
9
|
+
* @param {boolean} isRootProject Whether the project is the root project.
|
|
10
|
+
* @param {boolean} isReusableLibrary Whether the project is a reusable library.
|
|
11
|
+
* @param {string} namespace The namespace of the project.
|
|
12
|
+
* @param {string} sourceDirectory The source directory of the project.
|
|
13
|
+
*/
|
|
14
|
+
function processDependencyResources(
|
|
15
|
+
resources,
|
|
16
|
+
ui5PathMapping,
|
|
17
|
+
isRootProject,
|
|
18
|
+
isReusableLibrary,
|
|
19
|
+
namespace,
|
|
20
|
+
sourceDirectory
|
|
21
|
+
) {
|
|
22
|
+
for (const resource of resources) {
|
|
23
|
+
const resourcePath = resource.getPath().replace(/\/resources\/|\/test-resources\//g, '');
|
|
24
|
+
let itemPath;
|
|
25
|
+
if (sourceDirectory) {
|
|
26
|
+
itemPath = path.join(sourceDirectory, resourcePath);
|
|
27
|
+
} else {
|
|
28
|
+
itemPath = resource.getSourceMetadata?.().fsPath ?? resourcePath;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let targetPath = resourcePath.replace(/\\/g, '/');
|
|
32
|
+
if (targetPath.endsWith('.js')) {
|
|
33
|
+
targetPath = targetPath.replace('.js', '');
|
|
34
|
+
ui5PathMapping[targetPath + '.js'] = itemPath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (isRootProject || isReusableLibrary) {
|
|
38
|
+
if (targetPath.endsWith('.ts')) {
|
|
39
|
+
targetPath = targetPath.replace('.ts', '');
|
|
40
|
+
ui5PathMapping[targetPath + '.ts'] = itemPath;
|
|
41
|
+
}
|
|
42
|
+
if (namespace && !targetPath.startsWith(namespace)) {
|
|
43
|
+
targetPath = path.posix.join(namespace, targetPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ui5PathMapping[targetPath] = itemPath;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
5
51
|
/**
|
|
6
52
|
* Retrieves the file map from the UI5 project.
|
|
7
53
|
* @param {object} graph The graph object.
|
|
@@ -12,17 +58,22 @@ async function getFileMapFromUI5(graph, rootProject) {
|
|
|
12
58
|
let ui5PathMapping = {};
|
|
13
59
|
let ui5VersionInfo = {
|
|
14
60
|
name: 'SAPUI5 Distribution',
|
|
15
|
-
version: rootProject._config.framework.
|
|
61
|
+
version: rootProject._config.framework?.version ?? '1.0.0',
|
|
16
62
|
'buildTimestamp': '202412051614',
|
|
17
63
|
'scmRevision': '',
|
|
18
64
|
'libraries': []
|
|
19
65
|
};
|
|
20
66
|
|
|
21
67
|
await graph.traverseBreadthFirst(async ({ project: dependency }) => {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const namespace = dependency.getNamespace();
|
|
68
|
+
const dependencyType = dependency.getType();
|
|
69
|
+
const isReusableLibrary = dependencyType === 'library' && !dependency.isFrameworkProject();
|
|
25
70
|
const isRootProject = dependency.getName() === rootProject.getName();
|
|
71
|
+
const reader = dependency.getReader({ style: isReusableLibrary || isRootProject ? 'flat' : 'runtime' });
|
|
72
|
+
let sourcePath;
|
|
73
|
+
if (dependencyType !== 'module') {
|
|
74
|
+
sourcePath = dependency.getSourcePath();
|
|
75
|
+
}
|
|
76
|
+
const namespace = dependency.getNamespace();
|
|
26
77
|
ui5VersionInfo.libraries.push({
|
|
27
78
|
name: dependency.getName(),
|
|
28
79
|
version: dependency.getVersion(),
|
|
@@ -30,29 +81,7 @@ async function getFileMapFromUI5(graph, rootProject) {
|
|
|
30
81
|
scmRevision: ''
|
|
31
82
|
});
|
|
32
83
|
let resources = await reader.byGlob(`**/*.{ts,tsx,js,xml,properties,json}`);
|
|
33
|
-
|
|
34
|
-
for (const resource of resources) {
|
|
35
|
-
const resourcePath = resource.getPath().replace(/\/resources\/|\/test-resources\//g, '');
|
|
36
|
-
const itemPath = path.join(sourcePath, resourcePath);
|
|
37
|
-
|
|
38
|
-
let targetPath = resourcePath.replace(/\\/g, '/');
|
|
39
|
-
if (targetPath.endsWith('.js')) {
|
|
40
|
-
targetPath = targetPath.replace('.js', '');
|
|
41
|
-
ui5PathMapping[targetPath + '.js'] = itemPath;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isRootProject) {
|
|
45
|
-
if (targetPath.endsWith('.ts')) {
|
|
46
|
-
targetPath = targetPath.replace('.ts', '');
|
|
47
|
-
ui5PathMapping[targetPath + '.ts'] = itemPath;
|
|
48
|
-
}
|
|
49
|
-
if (!targetPath.startsWith(namespace)) {
|
|
50
|
-
targetPath = path.posix.join(namespace, targetPath);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
ui5PathMapping[targetPath] = itemPath;
|
|
55
|
-
}
|
|
84
|
+
processDependencyResources(resources, ui5PathMapping, isRootProject, isReusableLibrary, namespace, sourcePath);
|
|
56
85
|
});
|
|
57
86
|
return { ui5PathMapping, ui5VersionInfo };
|
|
58
87
|
}
|