Permalink
Browse files

Add browser specific url tests

  • Loading branch information...
1 parent 6554117 commit c35b6d733e048a3344ce95f5f225ee815a12f014 @lukeapage lukeapage committed Dec 16, 2012
View
@@ -4,4 +4,4 @@ node_modules
*~
.#*
test/browser/less.js
-test/browser/test-runner-main.htm
+test/browser/test-runner-*.htm
@@ -1,19 +1,25 @@
var path = require('path'),
fs = require('fs'),
- sys = require('util'),
- output = '<html><head>\n';
-
-fs.readdirSync(path.join('test/less/', '')).forEach(function (file) {
- if (! /\.less/.test(file)) { return; }
-
- var name = path.basename(file, '.less');
-
- if (name === "javascript" || name === "urls") { return; }
-
- output += '<link id="original-less:less-'+name+'" rel="stylesheet/less" type="text/css" href="http://localhost:8081/' + path.join('less', name) + '.less' +'">\n';
- output += '<link id="expected-less:less-'+name+'" rel="stylesheet" type="text/css" href="http://localhost:8081/' + path.join('css', name) + '.css' + '">\n';
-});
+ sys = require('util');
-output += String(fs.readFileSync(path.join('test/browser', 'template.htm'))).replace("{runner-name}", "main");
+var createTestRunnerPage = function(dir, exclude, testSuiteName) {
+ var output = '<html><head>\n';
-fs.writeFileSync(path.join('test/browser', 'test-runner-main.htm'), output);
+ fs.readdirSync(path.join("test", dir, 'less')).forEach(function (file) {
+ if (! /\.less/.test(file)) { return; }
+
+ var name = path.basename(file, '.less');
+
+ if (exclude && name.match(exclude)) { return; }
+
+ output += '<link id="original-less:' + (dir ? dir+'-' : "") +'less-'+name+'" rel="stylesheet/less" type="text/css" href="http://localhost:8081/' + path.join(dir, 'less', name) + '.less' +'">\n';
+ output += '<link id="expected-less:' + (dir ? dir+'-' : "") +'less-'+name+'" rel="stylesheet" type="text/css" href="http://localhost:8081/' + path.join(dir, 'css', name) + '.css' + '">\n';
+ });
+
+ output += String(fs.readFileSync(path.join('test/browser', 'template.htm'))).replace("{runner-name}", testSuiteName);
+
+ fs.writeFileSync(path.join('test/browser', 'test-runner-'+testSuiteName+'.htm'), output);
+};
+
+createTestRunnerPage("", /javascript|urls/, "main");
+createTestRunnerPage("browser", null, "browser");
View
@@ -0,0 +1,74 @@
+/*if not async then phantomjs fails to run the webserver and the test concurrently*/
+var less = { async: true };
+
+var testLessEqualsInDocument = function() {
+ var links = document.getElementsByTagName('link'),
+ typePattern = /^text\/(x-)?less$/;
+
+ for (var i = 0; i < links.length; i++) {
+ if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
+ (links[i].type.match(typePattern)))) {
+ testSheet(links[i]);
+ }
+ }
+};
+
+var testSheet = function(sheet) {
+ it(sheet.id + " should match the expected output", function() {
+ var lessOutputId = sheet.id.replace("original-", ""),
+ expectedOutputId = "expected-" + lessOutputId,
+ lessOutput = document.getElementById(lessOutputId).innerText,
+ expectedOutputHref = document.getElementById(expectedOutputId).href,
+ expectedOutput = loadFile(expectedOutputHref);
+
+ waitsFor(function() {
+ return expectedOutput.loaded;
+ }, "failed to load expected outout", 10000);
+
+ runs(function() {
+ // use sheet to do testing
+ expect(lessOutput).toEqual(expectedOutput.text);
+ });
+ });
+};
+
+var loadFile = function(href) {
+ var request = new XMLHttpRequest(),
+ response = { loaded: false, text: ""};
+ request.open('GET', href, true);
+ request.onload = function(e) {
+ response.text = request.response;
+ response.loaded = true;
+ }
+ request.send();
+ return response;
+};
+
+(function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ setTimeout(function() {
+ jasmineEnv.execute();
+ }, 3000);
+ }
+
+})();
View
@@ -0,0 +1,27 @@
+@font-face {
+ src: url("/fonts/garamond-pro.ttf");
+ src: local(Futura-Medium), url(http://localhost:8081/browser/less/fonts.svg#MyGeometricModern) format("svg");
+}
+#shorthands {
+ background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
+}
+#misc {
+ background-image: url(http://localhost:8081/browser/less/images/image.jpg);
+}
+#data-uri {
+ background: url(data:image/png;charset=utf-8;base64,
+ kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
+ k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
+ kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
+ background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
+ background-image: url(http://fonts.googleapis.com/css?family=\"Rokkitt\":\(400\),700);
+}
+#svg-data-uri {
+ background: transparent url('data:image/svg+xml, <svg version="1.1"><g></g></svg>');
+}
+.comma-delimited {
+ background: url(http://localhost:8081/browser/less/bg.jpg) no-repeat, url(http://localhost:8081/browser/less/bg.png) repeat-x top left, url(http://localhost:8081/browser/less/bg);
+}
+.values {
+ url: url('http://localhost:8081/browser/less/Trebuchet');
+}
@@ -0,0 +1,31 @@
+@font-face {
+ src: url("/fonts/garamond-pro.ttf");
+ src: local(Futura-Medium),
+ url(fonts.svg#MyGeometricModern) format("svg");
+}
+#shorthands {
+ background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
+}
+#misc {
+ background-image: url(images/image.jpg);
+}
+#data-uri {
+ background: url(data:image/png;charset=utf-8;base64,
+ kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
+ k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
+ kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
+ background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
+ background-image: url(http://fonts.googleapis.com/css?family=\"Rokkitt\":\(400\),700);
+}
+
+#svg-data-uri {
+ background: transparent url('data:image/svg+xml, <svg version="1.1"><g></g></svg>');
+}
+
+.comma-delimited {
+ background: url(bg.jpg) no-repeat, url(bg.png) repeat-x top left, url(bg);
+}
+.values {
+ @a: 'Trebuchet';
+ url: url(@a);
+}
@@ -1,4 +1,4 @@
-var page = require('webpage').create();
+var webpage = require('webpage');
var server = require('webserver').create();
var system = require('system');
var fs = require('fs');
@@ -63,10 +63,12 @@ function waitFor(testFx, onReady, timeOutMillis) {
}
}, 100); //< repeat check every 100ms
};
-if (system.args.length != 2 && system.args[1] != "--no-tests") {
- page.open("http://localhost:8081/browser/test-runner-main.htm", function (status) {
+
+function testPage(url) {
+ var page = webpage.create();
+ page.open(url, function (status) {
if (status !== "success") {
- console.log("Unable to access network");
+ console.log("Unable to access network - " + status);
phantom.exit();
} else {
waitFor(function(){
@@ -100,8 +102,24 @@ if (system.args.length != 2 && system.args[1] != "--no-tests") {
return 0;
}
});
- phantom.exit(exitCode);
+ testFinished(exitCode);
});
}
});
+}
+
+var totalTests = 0,
+ totalFailed = 0,
+ totalDone = 0;
+
+function testFinished(failed) {
+ if (failed) { totalFailed++; }
+ totalDone++;
+ if (totalDone === totalTests) { phantom.exit(totalFailed > 0 ? 1 : 0); }
+}
+
+if (system.args.length != 2 && system.args[1] != "--no-tests") {
+ totalTests = 2;
+ testPage("http://localhost:8081/browser/test-runner-main.htm");
+ testPage("http://localhost:8081/browser/test-runner-browser.htm");
}
@@ -0,0 +1,3 @@
+describe("less.js browser tests", function() {
+ testLessEqualsInDocument();
+});
@@ -1,42 +1,15 @@
-describe("less.js", function() {
-
- var links = document.getElementsByTagName('link'),
- typePattern = /^text\/(x-)?less$/,
- testSheet = function(sheet) {
- it(sheet.id + " should match the expected output", function() {
- var lessOutputId = sheet.id.replace("original-", ""),
- expectedOutputId = "expected-" + lessOutputId,
- lessOutput = document.getElementById(lessOutputId).innerText,
- expectedOutputHref = document.getElementById(expectedOutputId).href,
- expectedOutput = loadFile(expectedOutputHref);
-
- waitsFor(function() {
- return expectedOutput.loaded;
- }, "failed to load expected outout", 10000);
-
- runs(function() {
- // use sheet to do testing
- expect(lessOutput).toEqual(expectedOutput.text);
- });
- });
- };
-
- for (var i = 0; i < links.length; i++) {
- if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
- (links[i].type.match(typePattern)))) {
- testSheet(links[i]);
- }
+less.functions = {
+ add: function (a, b) {
+ return new(less.tree.Dimension)(a.value + b.value);
+ },
+ increment: function (a) {
+ return new(less.tree.Dimension)(a.value + 1);
+ },
+ _color: function (str) {
+ if (str.value === "evil red") { return new(less.tree.Color)("600") }
}
-});
+};
-var loadFile = function(href) {
- var request = new XMLHttpRequest(),
- response = { loaded: false, text: ""};
- request.open('GET', href, true);
- request.onload = function(e) {
- response.text = request.response;
- response.loaded = true;
- }
- request.send();
- return response;
-};
+describe("less.js main tests", function() {
+ testLessEqualsInDocument();
+});
View
@@ -1,54 +1,9 @@
-<script type="text/javascript">
-/*if not async then phantomjs fails to run the webserver and the test concurrently*/
-less = { async: true,
- functions: {
- add: function (a, b) {
- return new(less.tree.Dimension)(a.value + b.value);
- },
- increment: function (a) {
- return new(less.tree.Dimension)(a.value + 1);
- },
- _color: function (str) {
- if (str.value === "evil red") { return new(less.tree.Color)("600") }
- }
- }
- };
-</script>
-<script src="http://localhost:8081/browser/less.js" type="text/javascript"></script>
<script src="http://localhost:8081/browser/jasmine.js" type="text/javascript"></script>
<script src="http://localhost:8081/browser/jasmine-html.js" type="text/javascript"></script>
+<script src="http://localhost:8081/browser/common.js" type="text/javascript"></script>
<script src="http://localhost:8081/browser/runner-{runner-name}.js" type="text/javascript"></script>
+<script src="http://localhost:8081/browser/less.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://localhost:8081/browser/jasmine.css"></link>
- <script type="text/javascript">
- (function() {
- var jasmineEnv = jasmine.getEnv();
- jasmineEnv.updateInterval = 1000;
-
- var htmlReporter = new jasmine.HtmlReporter();
-
- jasmineEnv.addReporter(htmlReporter);
-
- jasmineEnv.specFilter = function(spec) {
- return htmlReporter.specFilter(spec);
- };
-
- var currentWindowOnload = window.onload;
-
- window.onload = function() {
- if (currentWindowOnload) {
- currentWindowOnload();
- }
- execJasmine();
- };
-
- function execJasmine() {
- setTimeout(function() {
- jasmineEnv.execute();
- }, 3000);
- }
-
- })();
- </script>
</head>
<body>
</body>

0 comments on commit c35b6d7

Please sign in to comment.