From 65a3b84383b5f4120d925c1e3e5536da49bb76bb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Fri, 7 Sep 2018 12:21:24 +0000 Subject: [PATCH 1/2] Update eslint requirement from ^1.10.3 to ^5.5.0 Updates the requirements on [eslint](https://github.com/eslint/eslint) to permit the latest version. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/commits/v5.5.0) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e57b2dd0..4a490bc3 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "devDependencies": { "clean-css": "^3.4.23", - "eslint": "^1.10.3", + "eslint": "^5.5.0", "graceful-fs": "^4.1.11", "mocha": "^3.2.0" } From cc64ce1e337758ff7792940b5daad71be11b5b75 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Fri, 7 Sep 2018 09:27:18 +0200 Subject: [PATCH 2/2] Use eslint config from ui5-tooling, adopt files according to config --- .eslintrc | 45 - .eslintrc.js | 48 + lib/diff.js | 47 +- lib/fileUtils.js | 12 +- lib/index.js | 176 +- lib/less/fileLoader.js | 27 +- lib/less/importsPush.js | 34 +- lib/less/parser.js | 13 +- lib/plugin/import-collector.js | 14 +- lib/plugin/rtl.js | 479 +++--- lib/plugin/variable-collector.js | 124 +- lib/scope.js | 48 +- package.json | 1 + test/common/helper.js | 22 +- test/test-custom-fs.js | 114 +- test/test-perf-workaround.js | 103 +- test/test.js | 2565 ++++++++++++++---------------- 17 files changed, 1803 insertions(+), 2069 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index a0bd1d9d..00000000 --- a/.eslintrc +++ /dev/null @@ -1,45 +0,0 @@ -{ - "env": { - "node": true - }, - "rules": { - "block-scoped-var": 1, - "brace-style": [2, "1tbs", { "allowSingleLine": true }], - "consistent-this": [2 , "that"], - "strict": [ 2, "global"], - "no-div-regex": 2, - "no-floating-decimal": 2, - "no-self-compare": 2, - "no-mixed-spaces-and-tabs": [2, true], - "no-nested-ternary": 2, - "no-unused-vars": [2, {"vars":"all", "args":"none"}], - "radix": 2, - "space-after-keywords": [2, "always"], - "space-unary-ops": 2, - "wrap-iife": [2, "any"], - - "camelcase": 1, - "consistent-return": 1, - "max-nested-callbacks": [1, 3], - "new-cap": 1, - "no-extra-boolean-cast": 1, - "no-lonely-if": 1, - "no-new": 1, - "no-new-wrappers": 1, - "no-redeclare": 1, - "no-unused-expressions": 1, - "no-use-before-define": [1, "nofunc"], - "no-warning-comments": 1, - "valid-jsdoc": [1, { - "requireReturn": false - }], - "default-case": 1, - - "dot-notation": 0, - "eol-last": 0, - "eqeqeq": 0, - "no-trailing-spaces": 0, - "no-underscore-dangle": 0, - "quotes": 0 - } -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..480a895c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,48 @@ +module.exports = { + "env": { + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 8 + }, + "extends": ["eslint:recommended", "google"], + "rules": { + "indent": [ + "error", + "tab" + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ], + "no-negated-condition": "off", + "require-jsdoc": "off", + "no-mixed-requires": "off", + "max-len": ["warn", 120], + "no-implicit-coercion": [ + 2, + { "allow": ["!!"] } + ], + "comma-dangle": "off", + "no-tabs": "off", + 'valid-jsdoc': [ + 2, + { + requireParamDescription: false, + requireReturnDescription: false, + requireReturn: false, + prefer: {return: 'returns'}, + } + ], + }, + "root": true +}; diff --git a/lib/diff.js b/lib/diff.js index 36c1947e..6d377cf3 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -12,21 +12,20 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; // Regular expression to match type of property in order to check whether // it possibly contains color values. -var rProperties = /(color|background|border|text|outline)(?!\-(width|radius|offset|style|align|overflow|transform))(\-(color|shadow|image))?/; +let rProperties = /(color|background|border|text|outline)(?!-(width|radius|offset|style|align|overflow|transform))(-(color|shadow|image))?/; function selectorEquals(s1, s2) { - // Make sure there is the same number of select parts if (s1.length !== s2.length) { return false; } // Check if all the parts are the same strings - for (var i = 0; i < s1.length; i++) { + for (let i = 0; i < s1.length; i++) { if (s1[i] !== s2[i]) { return false; } @@ -55,13 +54,13 @@ function Diffing(oBase, oCompare) { } Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) { - var aDiffRules = []; - var iBaseNode, iCompareNode; + let aDiffRules = []; + let iBaseNode; let iCompareNode; for (iBaseNode = 0, iCompareNode = 0; iBaseNode < oBaseRules.length; iBaseNode++, iCompareNode++) { - var oBaseNode = oBaseRules[iBaseNode]; - var oCompareNode = oCompareRules[iCompareNode]; - var oDiffNode = null; + let oBaseNode = oBaseRules[iBaseNode]; + let oCompareNode = oCompareRules[iCompareNode]; + let oDiffNode = null; // Add all different compare nodes to stack and check for next one while (oBaseNode.type !== oCompareNode.type) { @@ -71,8 +70,8 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) { } if (oBaseNode.type === "comment") { - var sBaseComment = oBaseNode.comment; - var sCompareComment = oCompareNode.comment; + let sBaseComment = oBaseNode.comment; + let sCompareComment = oCompareNode.comment; if (sBaseComment !== sCompareComment) { oDiffNode = oCompareNode; @@ -80,7 +79,6 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) { } if (oBaseNode.type === "rule") { - // Add all rules with different selector to stack and check for next one while (!selectorEquals(oBaseNode.selectors, oCompareNode.selectors)) { this.oStack.stylesheet.rules.push(oCompareNode); @@ -88,24 +86,20 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) { oCompareNode = oCompareRules[iCompareNode]; } - var aBaseDeclarations = oBaseNode.declarations; - var aCompareDeclarations = oCompareNode.declarations; - for (var j = 0; j < aBaseDeclarations.length; j++) { - var oBaseDeclaration = aBaseDeclarations[j]; - var oCompareDeclaration = aCompareDeclarations[j]; + let aBaseDeclarations = oBaseNode.declarations; + let aCompareDeclarations = oCompareNode.declarations; + for (let j = 0; j < aBaseDeclarations.length; j++) { + let oBaseDeclaration = aBaseDeclarations[j]; + let oCompareDeclaration = aCompareDeclarations[j]; if (oBaseDeclaration.type === "declaration") { - // TODO: Also check for different node and add to stack??? if (oBaseDeclaration.type === oCompareDeclaration.type) { - if (oBaseDeclaration.property === oCompareDeclaration.property) { - // Always add color properties to diff to prevent unexpected CSS overrides // due to selectors with more importance if (oBaseDeclaration.value !== oCompareDeclaration.value || oCompareDeclaration.property.match(rProperties)) { - // Add compared rule to diff if (!oDiffNode) { oDiffNode = oCompareNode; @@ -113,27 +107,22 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) { } oDiffNode.declarations.push(oCompareDeclaration); } - } } } } - } else if (oBaseNode.type === "media") { - - var aMediaDiffRules = this.diffRules(oBaseNode.rules, oCompareNode.rules); + let aMediaDiffRules = this.diffRules(oBaseNode.rules, oCompareNode.rules); if (aMediaDiffRules.length > 0) { oDiffNode = oCompareNode; oDiffNode.rules = aMediaDiffRules; } - } if (oDiffNode) { aDiffRules.push(oDiffNode); } - } // Add all leftover compare nodes to stack @@ -145,8 +134,8 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) { }; Diffing.prototype.run = function() { - var oBaseRules = this.oBase.stylesheet.rules; - var oCompareRules = this.oCompare.stylesheet.rules; + let oBaseRules = this.oBase.stylesheet.rules; + let oCompareRules = this.oCompare.stylesheet.rules; this.oDiff.stylesheet.rules = this.diffRules(oBaseRules, oCompareRules); diff --git a/lib/fileUtils.js b/lib/fileUtils.js index 808df5b9..39648b8d 100644 --- a/lib/fileUtils.js +++ b/lib/fileUtils.js @@ -12,20 +12,20 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; -var path = require('path'); +let path = require("path"); module.exports = function(fs) { if (!fs) { - fs = require('fs'); + fs = require("fs"); } function statFile(filePath) { return new Promise(function(resolve, reject) { fs.stat(filePath, function(err, stat) { // No rejection here as it is ok if the file was not found - resolve(stat ? { path: filePath, stat: stat } : null); + resolve(stat ? {path: filePath, stat: stat} : null); }); }); } @@ -41,7 +41,7 @@ module.exports = function(fs) { return path.join(rootPath, filePath); }) ).then(function(results) { - for (var i = 0; i < results.length; i++) { + for (let i = 0; i < results.length; i++) { if (results[i] !== null) { return results[i]; } @@ -62,7 +62,7 @@ module.exports = function(fs) { } return new Promise(function(resolve, reject) { fs.readFile(fileInfo.path, { - encoding: 'utf8' + encoding: "utf8" }, function(fileErr, content) { if (fileErr) { reject(fileErr); diff --git a/lib/index.js b/lib/index.js index 0d4c3acb..1d24ed59 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,23 +12,23 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; -var path = require('path'); -var assign = require('object-assign'); -var clone = require('clone'); -var css = require('css'); +let path = require("path"); +let assign = require("object-assign"); +let clone = require("clone"); +let css = require("css"); -var createParser = require('./less/parser'); -var diff = require('./diff'); -var scope = require('./scope'); +let createParser = require("./less/parser"); +let diff = require("./diff"); +let scope = require("./scope"); -var fileUtilsFactory = require('./fileUtils'); +let fileUtilsFactory = require("./fileUtils"); // Plugins -var RTLPlugin = require('./plugin/rtl'); -var ImportCollectorPlugin = require('./plugin/import-collector'); -var VariableCollectorPlugin = require('./plugin/variable-collector'); +let RTLPlugin = require("./plugin/rtl"); +let ImportCollectorPlugin = require("./plugin/import-collector"); +let VariableCollectorPlugin = require("./plugin/variable-collector"); // Workaround for a performance issue in the "css" parser module when used in combination // with the "colors" module that enhances the String prototype. @@ -38,11 +38,11 @@ var VariableCollectorPlugin = require('./plugin/variable-collector'); // that restores them afterwards. // To be used before/after calling "css.parse" function cleanupStringPrototype() { - var customGetters = {}, customProps = {}, s = "", key; + let customGetters = {}; let customProps = {}; let s = ""; let key; for (key in s) { if (!s.hasOwnProperty(key)) { - var getter = String.prototype.__lookupGetter__(key); + let getter = String.prototype.__lookupGetter__(key); if (typeof getter === "function") { customGetters[key] = getter; } else { @@ -64,10 +64,11 @@ function cleanupStringPrototype() { } for (key in customProps) { if (customProps.hasOwnProperty(key)) { + // eslint-disable-next-line no-extend-native String.prototype[key] = customProps[key]; } } - } + }; } function dotThemingFileToPath(s) { @@ -78,7 +79,7 @@ function dotThemingFileToPath(s) { return s; } -var Builder = function(options) { +let Builder = function(options) { this.themeCacheMapping = {}; this.customFs = options ? options.fs : null; this.fileUtils = fileUtilsFactory(this.customFs); @@ -94,11 +95,11 @@ Builder.prototype.setThemeCache = function(rootPath, cache) { Builder.prototype.clearCache = function() { this.themeCacheMapping = {}; -} +}; Builder.prototype.cacheTheme = function(result) { - var that = this; - var rootpath; + let that = this; + let rootpath; // Theme can only be cached if list of imports is available if (result.imports.length === 0) { @@ -116,15 +117,14 @@ Builder.prototype.cacheTheme = function(result) { return result; }); - }; Builder.prototype.build = function(options) { - var that = this; + let that = this; // Stores mapping between "virtual" paths (used within LESS) and real filesystem paths. // Only relevant when using the "rootPaths" option. - var mFileMappings = {}; + let mFileMappings = {}; // Assign default options options = assign({ @@ -144,15 +144,14 @@ Builder.prototype.build = function(options) { } function fileHandler(file, currentFileInfo, handleDataAndCallCallback, callback) { - - var pathname = path.posix.join(currentFileInfo.currentDirectory, file); + let pathname = path.posix.join(currentFileInfo.currentDirectory, file); that.fileUtils.readFile(pathname, options.rootPaths).then(function(result) { if (!result) { + // eslint-disable-next-line no-console console.log("File not found"); - callback({ type: 'File', message: "'" + file + "' wasn't found" }) + callback({type: "File", message: "'" + file + "' wasn't found"}); } else { - try { // Save import mapping to calculate full import paths later on mFileMappings[currentFileInfo.rootFilename] = mFileMappings[currentFileInfo.rootFilename] || {}; @@ -160,20 +159,21 @@ Builder.prototype.build = function(options) { handleDataAndCallCallback(pathname, result.content); } catch (e) { + // eslint-disable-next-line no-console console.log(e); callback(e); } - } }, function(err) { + // eslint-disable-next-line no-console console.log(err); callback(err); }); } function compile(config) { - var parserOptions = clone(options.parser); - var rootpath; + let parserOptions = clone(options.parser); + let rootpath; if (config.path) { // Keep rootpath for later usage in the ImportCollectorPlugin @@ -182,18 +182,17 @@ Builder.prototype.build = function(options) { } // Keep filename for later usage (see ImportCollectorPlugin) as less modifies the parserOptions.filename - var filename = parserOptions.filename; + let filename = parserOptions.filename; // Only use custom file handler when "rootPaths" or custom "fs" are used - var fnFileHandler; + let fnFileHandler; if ((options.rootPaths && options.rootPaths.length > 0) || that.customFs) { fnFileHandler = fileHandler; } return new Promise(function(resolve, reject) { - var parser = createParser(parserOptions, fnFileHandler); + let parser = createParser(parserOptions, fnFileHandler); parser.parse(config.content, function(err, tree) { - if (err) { reject(err); } else { @@ -201,20 +200,19 @@ Builder.prototype.build = function(options) { } }); }).then(function(tree) { - - var result = {}; + let result = {}; result.tree = tree; // plugins to collect imported files and variable values - var oImportCollector = new ImportCollectorPlugin({ + let oImportCollector = new ImportCollectorPlugin({ importMappings: mFileMappings[filename] }); - var oVariableCollector = new VariableCollectorPlugin(options.compiler); + let oVariableCollector = new VariableCollectorPlugin(options.compiler); // render to css result.css = tree.toCSS(assign(options.compiler, { - plugins: [ oImportCollector, oVariableCollector ] + plugins: [oImportCollector, oVariableCollector] })); // retrieve imported files @@ -229,7 +227,7 @@ Builder.prototype.build = function(options) { // also compile rtl-version if requested if (options.rtl) { result.cssRtl = tree.toCSS(assign(options.compiler, { - plugins: [ new RTLPlugin() ] + plugins: [new RTLPlugin()] })); } @@ -238,24 +236,23 @@ Builder.prototype.build = function(options) { } return result; - }); } function addInlineParameters(result) { return new Promise(function(resolve, reject) { if (typeof options.library === "object" && typeof options.library.name === "string") { - var parameters = JSON.stringify(result.variables); + let parameters = JSON.stringify(result.variables); // escape all chars that could cause problems with css parsers using URI-Encoding (% + HEX-Code) - var escapedChars = "%{}()'\"\\"; - for (var i = 0; i < escapedChars.length; i++) { - var char = escapedChars.charAt(i); - var hex = char.charCodeAt(0).toString(16).toUpperCase(); + let escapedChars = "%{}()'\"\\"; + for (let i = 0; i < escapedChars.length; i++) { + let char = escapedChars.charAt(i); + let hex = char.charCodeAt(0).toString(16).toUpperCase(); parameters = parameters.replace(new RegExp("\\" + char, "g"), "%" + hex); } - var parameterStyleRule = + let parameterStyleRule = "\n/* Inline theming parameters */\n#sap-ui-theme-" + options.library.name.replace(/\./g, "\\.") + " { background-image: url('data:text/plain;utf-8," + parameters + "'); }\n"; @@ -271,12 +268,12 @@ Builder.prototype.build = function(options) { } function getScopeVariables(options) { - var sScopeName = options.scopeName; - var oVariablesBase = options.baseVariables; - var oVariablesEmbedded = options.embeddedVariables; - var oVariablesDiff = {}; + let sScopeName = options.scopeName; + let oVariablesBase = options.baseVariables; + let oVariablesEmbedded = options.embeddedVariables; + let oVariablesDiff = {}; - for (var sKey in oVariablesEmbedded) { + for (let sKey in oVariablesEmbedded) { if (sKey in oVariablesBase) { if (oVariablesBase[sKey] != oVariablesEmbedded[sKey]) { oVariablesDiff[sKey] = oVariablesEmbedded[sKey]; @@ -285,7 +282,7 @@ Builder.prototype.build = function(options) { } // Merge variables - var oVariables = {}; + let oVariables = {}; oVariables["default"] = oVariablesBase; oVariables["scopes"] = {}; oVariables["scopes"][sScopeName] = oVariablesDiff; @@ -304,25 +301,24 @@ Builder.prototype.build = function(options) { embedded: results[1] }; }).then(function(results) { - var sScopeName = scopeOptions.selector; + let sScopeName = scopeOptions.selector; function applyScope(embeddedCompareCss, embeddedCss, bRtl) { - - var restoreStringPrototype = cleanupStringPrototype(); + let restoreStringPrototype = cleanupStringPrototype(); // Create diff object between embeddedCompare and embedded - var oBase = css.parse(embeddedCompareCss); - var oEmbedded = css.parse(embeddedCss); + let oBase = css.parse(embeddedCompareCss); + let oEmbedded = css.parse(embeddedCss); restoreStringPrototype(); - var oDiff = diff(oBase, oEmbedded); + let oDiff = diff(oBase, oEmbedded); // Create scope - var sScopeSelector = '.' + sScopeName; - var oScope = scope(oDiff.diff, sScopeSelector); + let sScopeSelector = "." + sScopeName; + let oScope = scope(oDiff.diff, sScopeSelector); - var oCssScopeRoot; + let oCssScopeRoot; if (oDiff.stack) { oCssScopeRoot = scope.scopeCssRoot(oDiff.stack.stylesheet.rules, sScopeName); @@ -334,7 +330,7 @@ Builder.prototype.build = function(options) { // Append scope + stack to embeddedCompareFile (actually target file, which is currently always the same i.e. "library.css") // The stack gets appended to the embeddedFile only - var sAppend = css.stringify(oScope, { + let sAppend = css.stringify(oScope, { compress: options.compiler && options.compiler.compress === true }); @@ -345,7 +341,6 @@ Builder.prototype.build = function(options) { } return sAppend + "\n"; - } results.embeddedCompare.css += applyScope(results.embeddedCompare.css, results.embedded.css); @@ -365,15 +360,15 @@ Builder.prototype.build = function(options) { scopeName: sScopeName }); - var concatImports = function(aImportsBase, aImportsEmbedded) { - var aConcats = aImportsBase.concat(aImportsEmbedded); + let concatImports = function(aImportsBase, aImportsEmbedded) { + let aConcats = aImportsBase.concat(aImportsEmbedded); return aConcats.filter(function(sImport, sIndex) { return aConcats.indexOf(sImport) == sIndex; - }) + }); }; - if (scopeOptions.baseFilePath !== options.lessInputPath) { + if (scopeOptions.baseFilePath !== options.lessInputPath) { results.embeddedCompare.imports = concatImports(results.embedded.imports, results.embeddedCompare.imports); } else { results.embeddedCompare.imports = concatImports(results.embeddedCompare.imports, results.embedded.imports); @@ -381,16 +376,14 @@ Builder.prototype.build = function(options) { // 6. Resolve promise with complete result object (css, cssRtl, variables, imports) return results.embeddedCompare; - }); } function readDotTheming(dotThemingInputPath) { return that.fileUtils.readFile(dotThemingInputPath, options.rootPaths).then(function(result) { - - var dotTheming; - var dotThemingFilePath; + let dotTheming; + let dotThemingFilePath; if (result) { dotTheming = JSON.parse(result.content); @@ -398,29 +391,27 @@ Builder.prototype.build = function(options) { } if (dotTheming && dotTheming.mCssScopes) { - // Currently only the "library" target is supported - var cssScope = dotTheming.mCssScopes["library"]; + let cssScope = dotTheming.mCssScopes["library"]; if (cssScope) { + let aScopes = cssScope.aScopes; + let oScopeConfig = aScopes[0]; // Currenlty only one scope is supported - var aScopes = cssScope.aScopes; - var oScopeConfig = aScopes[0]; // Currenlty only one scope is supported - - var sBaseFile = dotThemingFileToPath(cssScope.sBaseFile || cssScopeTarget); - var sEmbeddedCompareFile = dotThemingFileToPath(oScopeConfig.sEmbeddedCompareFile); - var sEmbeddedFile = dotThemingFileToPath(oScopeConfig.sEmbeddedFile); + let sBaseFile = dotThemingFileToPath(cssScope.sBaseFile); + let sEmbeddedCompareFile = dotThemingFileToPath(oScopeConfig.sEmbeddedCompareFile); + let sEmbeddedFile = dotThemingFileToPath(oScopeConfig.sEmbeddedFile); // Currently, only support the use case when "sBaseFile" equals "sEmbeddedCompareFile" if (sBaseFile !== sEmbeddedCompareFile) { throw new Error("Unsupported content in \"" + dotThemingInputPath + "\": " + - "\"sBaseFile\" (\"" + (cssScope.sBaseFile || cssScopeTarget) + "\") must be identical with " + + "\"sBaseFile\" (\"" + cssScope.sBaseFile + "\") must be identical with " + "\"sEmbeddedCompareFile\" (\"" + oScopeConfig.sEmbeddedCompareFile + "\")"); } - var baseFilePath = path.posix.join(themeDir, sBaseFile) + '.source.less'; - var embeddedCompareFilePath = path.posix.join(themeDir, sEmbeddedCompareFile) + '.source.less'; - var embeddedFilePath = path.posix.join(themeDir, sEmbeddedFile) + '.source.less'; + let baseFilePath = path.posix.join(themeDir, sBaseFile) + ".source.less"; + let embeddedCompareFilePath = path.posix.join(themeDir, sEmbeddedCompareFile) + ".source.less"; + let embeddedFilePath = path.posix.join(themeDir, sEmbeddedFile) + ".source.less"; // 1. Compile base + embedded files (both default + RTL variants) return compileWithScope({ @@ -449,39 +440,38 @@ Builder.prototype.build = function(options) { } if (options.lessInput) { - return compile({ content: options.lessInput }).then(addInlineParameters).then(that.cacheTheme.bind(that)); - } else { + // TODO: refactor + // eslint-disable-next-line no-var var themeDir = path.posix.dirname(options.lessInputPath); // Always use the sap/ui/core library to lookup .theming files - var coreThemeDir; + let coreThemeDir; if (options.library && typeof options.library.name === "string") { - var libraryNamespace = options.library.name.replace(/\./g, "/"); - coreThemeDir = themeDir.replace(libraryNamespace, "sap/ui/core"); + let libraryNamespace = options.library.name.replace(/\./g, "/"); + coreThemeDir = themeDir.replace(libraryNamespace, "sap/ui/core"); } else { coreThemeDir = themeDir.replace(/^.*\/themes\//, "/sap/ui/core/themes/"); } - var dotThemingInputPath = path.posix.join(coreThemeDir, '.theming'); + let dotThemingInputPath = path.posix.join(coreThemeDir, ".theming"); return that.fileUtils.findFile(options.lessInputPath, options.rootPaths).then(function(fileInfo) { - if (!fileInfo) { throw new Error("`lessInputPath` " + options.lessInputPath + " could not be found."); } // check theme has been already cached - var themeCache; + let themeCache; if (fileInfo.path) { themeCache = that.getThemeCache(fileInfo.path); } - var scopeOptions = options.scope; + let scopeOptions = options.scope; // Compile theme if not cached or RTL is requested and missing in cache if (!themeCache || (options.rtl && !themeCache.result.cssRtl)) { @@ -491,7 +481,7 @@ Builder.prototype.build = function(options) { return readDotTheming(dotThemingInputPath).then(addInlineParameters).then(that.cacheTheme.bind(that)); } else { return that.fileUtils.statFiles(themeCache.result.imports).then(function(newStats) { - for (var i = 0; i < newStats.length; i++) { + for (let i = 0; i < newStats.length; i++) { // check if .theming and less files have changed since last less compilation if (!newStats[i] || newStats[i].stat.mtime.getTime() !== themeCache.stats[i].stat.mtime.getTime()) { if (scopeOptions.selector && scopeOptions.embeddedFilePath && scopeOptions.embeddedCompareFilePath && scopeOptions.baseFilePath) { diff --git a/lib/less/fileLoader.js b/lib/less/fileLoader.js index bf64ae95..481df5ab 100644 --- a/lib/less/fileLoader.js +++ b/lib/less/fileLoader.js @@ -1,4 +1,4 @@ -/*! +/* ! * LESS - Leaner CSS v1.6.3 * http://lesscss.org * @@ -12,26 +12,27 @@ * */ -'use strict'; +"use strict"; module.exports = function createFileLoader(fileHandler) { return function fileLoader(file, currentFileInfo, callback, env) { - /* BEGIN MODIFICATION */ // Removed unused variables "dirname, data" - var pathname, - newFileInfo = { - relativeUrls: env.relativeUrls, - entryPath: currentFileInfo.entryPath, - rootpath: currentFileInfo.rootpath, - rootFilename: currentFileInfo.rootFilename - }; + let pathname; + + + let newFileInfo = { + relativeUrls: env.relativeUrls, + entryPath: currentFileInfo.entryPath, + rootpath: currentFileInfo.rootpath, + rootFilename: currentFileInfo.rootFilename + }; /* END MODIFICATION */ function handleDataAndCallCallback(data) { - var j = file.lastIndexOf('/'); + let j = file.lastIndexOf("/"); // Pass on an updated rootpath if path of imported file is relative and file // is in a (sub|sup) directory @@ -42,9 +43,10 @@ module.exports = function createFileLoader(fileHandler) { // - If path of imported file is '../mixins.less' and rootpath is 'less/', // then rootpath should become 'less/../' if (newFileInfo.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) { - var relativeSubDirectory = file.slice(0, j+1); + let relativeSubDirectory = file.slice(0, j+1); newFileInfo.rootpath = newFileInfo.rootpath + relativeSubDirectory; // append (sub|sup) directory path of imported file } + // eslint-disable-next-line no-useless-escape newFileInfo.currentDirectory = pathname.replace(/[^\\\/]*$/, ""); newFileInfo.filename = pathname; @@ -62,6 +64,5 @@ module.exports = function createFileLoader(fileHandler) { // The remainder of this function has been completely removed /* END MODIFICATION */ - }; }; diff --git a/lib/less/importsPush.js b/lib/less/importsPush.js index 7a68cc5e..e05dac67 100644 --- a/lib/less/importsPush.js +++ b/lib/less/importsPush.js @@ -1,4 +1,4 @@ -/*! +/* ! * LESS - Leaner CSS v1.6.3 * http://lesscss.org * @@ -12,30 +12,32 @@ * */ -/* eslint-disable consistent-this, new-cap */ -'use strict'; +/* eslint-disable consistent-this, new-cap, no-invalid-this */ +"use strict"; -var less = require('less'); -var tree = less.tree; +let less = require("less"); +let tree = less.tree; module.exports = function createImportsPushFunction(env, fileLoader, parserFactory) { return function importsPush(path, currentFileInfo, importOptions, callback) { - var parserImports = this; + let parserImports = this; this.queue.push(path); - var fileParsedFunc = function (e, root, fullPath) { + let fileParsedFunc = function(e, root, fullPath) { parserImports.queue.splice(parserImports.queue.indexOf(path), 1); // Remove the path from the queue /* BEGIN MODIFICATION */ // Replaced "rootFilename" with "env.filename" - var importedPreviously = fullPath in parserImports.files || fullPath === env.filename; + let importedPreviously = fullPath in parserImports.files || fullPath === env.filename; /* END MODIFICATION */ - parserImports.files[fullPath] = root; // Store the root + parserImports.files[fullPath] = root; // Store the root - if (e && !parserImports.error) { parserImports.error = e; } + if (e && !parserImports.error) { + parserImports.error = e; + } callback(e, root, importedPreviously, fullPath); }; @@ -43,17 +45,17 @@ module.exports = function createImportsPushFunction(env, fileLoader, parserFacto if (less.Parser.importer) { less.Parser.importer(path, currentFileInfo, fileParsedFunc, env); } else { - /* BEGIN MODIFICATION */ // Call custom fileLoader instead of "less.Parser.fileLoader" fileLoader(path, currentFileInfo, function(e, contents, fullPath, newFileInfo) { - /* END MODIFICATION */ - if (e) {fileParsedFunc(e); return;} + if (e) { + fileParsedFunc(e); return; + } - var newEnv = new tree.parseEnv(env); + let newEnv = new tree.parseEnv(env); newEnv.currentFileInfo = newFileInfo; newEnv.processImports = false; @@ -66,12 +68,10 @@ module.exports = function createImportsPushFunction(env, fileLoader, parserFacto if (importOptions.inline) { fileParsedFunc(null, contents, fullPath); } else { - /* BEGIN MODIFICATION */ // Create custom parser when resolving imports - parserFactory(newEnv, fileLoader).parse(contents, function (e, root) { - + parserFactory(newEnv, fileLoader).parse(contents, function(e, root) { /* END MODIFICATION */ fileParsedFunc(e, root, fullPath); diff --git a/lib/less/parser.js b/lib/less/parser.js index 415e3a60..465f5e04 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -13,11 +13,11 @@ // language governing permissions and limitations under the License. /* eslint-disable new-cap */ -'use strict'; +"use strict"; -var less = require('less'); -var createFileLoader = require('./fileLoader'); -var createImportsPushFunction = require('./importsPush'); +let less = require("less"); +let createFileLoader = require("./fileLoader"); +let createImportsPushFunction = require("./importsPush"); function parserFactory(env, fileLoader) { // Make sure that provided "env" is an instance @@ -25,7 +25,7 @@ function parserFactory(env, fileLoader) { env = new less.tree.parseEnv(env); } - var parser = new less.Parser(env); + let parser = new less.Parser(env); if (fileLoader) { patchParserImportsPush(parser, env, fileLoader); @@ -41,9 +41,8 @@ function patchParserImportsPush(parser, env, fileLoader) { } module.exports = function createParser(env, fileHandler) { - // Create fileLoader function if a fileHandler is provided - var fileLoader; + let fileLoader; if (fileHandler) { fileLoader = createFileLoader(fileHandler); } diff --git a/lib/plugin/import-collector.js b/lib/plugin/import-collector.js index 524b90d9..aa0a1453 100644 --- a/lib/plugin/import-collector.js +++ b/lib/plugin/import-collector.js @@ -12,14 +12,14 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; -var less = require('less'); +let less = require("less"); -var ImportCollector = module.exports = function(options) { - /*eslint-disable new-cap */ +let ImportCollector = module.exports = function(options) { + /* eslint-disable new-cap */ this.oVisitor = new less.tree.visitor(this); - /*eslint-enable new-cap */ + /* eslint-enable new-cap */ this.aImports = []; @@ -28,12 +28,12 @@ var ImportCollector = module.exports = function(options) { ImportCollector.prototype = { isPreEvalVisitor: true, - run: function (root) { + run: function(root) { this.oVisitor.visit(root); }, visitImport: function(importNode, visitArgs) { if (importNode.importedFilename) { - var fullImportPath = this.mImportMappings[importNode.importedFilename]; + let fullImportPath = this.mImportMappings[importNode.importedFilename]; if (fullImportPath) { this.aImports.push(fullImportPath); } else { diff --git a/lib/plugin/rtl.js b/lib/plugin/rtl.js index 69b4d8db..7e21b743 100644 --- a/lib/plugin/rtl.js +++ b/lib/plugin/rtl.js @@ -12,40 +12,40 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; -var less = require('less'); +let less = require("less"); -var cssSizePattern = /(-?[\.0-9]+)([a-z]*)/; -var percentagePattern = /^\s*(-?[\.0-9]+)%\s*$/; +let cssSizePattern = /(-?[.0-9]+)([a-z]*)/; +let percentagePattern = /^\s*(-?[.0-9]+)%\s*$/; -var urlPattern = /('?"?([^\)]*\/)?)img\/([^\)]*)/; -var urlReplacement = '$1img-RTL/$3'; +let urlPattern = /('?"?([^)]*\/)?)img\/([^)]*)/; +let urlReplacement = "$1img-RTL/$3"; -var swapLeftRightPattern = /(\bright\b|\bleft\b)/g; +let swapLeftRightPattern = /(\bright\b|\bleft\b)/g; -var converterFunctions = { +let converterFunctions = { modifyAttributeName: function(ruleNode, replacement) { - modifyOnce(ruleNode, 'modifyAttributeName', function(node) { + modifyOnce(ruleNode, "modifyAttributeName", function(node) { node.name = replacement; }); }, shuffle4Values: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - var newParts; - if (valueObject.type === 'Anonymous') { - var parts = splitBySpace(valueObject.value); + let newParts; + if (valueObject.type === "Anonymous") { + let parts = splitBySpace(valueObject.value); if (parts.length === 4) { newParts = parts.slice(0); newParts[1] = parts[3]; newParts[3] = parts[1]; - valueObject.value = newParts.join(' '); + valueObject.value = newParts.join(" "); } - } else if (valueObject.type === 'Expression') { - var nodeCount = 0; - var rightValueIndex = null, leftValueIndex = null; - for (var i = 0; i < valueObject.value.length; i++) { - if (valueObject.value[i].type === 'Comment') { + } else if (valueObject.type === "Expression") { + let nodeCount = 0; + let rightValueIndex = null; let leftValueIndex = null; + for (let i = 0; i < valueObject.value.length; i++) { + if (valueObject.value[i].type === "Comment") { continue; } @@ -65,21 +65,20 @@ var converterFunctions = { newParts[leftValueIndex] = valueObject.value[rightValueIndex]; valueObject.value = newParts; } - } }); }, borderRadius: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Anonymous') { - var parts = splitBySpace(valueObject.value); - valueObject.value = mirrorBorderRadius(parts).join(' '); - } else if (valueObject.type === 'Expression') { - var newParts = []; - var currentParts = []; - for (var i = 0; i < valueObject.value.length; i++) { - var part = valueObject.value[i]; - if (part.type === 'Anonymous' && part.value === '/') { + if (valueObject.type === "Anonymous") { + let parts = splitBySpace(valueObject.value); + valueObject.value = mirrorBorderRadius(parts).join(" "); + } else if (valueObject.type === "Expression") { + let newParts = []; + let currentParts = []; + for (let i = 0; i < valueObject.value.length; i++) { + let part = valueObject.value[i]; + if (part.type === "Anonymous" && part.value === "/") { newParts = newParts.concat(mirrorBorderRadius(currentParts), part); currentParts = []; } else { @@ -95,15 +94,14 @@ var converterFunctions = { }, background: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression') { - for (var i = 0; i < valueObject.value.length; i++) { - var part = valueObject.value[i]; + if (valueObject.type === "Expression") { + for (let i = 0; i < valueObject.value.length; i++) { + let part = valueObject.value[i]; // first Dimension is the horizontal position value - if (part.type === 'Dimension') { - + if (part.type === "Dimension") { // mirror percentage dimensions - if (part.unit.is('%')) { + if (part.unit.is("%")) { mirrorPercentageDimensionNode(part); } @@ -111,74 +109,73 @@ var converterFunctions = { } // check if first Keyword value (horizontal background posistion) is no percentage value - if (part.type === 'Keyword' && - (part.value === 'left' || - part.value === 'right' || - part.value === 'center')) { + if (part.type === "Keyword" && + (part.value === "left" || + part.value === "right" || + part.value === "center")) { break; } // also break if there is a / which splits up posistion and size definitions - if (part.type === 'Anonymous' && part.value === '/') { + if (part.type === "Anonymous" && part.value === "/") { break; } - } } }); }, multiPosition: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression' && valueObject.value.length >= 1) { - var potentialPercentageObject = valueObject.value.filter(function(node) { + if (valueObject.type === "Expression" && valueObject.value.length >= 1) { + let potentialPercentageObject = valueObject.value.filter(function(node) { // get first node except comments - return node.type !== 'Comment'; + return node.type !== "Comment"; })[0]; if (potentialPercentageObject && - potentialPercentageObject.type === 'Dimension' && - potentialPercentageObject.unit.is('%')) { + potentialPercentageObject.type === "Dimension" && + potentialPercentageObject.unit.is("%")) { mirrorPercentageDimensionNode(potentialPercentageObject); } - } else if (valueObject.type === 'Anonymous') { + } else if (valueObject.type === "Anonymous") { valueObject.value = splitByComma(valueObject.value).map(function(value) { - var valueParts = splitBySpace(value); - var match = valueParts[0].match(percentagePattern); + let valueParts = splitBySpace(value); + let match = valueParts[0].match(percentagePattern); if (match) { - var parsedValue = (match[0].indexOf('.') > -1) + let parsedValue = (match[0].indexOf(".") > -1) ? parseFloat(match[0]) : parseInt(match[0], 10); - valueParts[0] = (100 - parsedValue) + '%'; - return valueParts.join(' '); + valueParts[0] = (100 - parsedValue) + "%"; + return valueParts.join(" "); } else { return value; } - }).join(','); - } else if (valueObject.type === 'Dimension' && valueObject.unit.is('%')) { + }).join(","); + } else if (valueObject.type === "Dimension" && valueObject.unit.is("%")) { mirrorPercentageDimensionNode(valueObject); } }); }, singlePosition: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression' && valueObject.value.length >= 1) { - var potentialPercentageObject = valueObject.value[0]; - if (potentialPercentageObject.type === 'Dimension' && - potentialPercentageObject.unit.is('%')) { + if (valueObject.type === "Expression" && valueObject.value.length >= 1) { + let potentialPercentageObject = valueObject.value[0]; + if (potentialPercentageObject.type === "Dimension" && + potentialPercentageObject.unit.is("%")) { mirrorPercentageDimensionNode(potentialPercentageObject); } - } else if (valueObject.type === 'Anonymous') { - var valueParts = splitBySpace(valueObject.value); - var match = valueParts[0].match(percentagePattern); + } else if (valueObject.type === "Anonymous") { + let valueParts = splitBySpace(valueObject.value); + let match = valueParts[0].match(percentagePattern); if (match) { - valueParts[0] = (100 - parseInt(match[0], 10)) + '%'; - valueObject.value = valueParts.join(' '); + valueParts[0] = (100 - parseInt(match[0], 10)) + "%"; + valueObject.value = valueParts.join(" "); } } }); }, transform: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression') { + if (valueObject.type === "Expression") { valueObject.value.forEach(processTransformNode); } else { processTransformNode(valueObject); @@ -187,7 +184,7 @@ var converterFunctions = { }, cursor: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression') { + if (valueObject.type === "Expression") { valueObject.value.forEach(processCursorNode); } else { processCursorNode(valueObject); @@ -196,20 +193,18 @@ var converterFunctions = { }, shadow: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression') { - - for (var i = 0; i < valueObject.value.length; i++) { - if (valueObject.value[i].type === 'Dimension') { + if (valueObject.type === "Expression") { + for (let i = 0; i < valueObject.value.length; i++) { + if (valueObject.value[i].type === "Dimension") { negate(valueObject.value[i]); break; } } - - } else if (valueObject.type === 'Anonymous') { - modifyOnce(valueObject, 'shadow', function(node) { + } else if (valueObject.type === "Anonymous") { + modifyOnce(valueObject, "shadow", function(node) { node.value = splitByComma(node.value).map(function(part) { return mirrorShadow(part); - }).join(','); + }).join(","); }); } }); @@ -219,16 +214,16 @@ var converterFunctions = { }, url: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Url') { + if (valueObject.type === "Url") { replaceUrl(valueObject); - } else if (valueObject.type === 'Expression') { + } else if (valueObject.type === "Expression") { valueObject.value.forEach(replaceUrl); } }); }, gradient: function(ruleNode) { ruleNode.value.value.forEach(function(valueObject) { - if (valueObject.type === 'Expression') { + if (valueObject.type === "Expression") { valueObject.value.forEach(processGradientCallNode); } else { processGradientCallNode(valueObject); @@ -237,189 +232,189 @@ var converterFunctions = { } }; -var converterMapping = { +let converterMapping = { modifyAttributeName: { - 'left': 'right', - 'right': 'left', - 'border-left': 'border-right', - 'border-right': 'border-left', - 'border-left-color': 'border-right-color', - 'border-right-color': 'border-left-color', - 'border-left-style': 'border-right-style', - 'border-right-style': 'border-left-style', - 'border-left-width': 'border-right-width', - 'border-right-width': 'border-left-width', - 'margin-left': 'margin-right', - 'margin-right': 'margin-left', - 'padding-left': 'padding-right', - 'padding-right': 'padding-left', - 'border-bottom-left-radius': 'border-bottom-right-radius', - 'border-bottom-right-radius': 'border-bottom-left-radius', - 'border-top-left-radius': 'border-top-right-radius', - 'border-top-right-radius': 'border-top-left-radius', - 'nav-left': 'nav-right', - 'nav-right': 'nav-left', - '-moz-border-radius-topright': '-moz-border-radius-topleft', - '-moz-border-radius-topleft': '-moz-border-radius-topright', - '-webkit-border-top-right-radius': '-webkit-border-top-left-radius', - '-webkit-border-top-left-radius': '-webkit-border-top-right-radius', - '-moz-border-radius-bottomright': '-moz-border-radius-bottomleft', - '-moz-border-radius-bottomleft': '-moz-border-radius-bottomright', - '-webkit-border-bottom-right-radius': '-webkit-border-bottom-left-radius', - '-webkit-border-bottom-left-radius': '-webkit-border-bottom-right-radius' + "left": "right", + "right": "left", + "border-left": "border-right", + "border-right": "border-left", + "border-left-color": "border-right-color", + "border-right-color": "border-left-color", + "border-left-style": "border-right-style", + "border-right-style": "border-left-style", + "border-left-width": "border-right-width", + "border-right-width": "border-left-width", + "margin-left": "margin-right", + "margin-right": "margin-left", + "padding-left": "padding-right", + "padding-right": "padding-left", + "border-bottom-left-radius": "border-bottom-right-radius", + "border-bottom-right-radius": "border-bottom-left-radius", + "border-top-left-radius": "border-top-right-radius", + "border-top-right-radius": "border-top-left-radius", + "nav-left": "nav-right", + "nav-right": "nav-left", + "-moz-border-radius-topright": "-moz-border-radius-topleft", + "-moz-border-radius-topleft": "-moz-border-radius-topright", + "-webkit-border-top-right-radius": "-webkit-border-top-left-radius", + "-webkit-border-top-left-radius": "-webkit-border-top-right-radius", + "-moz-border-radius-bottomright": "-moz-border-radius-bottomleft", + "-moz-border-radius-bottomleft": "-moz-border-radius-bottomright", + "-webkit-border-bottom-right-radius": "-webkit-border-bottom-left-radius", + "-webkit-border-bottom-left-radius": "-webkit-border-bottom-right-radius" }, shuffle4Values: { - 'border-style': true, - 'border-color': true, - 'border-width': true, - 'margin': true, - 'padding': true, - 'border-image-outset': true, - 'border-image-width': true + "border-style": true, + "border-color": true, + "border-width": true, + "margin": true, + "padding": true, + "border-image-outset": true, + "border-image-width": true }, borderRadius: { - 'border-radius': true, - '-moz-border-radius': true, - '-webkit-border-radius': true + "border-radius": true, + "-moz-border-radius": true, + "-webkit-border-radius": true }, background: { - 'background': true + "background": true }, multiPosition: { - 'background-position': true + "background-position": true }, singlePosition: { - 'object-position': true, - 'perspective-origin': true, - '-moz-perspective-origin': true, - '-webkit-perspective-origin': true, - 'transform-origin': true, - '-moz-transform-origin': true, - '-ms-transform-origin': true, - '-webkit-transform-origin': true + "object-position": true, + "perspective-origin": true, + "-moz-perspective-origin": true, + "-webkit-perspective-origin": true, + "transform-origin": true, + "-moz-transform-origin": true, + "-ms-transform-origin": true, + "-webkit-transform-origin": true }, transform: { - 'transform': true, - '-ms-transform': true, - '-moz-transform': true, - '-webkit-transform': true + "transform": true, + "-ms-transform": true, + "-moz-transform": true, + "-webkit-transform": true }, cursor: { - 'cursor': true + "cursor": true }, shadow: { - 'box-shadow': true, - '-moz-box-shadow': true, - '-webkit-box-shadow': true, - 'text-shadow': true + "box-shadow": true, + "-moz-box-shadow": true, + "-webkit-box-shadow": true, + "text-shadow": true }, swapLeftRightValue: { - 'background': true, - 'background-position': true, - 'background-image': true, - '-ms-background-position-x': true, - 'break-after': true, - 'break-before': true, - 'clear': true, - 'object-position': true, - 'float': true, - 'page-break-after': true, - 'page-break-before': true, - 'perspective-origin': true, - 'ruby-align': true, + "background": true, + "background-position": true, + "background-image": true, + "-ms-background-position-x": true, + "break-after": true, + "break-before": true, + "clear": true, + "object-position": true, + "float": true, + "page-break-after": true, + "page-break-before": true, + "perspective-origin": true, + "ruby-align": true, // "text-align" is not mirrored because "start" and "end" are available to support RTL! IE does not support those and shall receive special CSS rules - 'transform-origin': true, - '-moz-transform-origin': true, - '-ms-transform-origin': true, - '-webkit-transform-origin': true + "transform-origin": true, + "-moz-transform-origin": true, + "-ms-transform-origin": true, + "-webkit-transform-origin": true }, url: { - 'background': true, - 'background-image': true, - 'content': true, - 'cursor': true, - 'icon': true, - 'list-style-image': true + "background": true, + "background-image": true, + "content": true, + "cursor": true, + "icon": true, + "list-style-image": true }, gradient: { - 'background': true, - 'background-image': true + "background": true, + "background-image": true } }; -var transformMapping = { +let transformMapping = { negateFirst: { - 'translate': true, - 'translate3d': true, - 'rotate': true, - 'rotatey': true, - 'rotateY': true, - 'rotatez': true, - 'rotateZ': true, - 'skewX': true, - 'skewx': true, - 'skewY': true, - 'skewy': true + "translate": true, + "translate3d": true, + "rotate": true, + "rotatey": true, + "rotateY": true, + "rotatez": true, + "rotateZ": true, + "skewX": true, + "skewx": true, + "skewY": true, + "skewy": true }, negateTwo: { - 'skew': true + "skew": true }, negateSecondNumber: { - 'rotate3d': true + "rotate3d": true } }; -var cursorMapping = { - 'e-resize': 'w-resize', - 'w-resize': 'e-resize', - 'ne-resize': 'nw-resize', - 'nw-resize': 'ne-resize', - 'se-resize': 'sw-resize', - 'sw-resize': 'se-resize', - 'nesw-resize': 'nwse-resize', - 'nwse-resize': 'nesw-resize' +let cursorMapping = { + "e-resize": "w-resize", + "w-resize": "e-resize", + "ne-resize": "nw-resize", + "nw-resize": "ne-resize", + "se-resize": "sw-resize", + "sw-resize": "se-resize", + "nesw-resize": "nwse-resize", + "nwse-resize": "nesw-resize" }; function swapLeftRight(valueObject) { - if (valueObject.type === 'Anonymous' || valueObject.type === 'Keyword') { - modifyOnce(valueObject, 'swapLeftRight', function(node) { + if (valueObject.type === "Anonymous" || valueObject.type === "Keyword") { + modifyOnce(valueObject, "swapLeftRight", function(node) { node.value = node.value.replace(swapLeftRightPattern, function(match, p1, offset, string) { - return p1 === 'left' ? 'right' : 'left'; + return p1 === "left" ? "right" : "left"; }); }); - } else if (valueObject.type === 'Expression') { + } else if (valueObject.type === "Expression") { valueObject.value.forEach(swapLeftRight); - } else if (valueObject.type === 'Call') { + } else if (valueObject.type === "Call") { valueObject.args.forEach(swapLeftRight); } } function splitByComma(value) { - var lastStart = 0; - var inParentheses = false; - var parts = []; - for (var i = 0; i < value.length; i++) { - var character = value[i]; - if (character === '(') { + let lastStart = 0; + let inParentheses = false; + let parts = []; + for (let i = 0; i < value.length; i++) { + let character = value[i]; + if (character === "(") { inParentheses = true; - } else if (character === ')') { + } else if (character === ")") { inParentheses = false; - } else if (character === ',') { + } else if (character === ",") { if (!inParentheses) { parts.push(value.substring(lastStart, i)); lastStart = i + 1; @@ -437,10 +432,10 @@ function splitBySpace(value) { } function mirrorBorderRadius(parts) { - var result = parts.slice(0); - var valueIndices = [], commentIndices = []; - var length = parts.filter(function(part, i) { - if (part.type !== 'Comment') { + let result = parts.slice(0); + let valueIndices = []; let commentIndices = []; + let length = parts.filter(function(part, i) { + if (part.type !== "Comment") { valueIndices.push(i); return true; } else { @@ -460,7 +455,6 @@ function mirrorBorderRadius(parts) { result[valueIndices[1]] = parts[valueIndices[0]]; result[valueIndices[2]] = parts[valueIndices[1]]; result.splice(valueIndices[2] + 1, 0, parts[valueIndices[2]]); - } else if (length === 4) { // 1 2 3 4 -> 2 1 4 3 @@ -473,19 +467,19 @@ function mirrorBorderRadius(parts) { } function negate(node) { - if (node.type === 'Dimension') { - modifyOnce(node, 'negate', function(negateNode) { + if (node.type === "Dimension") { + modifyOnce(node, "negate", function(negateNode) { negateNode.value = -negateNode.value; }); } } function processTransformNode(node) { - if (node.type !== 'Call') { + if (node.type !== "Call") { return; } - var name = node.name; + let name = node.name; if (transformMapping.negateFirst[name]) { negate(node.args[0]); } else if (transformMapping.negateTwo[name]) { @@ -499,14 +493,14 @@ function processTransformNode(node) { } function mirrorShadow(value) { - var parts = splitBySpace(value); - var offsetXIndex = (parts[0] === 'inset' && parts.length > 1) ? 1 : 0; - var offsetX = parts[offsetXIndex]; - var match = offsetX.match(cssSizePattern); + let parts = splitBySpace(value); + let offsetXIndex = (parts[0] === "inset" && parts.length > 1) ? 1 : 0; + let offsetX = parts[offsetXIndex]; + let match = offsetX.match(cssSizePattern); if (match) { - var offsetXValue = match[1]; - var negated; - if (offsetXValue.indexOf('.') > -1) { + let offsetXValue = match[1]; + let negated; + if (offsetXValue.indexOf(".") > -1) { negated = -parseFloat(offsetXValue); } else { negated = -parseInt(offsetXValue, 10); @@ -514,35 +508,32 @@ function mirrorShadow(value) { parts[offsetXIndex] = negated + match[2]; } - return parts.join(' '); + return parts.join(" "); } function mirrorPercentageDimensionNode(node) { - if (node.type === 'Dimension' && node.unit.is('%')) { - modifyOnce(node, 'mirrorPercentageDimensionNode', function(mirrorNode) { + if (node.type === "Dimension" && node.unit.is("%")) { + modifyOnce(node, "mirrorPercentageDimensionNode", function(mirrorNode) { mirrorNode.value = 100 - mirrorNode.value; }); } } function processGradientCallNode(node) { - if (node.type === 'Call' && - endsWith(node.name, 'linear-gradient') && + if (node.type === "Call" && + endsWith(node.name, "linear-gradient") && node.args.length >= 1) { - - var firstPart = node.args[0]; - if (firstPart.type === 'Dimension') { - - if (firstPart.unit.is('%')) { + let firstPart = node.args[0]; + if (firstPart.type === "Dimension") { + if (firstPart.unit.is("%")) { mirrorPercentageDimensionNode(firstPart); } mirrorLinearGradientAngle(firstPart); + } else if (firstPart.type === "Expression") { + let firstSubPart = firstPart.value[0]; - } else if (firstPart.type === 'Expression') { - var firstSubPart = firstPart.value[0]; - - if (firstSubPart.type === 'Dimension' && firstSubPart.unit.is('%')) { + if (firstSubPart.type === "Dimension" && firstSubPart.unit.is("%")) { mirrorPercentageDimensionNode(firstSubPart); } @@ -552,21 +543,21 @@ function processGradientCallNode(node) { } function mirrorLinearGradientAngle(node) { - if (node.type !== 'Dimension') { + if (node.type !== "Dimension") { return; } - modifyOnce(node, 'mirrorLinearGradientAngle', function(mirrorNode) { + modifyOnce(node, "mirrorLinearGradientAngle", function(mirrorNode) { switch (mirrorNode.unit.toString()) { - case 'deg': + case "deg": mirrorNode.value = 180 - mirrorNode.value; break; - case 'grad': + case "grad": mirrorNode.value = 200 - mirrorNode.value; break; - case 'rad': + case "rad": mirrorNode.value = Math.round((Math.PI - mirrorNode.value) * 100) / 100; break; - case 'turn': + case "turn": mirrorNode.value = Math.round((0.5 - mirrorNode.value) * 100) / 100; break; default: @@ -576,10 +567,10 @@ function mirrorLinearGradientAngle(node) { } function processCursorNode(node) { - if (node.type === 'Keyword') { - var replacement = cursorMapping[node.value]; + if (node.type === "Keyword") { + let replacement = cursorMapping[node.value]; if (replacement) { - modifyOnce(node, 'cursor', function(cursorNode) { + modifyOnce(node, "cursor", function(cursorNode) { cursorNode.value = replacement; }); } @@ -587,8 +578,8 @@ function processCursorNode(node) { } function replaceUrl(node) { - if (node.type === 'Url') { - modifyOnce(node, 'replaceUrl', function(urlNode) { + if (node.type === "Url") { + modifyOnce(node, "replaceUrl", function(urlNode) { urlNode.value.value = urlNode.value.value.replace(urlPattern, urlReplacement); }); } @@ -608,23 +599,25 @@ function modifyOnce(node, type, fn) { } } -var LessRtlPlugin = module.exports = function() { - /*eslint-disable new-cap */ +let LessRtlPlugin = module.exports = function() { + /* eslint-disable new-cap */ this.oVisitor = new less.tree.visitor(this); - /*eslint-enable new-cap */ + /* eslint-enable new-cap */ }; LessRtlPlugin.prototype = { isReplacing: true, isPreEvalVisitor: false, - run: function (root) { + run: function(root) { return this.oVisitor.visit(root); }, visitRule: function(ruleNode, visitArgs) { - for (var converter in converterMapping) { - var mappingValue = converterMapping[converter][ruleNode.name]; - if (mappingValue) { - converterFunctions[converter].call(this, ruleNode, mappingValue); + for (let converter in converterMapping) { + if (converterMapping.hasOwnProperty(converter)) { + let mappingValue = converterMapping[converter][ruleNode.name]; + if (mappingValue) { + converterFunctions[converter].call(this, ruleNode, mappingValue); + } } } diff --git a/lib/plugin/variable-collector.js b/lib/plugin/variable-collector.js index b70554bd..e8dcf52b 100644 --- a/lib/plugin/variable-collector.js +++ b/lib/plugin/variable-collector.js @@ -12,77 +12,77 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; -var path = require('path'); -var less = require('less'); +"use strict"; +let path = require("path"); +let less = require("less"); -var VariableCollector = module.exports = function(env) { - /*eslint-disable new-cap */ - this.oVisitor = new less.tree.visitor(this); - /*eslint-enable new-cap */ - this.env = env; - this.mVariables = {}; - this.mGlobalVariables = {}; - this.mVarFile = {}; +let VariableCollector = module.exports = function(env) { + /* eslint-disable new-cap */ + this.oVisitor = new less.tree.visitor(this); + /* eslint-enable new-cap */ + this.env = env; + this.mVariables = {}; + this.mGlobalVariables = {}; + this.mVarFile = {}; }; VariableCollector.prototype = { - isPreVisitor: true, - run: function (root) { - this.mGlobalVariables = root.variables(); - return this.oVisitor.visit(root); - }, + isPreVisitor: true, + run: function(root) { + this.mGlobalVariables = root.variables(); + return this.oVisitor.visit(root); + }, - visitRule: function(node) { - if (!node.variable) { - return; - } - if (!this.mGlobalVariables[node.name]) { - // Ignoring local variable - return; - } - try { - var value = node.value.toCSS(this.env); - this.mVariables[node.name.substr(1)] = { - value: value, - filename: node.currentFileInfo.filename, - rootFilename: node.currentFileInfo.rootFilename - }; - } catch (err) { - // Errors might occur within mixins. - // But as we only collect global variables, this doesn't matter... - } - }, + visitRule: function(node) { + if (!node.variable) { + return; + } + if (!this.mGlobalVariables[node.name]) { + // Ignoring local variable + return; + } + try { + let value = node.value.toCSS(this.env); + this.mVariables[node.name.substr(1)] = { + value: value, + filename: node.currentFileInfo.filename, + rootFilename: node.currentFileInfo.rootFilename + }; + } catch (err) { + // Errors might occur within mixins. + // But as we only collect global variables, this doesn't matter... + } + }, - getVariables: function(aImports) { - var mVariables = {}; + getVariables: function(aImports) { + let mVariables = {}; - for (var name in this.mVariables) { - if (this.mVariables.hasOwnProperty(name)) { - var oVar = this.mVariables[name]; - var dirname = path.posix.dirname(oVar.filename); - var baseFileName = path.posix.basename(oVar.rootFilename); // usually library.source.less - var libraryBaseFile = path.posix.normalize(path.posix.join(dirname, baseFileName)); + for (let name in this.mVariables) { + if (this.mVariables.hasOwnProperty(name)) { + let oVar = this.mVariables[name]; + let dirname = path.posix.dirname(oVar.filename); + let baseFileName = path.posix.basename(oVar.rootFilename); // usually library.source.less + let libraryBaseFile = path.posix.normalize(path.posix.join(dirname, baseFileName)); - // Only add variable if the corresponding library "base file" has been imported - if (aImports.indexOf(libraryBaseFile) > -1 || libraryBaseFile === oVar.rootFilename) { - mVariables[name] = oVar.value; - } - } - } + // Only add variable if the corresponding library "base file" has been imported + if (aImports.indexOf(libraryBaseFile) > -1 || libraryBaseFile === oVar.rootFilename) { + mVariables[name] = oVar.value; + } + } + } - return mVariables; - }, + return mVariables; + }, - getAllVariables: function(aImports) { - var mVariables = {}; - for (var name in this.mVariables) { - if (this.mVariables.hasOwnProperty(name)) { - var oVar = this.mVariables[name]; - mVariables[name] = oVar.value; - } - } - return mVariables; - } + getAllVariables: function(aImports) { + let mVariables = {}; + for (let name in this.mVariables) { + if (this.mVariables.hasOwnProperty(name)) { + let oVar = this.mVariables[name]; + mVariables[name] = oVar.value; + } + } + return mVariables; + } }; diff --git a/lib/scope.js b/lib/scope.js index 1a066e11..71976abf 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -12,30 +12,29 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; /** * DOM-Elements like html, body as CSS selector needs be handled differently in * the scoping. Those selectors will be identified by matching the respective * regEx. */ -var rRegex = /(html[^\s]*|body[^\s]*)/; +let rRegex = /(html[^\s]*|body[^\s]*)/; -var rPoint = /(^\s?\.{1}\w*)/; +let rPoint = /(^\s?\.{1}\w*)/; function handleScoping(sSelector, sScopeName) { - /** * Match the selector to regex, by splitting into two array elements, * where the first element is the resulting matching group. */ - var aCaptureGroups = sSelector.split(rRegex); + let aCaptureGroups = sSelector.split(rRegex); - var aSelectors = []; - var sSelector1, sSelector2; + let aSelectors = []; + let sSelector1; let sSelector2; // filter empty strings and undefined objects - var aMatch = aCaptureGroups.filter(function(n) { + let aMatch = aCaptureGroups.filter(function(n) { return !!n; }); @@ -47,7 +46,7 @@ function handleScoping(sSelector, sScopeName) { // starts with a css class or dom element if (aMatch[1].match(rPoint)) { sSelector2 = aMatch[0] + " " + sScopeName + - aMatch[1].replace(/\s/, ''); + aMatch[1].replace(/\s/, ""); } else { // no match, selector is a dom element sSelector2 = null; @@ -83,21 +82,18 @@ function Scoping(oSheet, sScopeName) { } Scoping.prototype.scopeRules = function(oRules) { - - for (var iNode = 0; iNode < oRules.length; iNode++) { - var oNode = oRules[iNode]; + for (let iNode = 0; iNode < oRules.length; iNode++) { + let oNode = oRules[iNode]; if (oNode.type === "rule") { + let aNewSelectors = []; - var aNewSelectors = []; - - for (var i = 0; i < oNode.selectors.length; i++) { - var sSelector = oNode.selectors[i]; - var sSelector2; + for (let i = 0; i < oNode.selectors.length; i++) { + let sSelector = oNode.selectors[i]; + let sSelector2; if (!(sSelector.match(/.sapContrast/))) { - - var aScopedSelectors = handleScoping(sSelector, this.sScopeName); + let aScopedSelectors = handleScoping(sSelector, this.sScopeName); sSelector = (aScopedSelectors[0] ? aScopedSelectors[0] : sSelector); sSelector2 = (aScopedSelectors[1] ? aScopedSelectors[1] : null); @@ -106,18 +102,15 @@ Scoping.prototype.scopeRules = function(oRules) { aNewSelectors.push(sSelector2); } } - } if (aNewSelectors.length > 0) { oNode.selectors = aNewSelectors; } - } else if (oNode.type === "media") { this.scopeRules(oNode.rules); } } - }; Scoping.prototype.run = function() { @@ -131,14 +124,12 @@ module.exports = function scope(oSheet, sScopeName) { }; module.exports.scopeCssRoot = function scopeCssRoot(oRules, sScopeName) { - - for (var iNode = 0; iNode < oRules.length; iNode++) { - var oNode = oRules[iNode]; + for (let iNode = 0; iNode < oRules.length; iNode++) { + let oNode = oRules[iNode]; if (oNode.type === "rule") { - - for (var i = 0; i < oNode.selectors.length; i++) { - var sSelector = oNode.selectors[i]; + for (let i = 0; i < oNode.selectors.length; i++) { + let sSelector = oNode.selectors[i]; if (sSelector.match(/#CSS_SCOPE_ROOT\b/)) { oNode.selectors[i] = "." + sScopeName; @@ -147,7 +138,6 @@ module.exports.scopeCssRoot = function scopeCssRoot(oRules, sScopeName) { return oNode; } - } } } diff --git a/package.json b/package.json index 4a490bc3..1fc78cd8 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "devDependencies": { "clean-css": "^3.4.23", "eslint": "^5.5.0", + "eslint-config-google": "^0.10.0", "graceful-fs": "^4.1.11", "mocha": "^3.2.0" } diff --git a/test/common/helper.js b/test/common/helper.js index 6b2af3f7..10387c46 100644 --- a/test/common/helper.js +++ b/test/common/helper.js @@ -12,22 +12,22 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -'use strict'; +"use strict"; -var fs = require('fs'); +let fs = require("fs"); -var crlfPattern = /\r\n/g; -var lastLfPattern = /\n$/; -var noLastLfPattern = /([^\n])$/; +let crlfPattern = /\r\n/g; +let lastLfPattern = /\n$/; +let noLastLfPattern = /([^\n])$/; // file util function readFile(filename, lastLf) { - var content = fs.readFileSync(filename, { encoding: 'utf-8' }).replace(crlfPattern, '\n'); - if (lastLf === false) { - return content.replace(lastLfPattern, ''); // needed when using compress option - } else { - return content.replace(noLastLfPattern, '$1\n'); // adds last LF - } + let content = fs.readFileSync(filename, {encoding: "utf-8"}).replace(crlfPattern, "\n"); + if (lastLf === false) { + return content.replace(lastLfPattern, ""); // needed when using compress option + } else { + return content.replace(noLastLfPattern, "$1\n"); // adds last LF + } } module.exports.readFile = readFile; diff --git a/test/test-custom-fs.js b/test/test-custom-fs.js index 2315175e..d4f3dd4a 100644 --- a/test/test-custom-fs.js +++ b/test/test-custom-fs.js @@ -12,71 +12,65 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -/*eslint-env mocha */ -'use strict'; +/* eslint-env mocha */ +"use strict"; -var assert = require('assert'); -var readFile = require('./common/helper').readFile; -var fs = require('fs'); +let assert = require("assert"); +let readFile = require("./common/helper").readFile; +let fs = require("fs"); // tested module -var Builder = require('../').Builder; +let Builder = require("../").Builder; -describe('(custom fs) CSS Scoping of', function() { +describe("(custom fs) CSS Scoping of", function() { + describe("comments", function() { + it("should return same CSS for foo", function() { + return new Builder({ + fs: require("graceful-fs") + }).build({ + lessInputPath: "comments/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/comments/lib1", + "test/fixtures/libraries/scopes/comments/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); - describe('comments', function() { + it("should return same CSS for bar", function() { + let readFileCalls = 0; - it('should return same CSS for foo', function() { - return new Builder({ - fs: require('graceful-fs') - }).build({ - lessInputPath: 'comments/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/comments/lib1', - 'test/fixtures/libraries/scopes/comments/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); + let statCalls = 0; - }); - - it('should return same CSS for bar', function() { - - var readFileCalls = 0, - statCalls = 0; - - return new Builder({ - fs: { - readFile: function() { - readFileCalls++; - return fs.readFile.apply(fs, arguments); - }, - stat: function() { - statCalls++; - return fs.stat.apply(fs, arguments); - } - } - }).build({ - lessInputPath: 'comments/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/comments/lib1', - 'test/fixtures/libraries/scopes/comments/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - assert.equal(readFileCalls, 3, "fs.readFile should have been called 3 times"); - assert.equal(statCalls, 19, "fs.stat should have been called 19 times"); - }); - - }); - - }); - -}); \ No newline at end of file + return new Builder({ + fs: { + readFile: function(...args) { + readFileCalls++; + return fs.readFile(...args); + }, + stat: function(...args) { + statCalls++; + return fs.stat(...args); + } + } + }).build({ + lessInputPath: "comments/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/comments/lib1", + "test/fixtures/libraries/scopes/comments/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + assert.equal(readFileCalls, 3, "fs.readFile should have been called 3 times"); + assert.equal(statCalls, 19, "fs.stat should have been called 19 times"); + }); + }); + }); +}); diff --git a/test/test-perf-workaround.js b/test/test-perf-workaround.js index 488bf6d8..d0341521 100644 --- a/test/test-perf-workaround.js +++ b/test/test-perf-workaround.js @@ -12,71 +12,66 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -/*eslint-env mocha */ -'use strict'; +/* eslint-env mocha */ +"use strict"; -var assert = require('assert'); -var path = require('path'); -var readFile = require('./common/helper').readFile; +let assert = require("assert"); +let path = require("path"); +let readFile = require("./common/helper").readFile; // tested module -var Builder = require('../').Builder; +let Builder = require("../").Builder; -describe('performance workaround', function() { +describe("performance workaround", function() { + it("should run with patched String prototype", function() { + function customGetter() { + return "customGetter"; + } + String.prototype.__defineGetter__("customGetter", customGetter); - it('should run with patched String prototype', function() { + function customProp() { + return "customProp"; + } + // eslint-disable-next-line no-extend-native + String.prototype.customProp = customProp; - function customGetter() { - return "customGetter"; - } - String.prototype.__defineGetter__("customGetter", customGetter); + return new Builder().build({ + lessInputPath: "my/ui/lib/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ], + library: { + name: "my.ui.lib" + } + }).then(function(result) { + let oVariablesExpected = { + "default": { + "color1": "#ffffff", - function customProp() { - return "customProp"; - } - String.prototype.customProp = customProp; + }, + "scopes": { + "fooContrast": { + "color1": "#000000" + } + } + }; - return new Builder().build({ - lessInputPath: 'my/ui/lib/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ], - library: { - name: "my.ui.lib" - } - }).then(function(result) { - - var oVariablesExpected = { - "default" : { - "color1": "#ffffff", - - }, - "scopes": { - "fooContrast": { - "color1": "#000000" - } - } - } - - assert.equal(result.css, readFile('test/expected/libraries/lib1/my/ui/lib/themes/foo/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib1/my/ui/lib/themes/foo/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, oVariablesExpected, 'variables should be correctly collected.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "library.source.less"), + assert.equal(result.css, readFile("test/expected/libraries/lib1/my/ui/lib/themes/foo/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib1/my/ui/lib/themes/foo/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, oVariablesExpected, "variables should be correctly collected."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "library.source.less"), path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "library.source.less"), path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), - path.join("test", "fixtures", "libraries", "lib1", "sap", "ui", "core", "themes", "foo", ".theming") - ], 'import list should be correct.'); - - assert.strictEqual(String.prototype.__lookupGetter__("customGetter"), customGetter, "Custom getter should again be set on String prototype."); - assert.strictEqual(String.prototype.customProp, customProp, "Custom property should again be set on String prototype."); - - }); - - }); + path.join("test", "fixtures", "libraries", "lib1", "sap", "ui", "core", "themes", "foo", ".theming") + ], "import list should be correct."); + assert.strictEqual(String.prototype.__lookupGetter__("customGetter"), customGetter, "Custom getter should again be set on String prototype."); + assert.strictEqual(String.prototype.customProp, customProp, "Custom property should again be set on String prototype."); + }); + }); }); diff --git a/test/test.js b/test/test.js index 322ab8f1..f4e31b83 100644 --- a/test/test.js +++ b/test/test.js @@ -12,1448 +12,1227 @@ // either express or implied. See the License for the specific // language governing permissions and limitations under the License. -/*eslint-env mocha */ -'use strict'; +/* eslint-env mocha */ +"use strict"; -var assert = require('assert'); -var path = require('path'); -var clone = require('clone'); -var readFile = require('./common/helper').readFile; +let assert = require("assert"); +let path = require("path"); +let clone = require("clone"); +let readFile = require("./common/helper").readFile; // tested module -var Builder = require('../').Builder; - -describe('options', function() { - - it('should return css, cssRtl, variables and imports with default options (lessInput)', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/simple/test.less') - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/simple/test.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/simple/test-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, JSON.parse(readFile('test/expected/simple/test-variables.json')), 'variables should be correctly collected.'); - assert.deepEqual(result.imports, [], 'import list should be empty.'); - - }); - - }); - - it('should return css, cssRtl, variables and imports with default options (lessInputPath)', function() { - - return new Builder().build({ - lessInputPath: 'test/fixtures/simple/test.less' - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/simple/test.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/simple/test-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, JSON.parse(readFile('test/expected/simple/test-variables.json')), 'variables should be correctly collected.'); - assert.deepEqual(result.imports, ['test/fixtures/simple/test.less'], 'import list should be empty.'); - - }); - - }); - - it('should not return cssRtl with option rtl set to false', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/simple/test.less'), - rtl: false - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/simple/test.css'), 'css should be correctly generated.'); - assert.strictEqual(result.cssRtl, undefined, 'rtl css should not be generated.'); - assert.deepEqual(result.variables, JSON.parse(readFile('test/expected/simple/test-variables.json')), 'variables should be correctly collected.'); - - }); - - }); - - it('should return minified css and cssRtl with lessOption compress set to true', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/simple/test.less'), - compiler: { - compress: true - } - }).then(function(result) { - - // remove the last LF to be able to compare the content correctly - assert.equal(result.css, readFile('test/expected/simple/test.min.css', false), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/simple/test-RTL.min.css', false), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, JSON.parse(readFile('test/expected/simple/test-variables.min.json')), 'variables should be correctly collected.'); - assert.deepEqual(result.imports, [], 'import list should be empty.'); - - }); - - }); - - it('should resolve import directives with rootPaths option', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/rootPaths/lib2/my/themes/bar/bar.less'), - rootPaths: [ - 'test/fixtures/rootPaths/lib1', - 'test/fixtures/rootPaths/lib2' - ], - parser: { - filename: 'my/themes/bar/bar.less' - } - }).then(function(result) { - - assert.equal(result.css, '', 'css should be empty.'); - assert.deepEqual(result.variables, {}, 'variables should be empty.'); - assert.deepEqual(result.imports, [ - path.join( - 'test', 'fixtures', 'rootPaths', - 'lib1', 'my', 'themes', 'foo', 'foo.less' - ) - ], 'import list should not correctly filled.'); - - }); - - }); - - it('should read input file with rootPaths option', function() { - - return new Builder().build({ - lessInputPath: 'my/themes/bar/bar.less', - rootPaths: [ - 'test/fixtures/rootPaths/lib1', - 'test/fixtures/rootPaths/lib2' - ] - }).then(function(result) { - - assert.equal(result.css, '', 'css should be empty.'); - assert.deepEqual(result.variables, {}, 'variables should be empty.'); - assert.deepEqual(result.imports, [ - path.join( - 'test', 'fixtures', 'rootPaths', - 'lib2', 'my', 'themes', 'bar', 'bar.less' - ), - path.join( - 'test', 'fixtures', 'rootPaths', - 'lib1', 'my', 'themes', 'foo', 'foo.less' - ) - ], 'import list should not correctly filled.'); - - }); - - }); - +let Builder = require("../").Builder; + +describe("options", function() { + it("should return css, cssRtl, variables and imports with default options (lessInput)", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/simple/test.less") + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/simple/test.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/simple/test-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, JSON.parse(readFile("test/expected/simple/test-variables.json")), "variables should be correctly collected."); + assert.deepEqual(result.imports, [], "import list should be empty."); + }); + }); + + it("should return css, cssRtl, variables and imports with default options (lessInputPath)", function() { + return new Builder().build({ + lessInputPath: "test/fixtures/simple/test.less" + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/simple/test.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/simple/test-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, JSON.parse(readFile("test/expected/simple/test-variables.json")), "variables should be correctly collected."); + assert.deepEqual(result.imports, ["test/fixtures/simple/test.less"], "import list should be empty."); + }); + }); + + it("should not return cssRtl with option rtl set to false", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/simple/test.less"), + rtl: false + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/simple/test.css"), "css should be correctly generated."); + assert.strictEqual(result.cssRtl, undefined, "rtl css should not be generated."); + assert.deepEqual(result.variables, JSON.parse(readFile("test/expected/simple/test-variables.json")), "variables should be correctly collected."); + }); + }); + + it("should return minified css and cssRtl with lessOption compress set to true", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/simple/test.less"), + compiler: { + compress: true + } + }).then(function(result) { + // remove the last LF to be able to compare the content correctly + assert.equal(result.css, readFile("test/expected/simple/test.min.css", false), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/simple/test-RTL.min.css", false), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, JSON.parse(readFile("test/expected/simple/test-variables.min.json")), "variables should be correctly collected."); + assert.deepEqual(result.imports, [], "import list should be empty."); + }); + }); + + it("should resolve import directives with rootPaths option", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/rootPaths/lib2/my/themes/bar/bar.less"), + rootPaths: [ + "test/fixtures/rootPaths/lib1", + "test/fixtures/rootPaths/lib2" + ], + parser: { + filename: "my/themes/bar/bar.less" + } + }).then(function(result) { + assert.equal(result.css, "", "css should be empty."); + assert.deepEqual(result.variables, {}, "variables should be empty."); + assert.deepEqual(result.imports, [ + path.join( + "test", "fixtures", "rootPaths", + "lib1", "my", "themes", "foo", "foo.less" + ) + ], "import list should not correctly filled."); + }); + }); + + it("should read input file with rootPaths option", function() { + return new Builder().build({ + lessInputPath: "my/themes/bar/bar.less", + rootPaths: [ + "test/fixtures/rootPaths/lib1", + "test/fixtures/rootPaths/lib2" + ] + }).then(function(result) { + assert.equal(result.css, "", "css should be empty."); + assert.deepEqual(result.variables, {}, "variables should be empty."); + assert.deepEqual(result.imports, [ + path.join( + "test", "fixtures", "rootPaths", + "lib2", "my", "themes", "bar", "bar.less" + ), + path.join( + "test", "fixtures", "rootPaths", + "lib1", "my", "themes", "foo", "foo.less" + ) + ], "import list should not correctly filled."); + }); + }); }); -describe('libraries (my/ui/lib)', function() { - - it('should create base theme', function() { - - return new Builder().build({ - lessInputPath: 'my/ui/lib/themes/base/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1' - ], - library: { - name: "my.ui.lib" - } - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/libraries/lib1/my/ui/lib/themes/base/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib1/my/ui/lib/themes/base/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, { color1: '#fefefe' }, 'variables should be correctly collected.'); - assert.deepEqual(result.allVariables, { color1: '#fefefe' }, 'allVariables should be correctly collected.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less") - ], 'import list should be correct.'); - - }); - - }); - - it('should create foo theme with scope as defined in .theming file', function() { - - return new Builder().build({ - lessInputPath: 'my/ui/lib/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ], - library: { - name: "my.ui.lib" - } - }).then(function(result) { - - var oVariablesExpected = { - "default" : { - "color1": "#ffffff", - - }, - "scopes": { - "fooContrast": { - "color1": "#000000" - } - } - } - - assert.equal(result.css, readFile('test/expected/libraries/lib1/my/ui/lib/themes/foo/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib1/my/ui/lib/themes/foo/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, oVariablesExpected, 'variables should be correctly collected.'); - assert.deepEqual(result.allVariables, oVariablesExpected, 'allVariables should be correctly collected.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), - path.join("test", "fixtures", "libraries", "lib1", "sap", "ui", "core", "themes", "foo", ".theming") - ], 'import list should be correct.'); - - }); - - }); - - it('should create bar theme with scope as defined in .theming file', function() { - - return new Builder().build({ - lessInputPath: 'my/ui/lib/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ], - library: { - name: "my.ui.lib" - } - }).then(function(result) { - - var oVariablesExpected = { - "default" : { - "color1": "#ffffff", - }, - "scopes": { - "barContrast": { - "color1": "#000000" - } - } - } - - assert.equal(result.css, readFile('test/expected/libraries/lib2/my/ui/lib/themes/bar/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib2/my/ui/lib/themes/bar/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, oVariablesExpected, 'variables should be correctly collected.'); - assert.deepEqual(result.allVariables, oVariablesExpected, 'allVariables should be correctly collected.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), - path.join("test", "fixtures", "libraries", "lib2", "sap", "ui", "core", "themes", "bar", ".theming") - ], 'import list should be correct.'); - - }); - - }); - +describe("libraries (my/ui/lib)", function() { + it("should create base theme", function() { + return new Builder().build({ + lessInputPath: "my/ui/lib/themes/base/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1" + ], + library: { + name: "my.ui.lib" + } + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/lib1/my/ui/lib/themes/base/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib1/my/ui/lib/themes/base/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, {color1: "#fefefe"}, "variables should be correctly collected."); + assert.deepEqual(result.allVariables, {color1: "#fefefe"}, "allVariables should be correctly collected."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less") + ], "import list should be correct."); + }); + }); + + it("should create foo theme with scope as defined in .theming file", function() { + return new Builder().build({ + lessInputPath: "my/ui/lib/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ], + library: { + name: "my.ui.lib" + } + }).then(function(result) { + let oVariablesExpected = { + "default": { + "color1": "#ffffff", + + }, + "scopes": { + "fooContrast": { + "color1": "#000000" + } + } + }; + + assert.equal(result.css, readFile("test/expected/libraries/lib1/my/ui/lib/themes/foo/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib1/my/ui/lib/themes/foo/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, oVariablesExpected, "variables should be correctly collected."); + assert.deepEqual(result.allVariables, oVariablesExpected, "allVariables should be correctly collected."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), + path.join("test", "fixtures", "libraries", "lib1", "sap", "ui", "core", "themes", "foo", ".theming") + ], "import list should be correct."); + }); + }); + + it("should create bar theme with scope as defined in .theming file", function() { + return new Builder().build({ + lessInputPath: "my/ui/lib/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ], + library: { + name: "my.ui.lib" + } + }).then(function(result) { + let oVariablesExpected = { + "default": { + "color1": "#ffffff", + }, + "scopes": { + "barContrast": { + "color1": "#000000" + } + } + }; + + assert.equal(result.css, readFile("test/expected/libraries/lib2/my/ui/lib/themes/bar/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib2/my/ui/lib/themes/bar/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, oVariablesExpected, "variables should be correctly collected."); + assert.deepEqual(result.allVariables, oVariablesExpected, "allVariables should be correctly collected."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), + path.join("test", "fixtures", "libraries", "lib2", "sap", "ui", "core", "themes", "bar", ".theming") + ], "import list should be correct."); + }); + }); }); -describe('libraries (my/other/ui/lib)', function() { - - it('should create base theme', function() { - - return new Builder().build({ - lessInputPath: 'my/other/ui/lib/themes/base/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib3' - ], - library: { - name: "my.other.ui.lib" - } - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/libraries/lib3/my/other/ui/lib/themes/base/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib3/my/other/ui/lib/themes/base/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.variables, { "_my_other_ui_lib_MyControl_color1": "#fefefe" }, 'variables should be correctly collected.'); - assert.deepEqual(result.allVariables, { - "_my_other_ui_lib_MyControl_color1": "#fefefe", - "color1": "#fefefe" - }, 'allVariables should be correctly collected.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "MyControl.less") - ], 'import list should be correct.'); - - }); - - }); - - it('should create foo theme with scope as defined in .theming file', function() { - - return new Builder().build({ - lessInputPath: 'my/other/ui/lib/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2', - 'test/fixtures/libraries/lib3' - ], - library: { - name: "my.other.ui.lib" - } - }).then(function(result) { - - var oVariablesExpected = { - "default" : { - "_my_other_ui_lib_MyControl_color1": "#ffffff", - "_my_other_ui_lib_MyControl_color2": "#008000" - }, - "scopes": { - "fooContrast": { - "_my_other_ui_lib_MyControl_color1": "#000000" - } - } - }; - var oAllVariablesExpected = { - "default" : { - "_my_other_ui_lib_MyControl_color1": "#ffffff", - "_my_other_ui_lib_MyControl_color2": "#008000", - "color1": "#ffffff" - }, - "scopes": { - "fooContrast": { - "_my_other_ui_lib_MyControl_color1": "#000000", - "color1": "#000000" - } - } - }; - - assert.deepEqual(result.variables, oVariablesExpected, 'variables should be correctly collected.'); - assert.deepEqual(result.allVariables, oAllVariablesExpected, 'allVariables should be correctly collected.'); - assert.equal(result.css, readFile('test/expected/libraries/lib3/my/other/ui/lib/themes/foo/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib3/my/other/ui/lib/themes/foo/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "MyControl.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "MyControl.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "bar", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), - path.join("test", "fixtures", "libraries", "lib1", "sap", "ui", "core", "themes", "foo", ".theming") - ], 'import list should be correct.'); - - }); - - }); - - it('should create bar theme with scope as defined in .theming file', function() { - - return new Builder().build({ - lessInputPath: 'my/other/ui/lib/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2', - 'test/fixtures/libraries/lib3' - ], - library: { - name: "my.other.ui.lib" - } - }).then(function(result) { - - var oVariablesExpected = { - "default" : { - "_my_other_ui_lib_MyControl_color1": "#ffffff", - "_my_other_ui_lib_MyControl_color2": "#008000" - }, - "scopes": { - "barContrast": { - "_my_other_ui_lib_MyControl_color1": "#000000" - } - } - }; - var oAllVariablesExpected = { - "default" : { - "_my_other_ui_lib_MyControl_color1": "#ffffff", - "_my_other_ui_lib_MyControl_color2": "#008000", - "color1": "#ffffff" - }, - "scopes": { - "barContrast": { - "_my_other_ui_lib_MyControl_color1": "#000000", - "color1": "#000000" - } - } - }; - - assert.deepEqual(result.variables, oVariablesExpected, 'variables should be correctly collected.'); - assert.deepEqual(result.allVariables, oAllVariablesExpected, 'allVariables should be correctly collected.'); - assert.equal(result.css, readFile('test/expected/libraries/lib3/my/other/ui/lib/themes/bar/library.css'), 'css should be correctly generated.'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/lib3/my/other/ui/lib/themes/bar/library-RTL.css'), 'rtl css should be correctly generated.'); - assert.deepEqual(result.imports, [ - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "bar", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "library.source.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "MyControl.less"), - path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), - path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "MyControl.less"), - path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), - path.join("test", "fixtures", "libraries", "lib2", "sap", "ui", "core", "themes", "bar", ".theming") - ], 'import list should be correct.'); - - }); - - }); - +describe("libraries (my/other/ui/lib)", function() { + it("should create base theme", function() { + return new Builder().build({ + lessInputPath: "my/other/ui/lib/themes/base/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib3" + ], + library: { + name: "my.other.ui.lib" + } + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/lib3/my/other/ui/lib/themes/base/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib3/my/other/ui/lib/themes/base/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.variables, {"_my_other_ui_lib_MyControl_color1": "#fefefe"}, "variables should be correctly collected."); + assert.deepEqual(result.allVariables, { + "_my_other_ui_lib_MyControl_color1": "#fefefe", + "color1": "#fefefe" + }, "allVariables should be correctly collected."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "MyControl.less") + ], "import list should be correct."); + }); + }); + + it("should create foo theme with scope as defined in .theming file", function() { + return new Builder().build({ + lessInputPath: "my/other/ui/lib/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2", + "test/fixtures/libraries/lib3" + ], + library: { + name: "my.other.ui.lib" + } + }).then(function(result) { + let oVariablesExpected = { + "default": { + "_my_other_ui_lib_MyControl_color1": "#ffffff", + "_my_other_ui_lib_MyControl_color2": "#008000" + }, + "scopes": { + "fooContrast": { + "_my_other_ui_lib_MyControl_color1": "#000000" + } + } + }; + let oAllVariablesExpected = { + "default": { + "_my_other_ui_lib_MyControl_color1": "#ffffff", + "_my_other_ui_lib_MyControl_color2": "#008000", + "color1": "#ffffff" + }, + "scopes": { + "fooContrast": { + "_my_other_ui_lib_MyControl_color1": "#000000", + "color1": "#000000" + } + } + }; + + assert.deepEqual(result.variables, oVariablesExpected, "variables should be correctly collected."); + assert.deepEqual(result.allVariables, oAllVariablesExpected, "allVariables should be correctly collected."); + assert.equal(result.css, readFile("test/expected/libraries/lib3/my/other/ui/lib/themes/foo/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib3/my/other/ui/lib/themes/foo/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "MyControl.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "MyControl.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "bar", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), + path.join("test", "fixtures", "libraries", "lib1", "sap", "ui", "core", "themes", "foo", ".theming") + ], "import list should be correct."); + }); + }); + + it("should create bar theme with scope as defined in .theming file", function() { + return new Builder().build({ + lessInputPath: "my/other/ui/lib/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2", + "test/fixtures/libraries/lib3" + ], + library: { + name: "my.other.ui.lib" + } + }).then(function(result) { + let oVariablesExpected = { + "default": { + "_my_other_ui_lib_MyControl_color1": "#ffffff", + "_my_other_ui_lib_MyControl_color2": "#008000" + }, + "scopes": { + "barContrast": { + "_my_other_ui_lib_MyControl_color1": "#000000" + } + } + }; + let oAllVariablesExpected = { + "default": { + "_my_other_ui_lib_MyControl_color1": "#ffffff", + "_my_other_ui_lib_MyControl_color2": "#008000", + "color1": "#ffffff" + }, + "scopes": { + "barContrast": { + "_my_other_ui_lib_MyControl_color1": "#000000", + "color1": "#000000" + } + } + }; + + assert.deepEqual(result.variables, oVariablesExpected, "variables should be correctly collected."); + assert.deepEqual(result.allVariables, oAllVariablesExpected, "allVariables should be correctly collected."); + assert.equal(result.css, readFile("test/expected/libraries/lib3/my/other/ui/lib/themes/bar/library.css"), "css should be correctly generated."); + assert.equal(result.cssRtl, readFile("test/expected/libraries/lib3/my/other/ui/lib/themes/bar/library-RTL.css"), "rtl css should be correctly generated."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "bar", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "library.source.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "base", "global.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "base", "MyControl.less"), + path.join("test", "fixtures", "libraries", "lib1", "my", "ui", "lib", "themes", "foo", "global.less"), + path.join("test", "fixtures", "libraries", "lib3", "my", "other", "ui", "lib", "themes", "foo", "MyControl.less"), + path.join("test", "fixtures", "libraries", "lib2", "my", "ui", "lib", "themes", "bar", "global.less"), + path.join("test", "fixtures", "libraries", "lib2", "sap", "ui", "core", "themes", "bar", ".theming") + ], "import list should be correct."); + }); + }); }); -describe('error handling', function() { - - it('should have correct error in case of undefined variable usage (lessInput)', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/error/undefined-var.less') - }).then(function(result) { - // no resolve - assert.ok(false); - - }, function(err) { - - assert.ok(err); - - }); - - }); - - it('should have correct error in case of undefined variable usage (lessInputPath)', function() { - - return new Builder().build({ - lessInputPath: 'main.less', - rootPaths: ['test/fixtures/error'] - }).then(function(result) { - // no resolve - assert.ok(false); - - }, function(err) { - - assert.ok(err); - - }); - - }); - +describe("error handling", function() { + it("should have correct error in case of undefined variable usage (lessInput)", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/error/undefined-var.less") + }).then(function(result) { + // no resolve + assert.ok(false); + }, function(err) { + assert.ok(err); + }); + }); + + it("should have correct error in case of undefined variable usage (lessInputPath)", function() { + return new Builder().build({ + lessInputPath: "main.less", + rootPaths: ["test/fixtures/error"] + }).then(function(result) { + // no resolve + assert.ok(false); + }, function(err) { + assert.ok(err); + }); + }); }); function assertLessToRtlCssEqual(filename) { - var lessFilename = 'test/fixtures/rtl/' + filename + '.less'; - var cssFilename = 'test/expected/rtl/' + filename + '.css'; - - return new Builder().build({ - lessInput: readFile(lessFilename), - parser: { - filename: filename + '.less', - paths: 'test/fixtures/rtl' - } - }).then(function(result) { - assert.equal(result.cssRtl, readFile(cssFilename), 'rtl css should not be generated.'); - }); + let lessFilename = "test/fixtures/rtl/" + filename + ".less"; + let cssFilename = "test/expected/rtl/" + filename + ".css"; + + return new Builder().build({ + lessInput: readFile(lessFilename), + parser: { + filename: filename + ".less", + paths: "test/fixtures/rtl" + } + }).then(function(result) { + assert.equal(result.cssRtl, readFile(cssFilename), "rtl css should not be generated."); + }); } -describe('rtl', function() { - - it('background-position', function() { - return assertLessToRtlCssEqual('background-position'); - }); - - it('background', function() { - return assertLessToRtlCssEqual('background'); - }); +describe("rtl", function() { + it("background-position", function() { + return assertLessToRtlCssEqual("background-position"); + }); - it('border', function() { - return assertLessToRtlCssEqual('border'); - }); + it("background", function() { + return assertLessToRtlCssEqual("background"); + }); - it('cursor', function() { - return assertLessToRtlCssEqual('cursor'); - }); + it("border", function() { + return assertLessToRtlCssEqual("border"); + }); - it('gradient', function() { - return assertLessToRtlCssEqual('gradient'); - }); + it("cursor", function() { + return assertLessToRtlCssEqual("cursor"); + }); - it('image-url', function() { - return assertLessToRtlCssEqual('image-url'); - }); + it("gradient", function() { + return assertLessToRtlCssEqual("gradient"); + }); - it('misc', function() { - return assertLessToRtlCssEqual('misc'); - }); + it("image-url", function() { + return assertLessToRtlCssEqual("image-url"); + }); - it('shadow', function() { - return assertLessToRtlCssEqual('shadow'); - }); + it("misc", function() { + return assertLessToRtlCssEqual("misc"); + }); - it('transform', function() { - return assertLessToRtlCssEqual('transform'); - }); + it("shadow", function() { + return assertLessToRtlCssEqual("shadow"); + }); - it('variables', function() { - return assertLessToRtlCssEqual('variables'); - }); + it("transform", function() { + return assertLessToRtlCssEqual("transform"); + }); + it("variables", function() { + return assertLessToRtlCssEqual("variables"); + }); }); -describe('variables', function() { - - it('should return only globally defined variables', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/variables/main.less') - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/variables/main.css'), 'css should be correctly generated.'); - assert.deepEqual(result.variables, JSON.parse(readFile('test/expected/variables/variables.json')), 'variables should be correctly collected.'); - assert.deepEqual(result.imports, [], 'import list should be empty.'); - - }); - - }); - +describe("variables", function() { + it("should return only globally defined variables", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/variables/main.less") + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/variables/main.css"), "css should be correctly generated."); + assert.deepEqual(result.variables, JSON.parse(readFile("test/expected/variables/variables.json")), "variables should be correctly collected."); + assert.deepEqual(result.imports, [], "import list should be empty."); + }); + }); }); -describe('imports', function() { - - it('should return imported file paths', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/imports/main.less'), - parser: { - filename: 'main.less', - paths: [ 'test/fixtures/imports' ] - } - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/imports/main.css'), 'css should be correctly generated.'); - assert.deepEqual(result.variables, {}, 'variables should be empty.'); - assert.deepEqual(result.imports, [ - path.join('test', 'fixtures', 'imports', 'dir1', 'foo.less'), - path.join('test', 'fixtures', 'imports', 'dir2', 'bar.less'), - path.join('test', 'fixtures', 'imports', 'dir3', 'inline.css') - ], 'import list should be correctly filled.'); - - }); - - }); - - it('should use "relativeUrls" parser option by default', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/imports/main.less'), - parser: { - filename: 'main.less', - paths: [ 'test/fixtures/imports' ] - } - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/imports/main.css'), 'css should be correctly generated.'); - - }); - - }); - - it('should not rewrite urls when "relativeUrls" parser option is set to "false"', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/imports/main.less'), - parser: { - filename: 'main.less', - paths: [ 'test/fixtures/imports' ], - relativeUrls: false - } - }).then(function(result) { - - assert.equal(result.css, readFile('test/expected/imports/main-no-relativeUrls.css'), 'css should be correctly generated.'); - - }); - - }); - +describe("imports", function() { + it("should return imported file paths", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/imports/main.less"), + parser: { + filename: "main.less", + paths: ["test/fixtures/imports"] + } + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/imports/main.css"), "css should be correctly generated."); + assert.deepEqual(result.variables, {}, "variables should be empty."); + assert.deepEqual(result.imports, [ + path.join("test", "fixtures", "imports", "dir1", "foo.less"), + path.join("test", "fixtures", "imports", "dir2", "bar.less"), + path.join("test", "fixtures", "imports", "dir3", "inline.css") + ], "import list should be correctly filled."); + }); + }); + + it("should use \"relativeUrls\" parser option by default", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/imports/main.less"), + parser: { + filename: "main.less", + paths: ["test/fixtures/imports"] + } + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/imports/main.css"), "css should be correctly generated."); + }); + }); + + it("should not rewrite urls when \"relativeUrls\" parser option is set to \"false\"", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/imports/main.less"), + parser: { + filename: "main.less", + paths: ["test/fixtures/imports"], + relativeUrls: false + } + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/imports/main-no-relativeUrls.css"), "css should be correctly generated."); + }); + }); }); -describe('inline theming parameters', function() { - - it('should not include inline parameters when no library name is given', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/simple/test.less') - }).then(function(result) { - - assert.ok(!/#sap-ui-theme-/.test(result.css), 'inline parameter rule should not be present.'); - assert.ok(!/data:text\/plain/.test(result.css), 'data-uri should not be present.'); - - assert.equal(result.css, readFile('test/expected/simple/test.css'), 'css should be correctly generated.'); - - }); - - }); - - it('should include inline parameters when library name is given', function() { - - return new Builder().build({ - lessInput: readFile('test/fixtures/simple/test.less'), - library: { - name: 'foo.bar' - } - }).then(function(result) { - - assert.ok(/#sap-ui-theme-foo\\.bar/.test(result.css), 'inline parameter rule for library should be present.'); - assert.ok(/data:text\/plain/.test(result.css), 'data-uri should be present.'); - - assert.equal(result.css, readFile('test/expected/simple/test-inline-parameters.css'), 'css should be correctly generated.'); - - }); - - }); - +describe("inline theming parameters", function() { + it("should not include inline parameters when no library name is given", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/simple/test.less") + }).then(function(result) { + assert.ok(!/#sap-ui-theme-/.test(result.css), "inline parameter rule should not be present."); + assert.ok(!/data:text\/plain/.test(result.css), "data-uri should not be present."); + + assert.equal(result.css, readFile("test/expected/simple/test.css"), "css should be correctly generated."); + }); + }); + + it("should include inline parameters when library name is given", function() { + return new Builder().build({ + lessInput: readFile("test/fixtures/simple/test.less"), + library: { + name: "foo.bar" + } + }).then(function(result) { + assert.ok(/#sap-ui-theme-foo\\.bar/.test(result.css), "inline parameter rule for library should be present."); + assert.ok(/data:text\/plain/.test(result.css), "data-uri should be present."); + + assert.equal(result.css, readFile("test/expected/simple/test-inline-parameters.css"), "css should be correctly generated."); + }); + }); }); -describe('theme caching', function() { - - it('should cache the theme', function() { - - var lessOptions = { - lessInputPath: 'my/ui/lib/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ], - library: { - name: "my.ui.lib" - } - }; +describe("theme caching", function() { + it("should cache the theme", function() { + let lessOptions = { + lessInputPath: "my/ui/lib/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ], + library: { + name: "my.ui.lib" + } + }; - var builder = new Builder(); + let builder = new Builder(); - return builder.build(lessOptions).then(function(res) { + return builder.build(lessOptions).then(function(res) { + let cacheFirstRun = clone(builder.themeCacheMapping); - var cacheFirstRun = clone(builder.themeCacheMapping); + assert.notDeepEqual(cacheFirstRun, {}, "themeCache should not be empty."); - assert.notDeepEqual(cacheFirstRun, {}, 'themeCache should not be empty.'); + // second run + return builder.build(lessOptions).then(function(result) { + let cacheSecondRun = clone(builder.themeCacheMapping); - // second run - return builder.build(lessOptions).then(function(result) { + assert.deepEqual(res, result, "callback result should be the same"); - var cacheSecondRun = clone(builder.themeCacheMapping); + assert.notDeepEqual(cacheSecondRun, {}, "themeCache should not be empty."); - assert.deepEqual(res, result, "callback result should be the same"); + assert.deepEqual(cacheFirstRun, cacheSecondRun, "cache should be equal after second build run."); + }); + }); + }); - assert.notDeepEqual(cacheSecondRun, {}, 'themeCache should not be empty.'); + it("should recompile the theme after clearing the cache", function() { + let lessOptions = { + lessInputPath: "my/ui/lib/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ], + library: { + name: "my.ui.lib" + } + }; - assert.deepEqual(cacheFirstRun, cacheSecondRun, 'cache should be equal after second build run.') + let builder = new Builder(); - }); + return builder.build(lessOptions).then(function(res) { + let cacheFirstRun = clone(builder.themeCacheMapping); - }); + assert.notDeepEqual(cacheFirstRun, {}, "themeCache should not be empty."); - }); + builder.clearCache(); - it('should recompile the theme after clearing the cache', function() { + assert.deepEqual(builder.themeCacheMapping, {}, "themeCache should be empty."); - var lessOptions = { - lessInputPath: 'my/ui/lib/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ], - library: { - name: "my.ui.lib" - } - }; + // second run + return builder.build(lessOptions).then(function(result) { + let cacheSecondRun = clone(builder.themeCacheMapping); - var builder = new Builder(); + assert.equal(JSON.stringify(res, null, 4), JSON.stringify(result, null, 4), "callback result should be the same"); - return builder.build(lessOptions).then(function(res) { - - var cacheFirstRun = clone(builder.themeCacheMapping); - - assert.notDeepEqual(cacheFirstRun, {}, 'themeCache should not be empty.'); - - builder.clearCache(); - - assert.deepEqual(builder.themeCacheMapping, {}, 'themeCache should be empty.'); - - // second run - return builder.build(lessOptions).then(function(result) { - - var cacheSecondRun = clone(builder.themeCacheMapping); - - assert.equal(JSON.stringify(res, null, 4), JSON.stringify(result, null, 4), "callback result should be the same"); - - assert.notDeepEqual(cacheSecondRun, {}, 'themeCache should not be empty.'); - - }); - - }); - - }); + assert.notDeepEqual(cacheSecondRun, {}, "themeCache should not be empty."); + }); + }); + }); }); -describe('CSS Scoping (via .theming file) of', function() { - - describe('comments', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'comments/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/comments/lib1', - 'test/fixtures/libraries/scopes/comments/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'comments/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/comments/lib1', - 'test/fixtures/libraries/scopes/comments/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('css-scope-root', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'css-scope-root/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/css-scope-root/lib1', - 'test/fixtures/libraries/scopes/css-scope-root/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'css-scope-root/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/css-scope-root/lib1', - 'test/fixtures/libraries/scopes/css-scope-root/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('default', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'default/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/default/lib1', - 'test/fixtures/libraries/scopes/default/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/default/lib1/default/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/default/lib1/default/themes/foo/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'default/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/default/lib1', - 'test/fixtures/libraries/scopes/default/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/default/lib2/default/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/default/lib2/default/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - }); - - - describe('dom', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'dom/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/dom/lib1', - 'test/fixtures/libraries/scopes/dom/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'dom/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/dom/lib1', - 'test/fixtures/libraries/scopes/dom/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('empty media queries', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'empty-media-queries/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/empty-media-queries/lib1', - 'test/fixtures/libraries/scopes/empty-media-queries/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'empty-media-queries/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/empty-media-queries/lib1', - 'test/fixtures/libraries/scopes/empty-media-queries/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('HTML', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'html/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/html/lib1', - 'test/fixtures/libraries/scopes/html/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'html/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/html/lib1', - 'test/fixtures/libraries/scopes/html/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/html/lib2/html/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/html/lib2/html/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - - describe('media-queries', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'media-queries/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/media-queries/lib1', - 'test/fixtures/libraries/scopes/media-queries/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'media-queries/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/media-queries/lib1', - 'test/fixtures/libraries/scopes/media-queries/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('mixins', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'mixins/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/mixins/lib1', - 'test/fixtures/libraries/scopes/mixins/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'mixins/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/mixins/lib1', - 'test/fixtures/libraries/scopes/mixins/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('multiple imports', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - lessInputPath: 'multiple-imports/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/multiple-imports/lib1', - 'test/fixtures/libraries/scopes/multiple-imports/lib2', - 'test/fixtures/libraries/lib1' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - lessInputPath: 'multiple-imports/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/multiple-imports/lib1', - 'test/fixtures/libraries/scopes/multiple-imports/lib2', - 'test/fixtures/libraries/lib1', - 'test/fixtures/libraries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); +describe("CSS Scoping (via .theming file) of", function() { + describe("comments", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "comments/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/comments/lib1", + "test/fixtures/libraries/scopes/comments/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "comments/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/comments/lib1", + "test/fixtures/libraries/scopes/comments/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + }); + + describe("css-scope-root", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "css-scope-root/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/css-scope-root/lib1", + "test/fixtures/libraries/scopes/css-scope-root/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "css-scope-root/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/css-scope-root/lib1", + "test/fixtures/libraries/scopes/css-scope-root/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + }); + + describe("default", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "default/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/default/lib1", + "test/fixtures/libraries/scopes/default/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/default/lib1/default/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/default/lib1/default/themes/foo/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "default/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/default/lib1", + "test/fixtures/libraries/scopes/default/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/default/lib2/default/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/default/lib2/default/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + }); + + + describe("dom", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "dom/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/dom/lib1", + "test/fixtures/libraries/scopes/dom/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "dom/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/dom/lib1", + "test/fixtures/libraries/scopes/dom/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("empty media queries", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "empty-media-queries/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/empty-media-queries/lib1", + "test/fixtures/libraries/scopes/empty-media-queries/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "empty-media-queries/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/empty-media-queries/lib1", + "test/fixtures/libraries/scopes/empty-media-queries/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("HTML", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "html/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/html/lib1", + "test/fixtures/libraries/scopes/html/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "html/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/html/lib1", + "test/fixtures/libraries/scopes/html/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/html/lib2/html/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/html/lib2/html/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + + describe("media-queries", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "media-queries/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/media-queries/lib1", + "test/fixtures/libraries/scopes/media-queries/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "media-queries/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/media-queries/lib1", + "test/fixtures/libraries/scopes/media-queries/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("mixins", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "mixins/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/mixins/lib1", + "test/fixtures/libraries/scopes/mixins/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "mixins/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/mixins/lib1", + "test/fixtures/libraries/scopes/mixins/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("multiple imports", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + lessInputPath: "multiple-imports/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/multiple-imports/lib1", + "test/fixtures/libraries/scopes/multiple-imports/lib2", + "test/fixtures/libraries/lib1" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + lessInputPath: "multiple-imports/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/multiple-imports/lib1", + "test/fixtures/libraries/scopes/multiple-imports/lib2", + "test/fixtures/libraries/lib1", + "test/fixtures/libraries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); }); -describe('CSS Scoping (via option) of', function() { - - describe('comments', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'comments/themes/bar/library.source.less', - embeddedCompareFilePath: 'comments/themes/foo/library.source.less', - baseFilePath: 'comments/themes/foo/library.source.less' - }, - lessInputPath: 'comments/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/comments/lib1', - 'test/fixtures/libraries/scopes/comments/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'comments/themes/bar/library.source.less', - embeddedCompareFilePath: 'comments/themes/foo/library.source.less', - baseFilePath: 'comments/themes/foo/library.source.less' - }, - lessInputPath: 'comments/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/comments/lib1', - 'test/fixtures/libraries/scopes/comments/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('css-scope-root', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'css-scope-root/themes/bar/library.source.less', - embeddedCompareFilePath: 'css-scope-root/themes/foo/library.source.less', - baseFilePath: 'css-scope-root/themes/foo/library.source.less' - }, - lessInputPath: 'css-scope-root/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/css-scope-root/lib1', - 'test/fixtures/libraries/scopes/css-scope-root/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'css-scope-root/themes/bar/library.source.less', - embeddedCompareFilePath: 'css-scope-root/themes/foo/library.source.less', - baseFilePath: 'css-scope-root/themes/foo/library.source.less' - }, - lessInputPath: 'css-scope-root/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/css-scope-root/lib1', - 'test/fixtures/libraries/scopes/css-scope-root/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('default', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'default/themes/bar/library.source.less', - embeddedCompareFilePath: 'default/themes/foo/library.source.less', - baseFilePath: 'default/themes/foo/library.source.less' - }, - lessInputPath: 'default/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/default/lib1', - 'test/fixtures/libraries/scopes/default/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/default/lib1/default/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/default/lib1/default/themes/foo/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'default/themes/bar/library.source.less', - embeddedCompareFilePath: 'default/themes/foo/library.source.less', - baseFilePath: 'default/themes/foo/library.source.less' - }, - lessInputPath: 'default/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/default/lib1', - 'test/fixtures/libraries/scopes/default/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/default/lib2/default/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/default/lib2/default/themes/bar/library-RTL.css'), 'Rtl CSS scoping should be correctly generated'); - }); - - }); - - }); - - - describe('dom', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'dom/themes/bar/library.source.less', - embeddedCompareFilePath: 'dom/themes/foo/library.source.less', - baseFilePath: 'dom/themes/foo/library.source.less' - }, - lessInputPath: 'dom/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/dom/lib1', - 'test/fixtures/libraries/scopes/dom/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'dom/themes/bar/library.source.less', - embeddedCompareFilePath: 'dom/themes/foo/library.source.less', - baseFilePath: 'dom/themes/foo/library.source.less' - }, - lessInputPath: 'dom/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/dom/lib1', - 'test/fixtures/libraries/scopes/dom/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('empty media queries', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'empty-media-queries/themes/bar/library.source.less', - embeddedCompareFilePath: 'empty-media-queries/themes/foo/library.source.less', - baseFilePath: 'empty-media-queries/themes/foo/library.source.less' - }, - lessInputPath: 'empty-media-queries/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/empty-media-queries/lib1', - 'test/fixtures/libraries/scopes/empty-media-queries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'empty-media-queries/themes/bar/library.source.less', - embeddedCompareFilePath: 'empty-media-queries/themes/foo/library.source.less', - baseFilePath: 'empty-media-queries/themes/foo/library.source.less' - }, - lessInputPath: 'empty-media-queries/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/empty-media-queries/lib1', - 'test/fixtures/libraries/scopes/empty-media-queries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('HTML', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'html/themes/bar/library.source.less', - embeddedCompareFilePath: 'html/themes/foo/library.source.less', - baseFilePath: 'html/themes/foo/library.source.less' - }, - lessInputPath: 'html/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/html/lib1', - 'test/fixtures/libraries/scopes/html/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'html/themes/bar/library.source.less', - embeddedCompareFilePath: 'html/themes/foo/library.source.less', - baseFilePath: 'html/themes/foo/library.source.less' - }, - lessInputPath: 'html/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/html/lib1', - 'test/fixtures/libraries/scopes/html/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/html/lib2/html/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/html/lib2/html/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - - describe('media-queries', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'media-queries/themes/bar/library.source.less', - embeddedCompareFilePath: 'media-queries/themes/foo/library.source.less', - baseFilePath: 'media-queries/themes/foo/library.source.less' - }, - lessInputPath: 'media-queries/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/media-queries/lib1', - 'test/fixtures/libraries/scopes/media-queries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'media-queries/themes/bar/library.source.less', - embeddedCompareFilePath: 'media-queries/themes/foo/library.source.less', - baseFilePath: 'media-queries/themes/foo/library.source.less' - }, - lessInputPath: 'media-queries/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/media-queries/lib1', - 'test/fixtures/libraries/scopes/media-queries/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('mixins', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'mixins/themes/bar/library.source.less', - embeddedCompareFilePath: 'mixins/themes/foo/library.source.less', - baseFilePath: 'mixins/themes/foo/library.source.less' - }, - lessInputPath: 'mixins/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/mixins/lib1', - 'test/fixtures/libraries/scopes/mixins/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'mixins/themes/bar/library.source.less', - embeddedCompareFilePath: 'mixins/themes/foo/library.source.less', - baseFilePath: 'mixins/themes/foo/library.source.less' - }, - lessInputPath: 'mixins/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/mixins/lib1', - 'test/fixtures/libraries/scopes/mixins/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); - - describe('multiple imports', function() { - - it('should return same CSS for foo', function() { - - return new Builder().build({ - scope: { - selector: 'fooContrast', - embeddedFilePath: 'multiple-imports/themes/bar/library.source.less', - embeddedCompareFilePath: 'multiple-imports/themes/foo/library.source.less', - baseFilePath: 'multiple-imports/themes/foo/library.source.less' - }, - lessInputPath: 'multiple-imports/themes/foo/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/multiple-imports/lib1', - 'test/fixtures/libraries/scopes/multiple-imports/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - it('should return same CSS for bar', function() { - - return new Builder().build({ - scope: { - selector: 'barContrast', - embeddedFilePath: 'multiple-imports/themes/bar/library.source.less', - embeddedCompareFilePath: 'multiple-imports/themes/foo/library.source.less', - baseFilePath: 'multiple-imports/themes/foo/library.source.less' - }, - lessInputPath: 'multiple-imports/themes/bar/library.source.less', - rootPaths: [ - 'test/fixtures/libraries/scopes/multiple-imports/lib1', - 'test/fixtures/libraries/scopes/multiple-imports/lib2' - ] - }).then(function(result) { - assert.equal(result.css, readFile('test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library.css'), 'CSS scoping should be correctly generated'); - assert.equal(result.cssRtl, readFile('test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library-RTL.css'), 'CSS scoping should be correctly generated'); - }); - - }); - - }); +describe("CSS Scoping (via option) of", function() { + describe("comments", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "comments/themes/bar/library.source.less", + embeddedCompareFilePath: "comments/themes/foo/library.source.less", + baseFilePath: "comments/themes/foo/library.source.less" + }, + lessInputPath: "comments/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/comments/lib1", + "test/fixtures/libraries/scopes/comments/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/comments/lib1/comments/themes/foo/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "comments/themes/bar/library.source.less", + embeddedCompareFilePath: "comments/themes/foo/library.source.less", + baseFilePath: "comments/themes/foo/library.source.less" + }, + lessInputPath: "comments/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/comments/lib1", + "test/fixtures/libraries/scopes/comments/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/comments/lib2/comments/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + }); + + describe("css-scope-root", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "css-scope-root/themes/bar/library.source.less", + embeddedCompareFilePath: "css-scope-root/themes/foo/library.source.less", + baseFilePath: "css-scope-root/themes/foo/library.source.less" + }, + lessInputPath: "css-scope-root/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/css-scope-root/lib1", + "test/fixtures/libraries/scopes/css-scope-root/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/css-scope-root/lib1/css-scope-root/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "css-scope-root/themes/bar/library.source.less", + embeddedCompareFilePath: "css-scope-root/themes/foo/library.source.less", + baseFilePath: "css-scope-root/themes/foo/library.source.less" + }, + lessInputPath: "css-scope-root/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/css-scope-root/lib1", + "test/fixtures/libraries/scopes/css-scope-root/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/css-scope-root/lib2/css-scope-root/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + }); + + describe("default", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "default/themes/bar/library.source.less", + embeddedCompareFilePath: "default/themes/foo/library.source.less", + baseFilePath: "default/themes/foo/library.source.less" + }, + lessInputPath: "default/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/default/lib1", + "test/fixtures/libraries/scopes/default/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/default/lib1/default/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/default/lib1/default/themes/foo/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "default/themes/bar/library.source.less", + embeddedCompareFilePath: "default/themes/foo/library.source.less", + baseFilePath: "default/themes/foo/library.source.less" + }, + lessInputPath: "default/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/default/lib1", + "test/fixtures/libraries/scopes/default/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/default/lib2/default/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/default/lib2/default/themes/bar/library-RTL.css"), "Rtl CSS scoping should be correctly generated"); + }); + }); + }); + + + describe("dom", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "dom/themes/bar/library.source.less", + embeddedCompareFilePath: "dom/themes/foo/library.source.less", + baseFilePath: "dom/themes/foo/library.source.less" + }, + lessInputPath: "dom/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/dom/lib1", + "test/fixtures/libraries/scopes/dom/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/dom/lib1/dom/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "dom/themes/bar/library.source.less", + embeddedCompareFilePath: "dom/themes/foo/library.source.less", + baseFilePath: "dom/themes/foo/library.source.less" + }, + lessInputPath: "dom/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/dom/lib1", + "test/fixtures/libraries/scopes/dom/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/dom/lib2/dom/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("empty media queries", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "empty-media-queries/themes/bar/library.source.less", + embeddedCompareFilePath: "empty-media-queries/themes/foo/library.source.less", + baseFilePath: "empty-media-queries/themes/foo/library.source.less" + }, + lessInputPath: "empty-media-queries/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/empty-media-queries/lib1", + "test/fixtures/libraries/scopes/empty-media-queries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/empty-media-queries/lib1/empty-media-queries/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "empty-media-queries/themes/bar/library.source.less", + embeddedCompareFilePath: "empty-media-queries/themes/foo/library.source.less", + baseFilePath: "empty-media-queries/themes/foo/library.source.less" + }, + lessInputPath: "empty-media-queries/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/empty-media-queries/lib1", + "test/fixtures/libraries/scopes/empty-media-queries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/empty-media-queries/lib2/empty-media-queries/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("HTML", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "html/themes/bar/library.source.less", + embeddedCompareFilePath: "html/themes/foo/library.source.less", + baseFilePath: "html/themes/foo/library.source.less" + }, + lessInputPath: "html/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/html/lib1", + "test/fixtures/libraries/scopes/html/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/html/lib1/html/themes/foo/library.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "html/themes/bar/library.source.less", + embeddedCompareFilePath: "html/themes/foo/library.source.less", + baseFilePath: "html/themes/foo/library.source.less" + }, + lessInputPath: "html/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/html/lib1", + "test/fixtures/libraries/scopes/html/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/html/lib2/html/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/html/lib2/html/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + + describe("media-queries", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "media-queries/themes/bar/library.source.less", + embeddedCompareFilePath: "media-queries/themes/foo/library.source.less", + baseFilePath: "media-queries/themes/foo/library.source.less" + }, + lessInputPath: "media-queries/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/media-queries/lib1", + "test/fixtures/libraries/scopes/media-queries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/media-queries/lib1/media-queries/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "media-queries/themes/bar/library.source.less", + embeddedCompareFilePath: "media-queries/themes/foo/library.source.less", + baseFilePath: "media-queries/themes/foo/library.source.less" + }, + lessInputPath: "media-queries/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/media-queries/lib1", + "test/fixtures/libraries/scopes/media-queries/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/media-queries/lib2/media-queries/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("mixins", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "mixins/themes/bar/library.source.less", + embeddedCompareFilePath: "mixins/themes/foo/library.source.less", + baseFilePath: "mixins/themes/foo/library.source.less" + }, + lessInputPath: "mixins/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/mixins/lib1", + "test/fixtures/libraries/scopes/mixins/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/mixins/lib1/mixins/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "mixins/themes/bar/library.source.less", + embeddedCompareFilePath: "mixins/themes/foo/library.source.less", + baseFilePath: "mixins/themes/foo/library.source.less" + }, + lessInputPath: "mixins/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/mixins/lib1", + "test/fixtures/libraries/scopes/mixins/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/mixins/lib2/mixins/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); + + describe("multiple imports", function() { + it("should return same CSS for foo", function() { + return new Builder().build({ + scope: { + selector: "fooContrast", + embeddedFilePath: "multiple-imports/themes/bar/library.source.less", + embeddedCompareFilePath: "multiple-imports/themes/foo/library.source.less", + baseFilePath: "multiple-imports/themes/foo/library.source.less" + }, + lessInputPath: "multiple-imports/themes/foo/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/multiple-imports/lib1", + "test/fixtures/libraries/scopes/multiple-imports/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/multiple-imports/lib1/multiple-imports/themes/foo/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + + it("should return same CSS for bar", function() { + return new Builder().build({ + scope: { + selector: "barContrast", + embeddedFilePath: "multiple-imports/themes/bar/library.source.less", + embeddedCompareFilePath: "multiple-imports/themes/foo/library.source.less", + baseFilePath: "multiple-imports/themes/foo/library.source.less" + }, + lessInputPath: "multiple-imports/themes/bar/library.source.less", + rootPaths: [ + "test/fixtures/libraries/scopes/multiple-imports/lib1", + "test/fixtures/libraries/scopes/multiple-imports/lib2" + ] + }).then(function(result) { + assert.equal(result.css, readFile("test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library.css"), "CSS scoping should be correctly generated"); + assert.equal(result.cssRtl, readFile("test/expected/libraries/scopes/multiple-imports/lib2/multiple-imports/themes/bar/library-RTL.css"), "CSS scoping should be correctly generated"); + }); + }); + }); });