-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
195 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,4 @@ node_modules | |
| *~ | ||
| .#* | ||
| test/browser/less.js | ||
| test/browser/test-runner-main.htm | ||
| test/browser/test-runner-*.htm | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
|
|
||
| })(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| describe("less.js browser tests", function() { | ||
| testLessEqualsInDocument(); | ||
| }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters