Skip to content

Commit 6c00696

Browse files
committed
[INTERNAL] Fix tests
1 parent 04a1f31 commit 6c00696

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

lib/index.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const ImportCollectorPlugin = require("./plugin/import-collector");
1515
const VariableCollectorPlugin = require("./plugin/variable-collector");
1616
const UrlCollector = require("./plugin/url-collector");
1717

18-
const LESS_OPENUI5_VERSION = require("../package.json").version;
19-
2018
// Workaround for a performance issue in the "css" parser module when used in combination
2119
// with the "colors" module that enhances the String prototype.
2220
// See: https://github.com/reworkcss/css/issues/88
@@ -72,6 +70,15 @@ const Builder = function(options) {
7270
this.fileUtils = fileUtilsFactory(this.customFs);
7371
};
7472

73+
let engineInfo;
74+
Builder.getEngineInfo = function() {
75+
if (!engineInfo) {
76+
const {name, version} = require("../package.json");
77+
engineInfo = {name, version};
78+
}
79+
return engineInfo;
80+
};
81+
7582
Builder.prototype.getThemeCache = function(rootPath) {
7683
return this.themeCacheMapping[rootPath];
7784
};
@@ -375,18 +382,19 @@ Builder.prototype.build = function(options) {
375382
// TODO: How to get theme name? .theming "sId"? parse from file path? new parameter?
376383
const themeId = "<theme-name>";
377384

385+
const {version, name} = Builder.getEngineInfo();
378386
const metadataJson = JSON.stringify({
379-
"Path": `UI5.${libraryNameSlashed}.${themeId}.library`,
380-
"PathPattern": "/%frameworkId%/%libId%/themes/%themeId%/%fileId%.css",
381-
"Extends": ["base"], // TODO: Read from .theming?
382-
"Scopes": scopes,
383-
"Engine": {
384-
"Version": LESS_OPENUI5_VERSION,
385-
"Name": "less-openui5"
387+
Path: `UI5.${libraryNameSlashed}.${themeId}.library`,
388+
PathPattern: "/%frameworkId%/%libId%/themes/%themeId%/%fileId%.css",
389+
Extends: ["base"], // TODO: Read from .theming?
390+
Scopes: scopes,
391+
Engine: {
392+
Version: version,
393+
Name: name
386394
},
387-
"Version": {
388-
"Build": "<TODO>", // TOOD: add new property options.library.version
389-
"Source": "<TODO>" // TOOD: add new property options.library.version
395+
Version: {
396+
Build: "<TODO>", // TOOD: add new property options.library.version
397+
Source: "<TODO>" // TOOD: add new property options.library.version
390398
}
391399
});
392400

@@ -656,3 +664,11 @@ Builder.prototype.build = function(options) {
656664
};
657665

658666
module.exports.Builder = Builder;
667+
668+
// Set engine info during unit test execution to have a static version that can be used in the expected build results
669+
if (process.env.NODE_ENV === "test") {
670+
engineInfo = {
671+
name: "less-openui5",
672+
version: "0.0.0-test"
673+
};
674+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"scripts": {
2525
"lint": "eslint ./",
26-
"unit": "mocha test/*.js",
27-
"unit-debug": "mocha --inspect --inspect-brk test/*.js",
26+
"unit": "NODE_ENV=test mocha test/*.js",
27+
"unit-debug": "NODE_ENV=test mocha --inspect --inspect-brk test/*.js",
2828
"coverage": "nyc npm run unit",
2929
"test": "npm run lint && npm run coverage && npm run depcheck",
3030
"preversion": "npm test",

test/expected/inlineCssVariables/lib3/my/other/ui/lib/themes/base/library-RTL.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
:root {
33
--sapUiTheme-my-other-ui-lib: true;
4-
--sapThemeMetaData-UI5-my-other-ui-lib: {"Path":"UI5.my/other/ui/lib.<theme-name>.library","PathPattern":"/%frameworkId%/%libId%/themes/%themeId%/%fileId%.css","Extends":["base"],"Scopes":[],"Engine":{"Version":"0.11.1","Name":"less-openui5"},"Version":{"Build":"<TODO>","Source":"<TODO>"}};
4+
--sapThemeMetaData-UI5-my-other-ui-lib: {"Path":"UI5.my/other/ui/lib.<theme-name>.library","PathPattern":"/%frameworkId%/%libId%/themes/%themeId%/%fileId%.css","Extends":["base"],"Scopes":[],"Engine":{"Version":"0.0.0-test","Name":"less-openui5"},"Version":{"Build":"<TODO>","Source":"<TODO>"}};
55
}
66
:root {
77
--_my_other_ui_lib_MyControl_color1: var(--color1);

test/expected/inlineCssVariables/lib3/my/other/ui/lib/themes/base/library.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
:root {
33
--sapUiTheme-my-other-ui-lib: true;
4-
--sapThemeMetaData-UI5-my-other-ui-lib: {"Path":"UI5.my/other/ui/lib.<theme-name>.library","PathPattern":"/%frameworkId%/%libId%/themes/%themeId%/%fileId%.css","Extends":["base"],"Scopes":[],"Engine":{"Version":"0.11.1","Name":"less-openui5"},"Version":{"Build":"<TODO>","Source":"<TODO>"}};
4+
--sapThemeMetaData-UI5-my-other-ui-lib: {"Path":"UI5.my/other/ui/lib.<theme-name>.library","PathPattern":"/%frameworkId%/%libId%/themes/%themeId%/%fileId%.css","Extends":["base"],"Scopes":[],"Engine":{"Version":"0.0.0-test","Name":"less-openui5"},"Version":{"Build":"<TODO>","Source":"<TODO>"}};
55
}
66
:root {
77
--_my_other_ui_lib_MyControl_color1: var(--color1);

test/expected/libraries/lib1/my/ui/lib/themes/foo/css_variables.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:root {
22
--color1: #ffffff;
33
--url1: url('../base/111');
4+
--url1__asResolvedUrl: "ui5://my/ui/lib/themes/base/111";
45
}
56
.fooContrast {
67
--color1: #000000;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@color1: #ffffff;
22
@url1: url('../base/111');
3+
@url1__asResolvedUrl: "ui5://my/ui/lib/themes/base/111";
34

45
:root {
56
--color1: @color1;
67
--url1: @url1;
8+
--url1__asResolvedUrl: @url1__asResolvedUrl;
79
}

0 commit comments

Comments
 (0)