mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Test result outputs
This commit is contained in:
parent
cdc7a744e3
commit
3bbcfe36e0
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ node_modules/
|
||||
server.js
|
||||
*.sublime-workspace
|
||||
chromedriver.log
|
||||
.baseline
|
1
tests/results/chrome-23.0.1271.97-windows-vista.json
Normal file
1
tests/results/chrome-23.0.1271.97-windows-vista.json
Normal file
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":98,"cases/background/linear-gradient.html":82.27},"date":"2012-12-28T16:48:04.248Z","version":"23.0.1271.97"}
|
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":100,"cases/background/linear-gradient.html":82.27},"date":"2012-12-28T17:20:56.098Z","version":"23.0.1271.97"}
|
1
tests/results/chrome.json
Normal file
1
tests/results/chrome.json
Normal file
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":100,"cases/background/linear-gradient.html":82.27},"date":"2012-12-28T16:48:04.248Z","version":"23.0.1271.97"}
|
1
tests/results/firefox-12.0-windows-vista.json
Normal file
1
tests/results/firefox-12.0-windows-vista.json
Normal file
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":100,"cases/background/linear-gradient.html":92.64},"date":"2012-12-28T16:48:10.772Z","version":"12.0"}
|
1
tests/results/firefox.json
Normal file
1
tests/results/firefox.json
Normal file
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":100,"cases/background/linear-gradient.html":85.64},"date":"2012-12-28T16:48:10.772Z","version":"12.0"}
|
1
tests/results/iexplorer-9-windows-vista.json
Normal file
1
tests/results/iexplorer-9-windows-vista.json
Normal file
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":100,"cases/background/linear-gradient.html":100},"date":"2012-12-28T16:48:04.855Z","version":"9"}
|
1
tests/results/iexplorer.json
Normal file
1
tests/results/iexplorer.json
Normal file
@ -0,0 +1 @@
|
||||
{"tests":{"cases/background/encoded.html":100,"cases/background/linear-gradient.html":100},"date":"2012-12-28T16:48:04.855Z","version":"9"}
|
@ -1,13 +1,14 @@
|
||||
var webdriver = require("webdriver.js").webdriver,
|
||||
http = require("http"),
|
||||
url = require("url"),
|
||||
path = require("path"),
|
||||
base64_arraybuffer = require('base64-arraybuffer'),
|
||||
PNG = require('png-js'),
|
||||
fs = require("fs");
|
||||
(function(){
|
||||
"use strict;"
|
||||
var webdriver = require("webdriver.js").webdriver,
|
||||
http = require("http"),
|
||||
url = require("url"),
|
||||
path = require("path"),
|
||||
base64_arraybuffer = require('base64-arraybuffer'),
|
||||
PNG = require('png-js'),
|
||||
fs = require("fs");
|
||||
|
||||
|
||||
function createServer(port) {
|
||||
function createServer(port) {
|
||||
return http.createServer(function(request, response) {
|
||||
var uri = url.parse(request.url).pathname,
|
||||
filename = path.join(process.cwd(), "../" + uri);
|
||||
@ -41,9 +42,9 @@ function createServer(port) {
|
||||
});
|
||||
|
||||
}).listen(port);
|
||||
}
|
||||
}
|
||||
|
||||
function walkDir(dir, done) {
|
||||
function walkDir(dir, done) {
|
||||
var results = [];
|
||||
fs.readdir(dir, function(err, list) {
|
||||
if (err) return done(err);
|
||||
@ -65,15 +66,15 @@ function walkDir(dir, done) {
|
||||
});
|
||||
})();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
function getPixelArray(base64, func) {
|
||||
function getPixelArray(base64, func) {
|
||||
var arraybuffer = base64_arraybuffer.decode(base64);
|
||||
(new PNG(arraybuffer)).decode(func);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function testPage(browser, url, done) {
|
||||
function testPage(browser, url, done) {
|
||||
|
||||
browser.url(url)
|
||||
.$(".html2canvas", 5000, function(){
|
||||
@ -96,9 +97,75 @@ function testPage(browser, url, done) {
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function runBrowsers(pages){
|
||||
var writeResultFile = function(filename, json, append) {
|
||||
fs.writeFile(filename + (append || ""), json);
|
||||
};
|
||||
|
||||
var openResultFile = function(stats, browser) {
|
||||
var tests = stats[browser].tests,
|
||||
filename = "results/" + browser + ".json",
|
||||
write = writeResultFile.bind(null, filename, JSON.stringify(stats[browser]));
|
||||
|
||||
fs.exists(filename, function(exists) {
|
||||
if(exists) {
|
||||
fs.readFile(filename, "binary", parseResultFile.bind(null, tests, browser, write));
|
||||
} else {
|
||||
write();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var setColor = function(color, text) {
|
||||
return color + text.amount + "% " + text.test;
|
||||
};
|
||||
|
||||
var parseResultFile = function(tests, browser, createResultFile, err, file) {
|
||||
if (err) throw err;
|
||||
var data = JSON.parse(file),
|
||||
improved = [],
|
||||
colors = {
|
||||
red: "\x1b[1;31m",
|
||||
green: "\x1b[0;32m"
|
||||
},
|
||||
regressed = [];
|
||||
|
||||
Object.keys(tests).forEach(function(test){
|
||||
var testResult = tests[test],
|
||||
dataResult = data.tests[test],
|
||||
dataObject = {
|
||||
amount: testResult - dataResult,
|
||||
test: test
|
||||
};
|
||||
|
||||
if (testResult > dataResult) {
|
||||
improved.push(dataObject);
|
||||
} else if (testResult < dataResult) {
|
||||
regressed.push(dataObject);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (improved.length > 0 || regressed.length > 0) {
|
||||
if (regressed.length === 0) {
|
||||
createResultFile(".baseline");
|
||||
}
|
||||
|
||||
console.log((regressed.length > 0) ? colors.red : colors.green, browser);
|
||||
|
||||
improved.map(setColor.bind(null, colors.green)).concat(regressed.map(setColor.bind(null, colors.red))).forEach(function(item) {
|
||||
console.log(" *", item);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function handleResults(stats) {
|
||||
Object.keys(stats).forEach(openResultFile.bind(null, stats));
|
||||
}
|
||||
|
||||
function runBrowsers(pages){
|
||||
|
||||
var port = 5555,
|
||||
stats = {},
|
||||
@ -110,7 +177,7 @@ function runBrowsers(pages){
|
||||
var browserDone = function() {
|
||||
if (++browsersDone >= browsers.length) {
|
||||
server.close();
|
||||
console.log(stats);
|
||||
handleResults(stats);
|
||||
}
|
||||
};
|
||||
|
||||
@ -119,13 +186,14 @@ function runBrowsers(pages){
|
||||
browser: browserName
|
||||
}),
|
||||
browserType;
|
||||
|
||||
browserName = browserName.replace("internet explorer", "iexplorer");
|
||||
browser.status(function(browserInfo){
|
||||
browserType = [browserName, browser.version, browserInfo.os.name.replace(/\s+/g, "-").toLowerCase()].join("-");
|
||||
var date = new Date(),
|
||||
obj = {
|
||||
tests: {},
|
||||
date: date.toISOString()
|
||||
date: date.toISOString(),
|
||||
version: browser.version
|
||||
};
|
||||
stats[browserType] = obj;
|
||||
stats[browserName] = obj;
|
||||
@ -145,10 +213,11 @@ function runBrowsers(pages){
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
walkDir("cases", function(err, results) {
|
||||
walkDir("cases", function(err, results) {
|
||||
if (err) throw err;
|
||||
runBrowsers(results);
|
||||
});
|
||||
runBrowsers(results.slice(0, 2));
|
||||
});
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user