[Pkg-javascript-commits] [less.js] 216/285: ie support in the tests

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:55 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit f24db033de298f343e0555324d312a97f4c90bef
Author: Luke Page <luke.a.page at gmail.com>
Date:   Wed Oct 22 12:46:22 2014 +0100

    ie support in the tests
---
 Gruntfile.js                | 39 ++++++++++++++++++++++++++++++++++++---
 lib/less-browser/browser.js | 40 ++++++++++++++++++++--------------------
 test/browser/common.js      | 28 ++++++++++++++++++++++++----
 3 files changed, 80 insertions(+), 27 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 9966c5c..f813067 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -232,16 +232,49 @@ module.exports = function (grunt) {
                     username: "lukeapage",
                     key: "2d7199e2-74da-432f-9449-c8c247babecf",
                     urls: ["post-processor", "global-vars", "modify-vars", "production", "rootpath-relative",
-                           "rootpath", "relative-urls", "browser", "no-js-errors", "errors", "legacy"
+                           "rootpath", "relative-urls", "browser", "no-js-errors", "legacy"
                     ].map(function(testName) {
                         return "http://localhost:8081/tmp/browser/test-runner-" + testName + ".html";
                     }),
                     testname: 'Sauce Unit Test for less.js',
                     browsers: [{
                         browserName: "chrome",
-                        version: '37',
+                        version: '',
                         platform: 'Windows 8'
-                    }]
+                    },
+                    {
+                        browserName: "firefox",
+                        version: '33',
+                        platform: 'Linux'
+                    },
+                    {
+                        browserName: "iPad",
+                        version: '8.0',
+                        platform: 'OS X 10.9',
+                        'device-orientation': 'portrait'
+                    },
+                    {
+                        browserName: "internet explorer",
+                        version: '8',
+                        platform: 'Windows XP'
+                    },
+                    {
+                        browserName: "internet explorer",
+                        version: '9',
+                        platform: 'Windows 7'
+                    },
+                    {
+                        browserName: "internet explorer",
+                        version: '10',
+                        platform: 'Windows 7'
+                    },
+                    {
+                        browserName: "internet explorer",
+                        version: '11',
+                        platform: 'Windows 8.1'
+                    }],
+                    sauceConfig: {'record-video': false, 'record-screenshots': false, 'idle-timeout': 60, 'max-duration': 100},
+                    throttled: 3
                 }
             }
         },
diff --git a/lib/less-browser/browser.js b/lib/less-browser/browser.js
index fdb1d06..41aeb5b 100644
--- a/lib/less-browser/browser.js
+++ b/lib/less-browser/browser.js
@@ -8,47 +8,47 @@ module.exports = {
         var id = 'less:' + (sheet.title || utils.extractId(href));
 
         // If this has already been inserted into the DOM, we may need to replace it
-        var oldCss = document.getElementById(id);
-        var keepOldCss = false;
+        var oldStyleNode = document.getElementById(id);
+        var keepOldStyleNode = false;
 
         // Create a new stylesheet node for insertion or (if necessary) replacement
-        var css = document.createElement('style');
-        css.setAttribute('type', 'text/css');
+        var styleNode = document.createElement('style');
+        styleNode.setAttribute('type', 'text/css');
         if (sheet.media) {
-            css.setAttribute('media', sheet.media);
+            styleNode.setAttribute('media', sheet.media);
         }
-        css.id = id;
+        styleNode.id = id;
 
-        if (!css.styleSheet) {
-            css.appendChild(document.createTextNode(styles));
+        if (!styleNode.styleSheet) {
+            styleNode.appendChild(document.createTextNode(styles));
 
-            // If new contents match contents of oldCss, don't replace oldCss
-            keepOldCss = (oldCss !== null && oldCss.childNodes.length > 0 && css.childNodes.length > 0 &&
-                oldCss.firstChild.nodeValue === css.firstChild.nodeValue);
+            // If new contents match contents of oldStyleNode, don't replace oldStyleNode
+            keepOldStyleNode = (oldStyleNode !== null && oldStyleNode.childNodes.length > 0 && styleNode.childNodes.length > 0 &&
+                oldStyleNode.firstChild.nodeValue === styleNode.firstChild.nodeValue);
         }
 
         var head = document.getElementsByTagName('head')[0];
 
-        // If there is no oldCss, just append; otherwise, only append if we need
-        // to replace oldCss with an updated stylesheet
-        if (oldCss === null || keepOldCss === false) {
+        // If there is no oldStyleNode, just append; otherwise, only append if we need
+        // to replace oldStyleNode with an updated stylesheet
+        if (oldStyleNode === null || keepOldStyleNode === false) {
             var nextEl = sheet && sheet.nextSibling || null;
             if (nextEl) {
-                nextEl.parentNode.insertBefore(css, nextEl);
+                nextEl.parentNode.insertBefore(styleNode, nextEl);
             } else {
-                head.appendChild(css);
+                head.appendChild(styleNode);
             }
         }
-        if (oldCss && keepOldCss === false) {
-            oldCss.parentNode.removeChild(oldCss);
+        if (oldStyleNode && keepOldStyleNode === false) {
+            oldStyleNode.parentNode.removeChild(oldStyleNode);
         }
 
         // For IE.
         // This needs to happen *after* the style element is added to the DOM, otherwise IE 7 and 8 may crash.
         // See http://social.msdn.microsoft.com/Forums/en-US/7e081b65-878a-4c22-8e68-c10d39c2ed32/internet-explorer-crashes-appending-style-element-to-head
-        if (css.styleSheet) {
+        if (styleNode.styleSheet) {
             try {
-                css.styleSheet.cssText = styles;
+                styleNode.styleSheet.cssText = styles;
             } catch (e) {
                 throw new Error("Couldn't reassign styleSheet.cssText.");
             }
diff --git a/test/browser/common.js b/test/browser/common.js
index 50a9c25..0292f62 100644
--- a/test/browser/common.js
+++ b/test/browser/common.js
@@ -43,6 +43,21 @@ var testLessInDocument = function (testFunc) {
     }
 };
 
+var ieFormat = function(text) {
+    var styleNode = document.createElement('style');
+    styleNode.setAttribute('type', 'text/css');
+    var headNode = document.getElementsByTagName('head')[0];
+    headNode.appendChild(styleNode);
+    try {
+        styleNode.styleSheet.cssText = text;
+    } catch (e) {
+        throw new Error("Couldn't reassign styleSheet.cssText.");
+    }
+    var transformedText = styleNode.styleSheet.cssText;
+    headNode.removeChild(styleNode);
+    return transformedText;
+};
+
 var testSheet = function (sheet) {
     it(sheet.id + " should match the expected output", function (done) {
         var lessOutputId = sheet.id.replace("original-", ""),
@@ -56,11 +71,16 @@ var testSheet = function (sheet) {
         less.pageLoadFinished
             .then(function () {
                 lessOutputObj = document.getElementById(lessOutputId);
-                lessOutput = lessOutputObj.innerText || lessOutputObj.innerHTML;
+                var isIE = Boolean(lessOutputObj.styleSheet);
+                lessOutput = isIE ? lessOutputObj.styleSheet.cssText :
+                    (lessOutputObj.innerText || lessOutputObj.innerHTML);
 
                 expectedOutput
                     .then(function (text) {
-                        expect(text).toEqual(lessOutput);
+                        if (isIE) {
+                            text = ieFormat(text);
+                        }
+                        expect(lessOutput).toEqual(text);
                         done();
                     });
             });
@@ -116,7 +136,7 @@ var testErrorSheet = function (sheet) {
                             .replace("{pathrel}", "")
                             .replace("{pathhref}", "http://localhost:8081/test/less/errors/")
                             .replace("{404status}", " (404)");
-                        expect(errorTxt).toEqual(actualErrorMsg);
+                        expect(actualErrorMsg).toEqual(errorTxt);
                         if (errorTxt == actualErrorMsg) {
                             actualErrorElement.style.display = "none";
                         }
@@ -148,7 +168,7 @@ var testErrorSheetConsole = function (sheet) {
                     .replace("{pathhref}", "http://localhost:8081/browser/less/")
                     .replace("{404status}", " (404)")
                     .trim();
-                expect(errorTxt).toEqual(actualErrorMsg);
+                expect(actualErrorMsg).toEqual(errorTxt);
                 done();
             });
     });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list