mirror of
https://github.com/konvajs/konva.git
synced 2025-11-18 17:21:36 +08:00
fixed up unit serialization tests. cleaned up constructor jsdoc comments. fixed Ellipse setRadius method
This commit is contained in:
136
tests/js/Test.js
136
tests/js/Test.js
@@ -3,95 +3,103 @@ var testCounter = null;
|
||||
var before, after;
|
||||
|
||||
function startTimer() {
|
||||
var date = new Date();
|
||||
before = date.getTime();
|
||||
var date = new Date();
|
||||
before = date.getTime();
|
||||
|
||||
}
|
||||
|
||||
function endTimer(str) {
|
||||
var date = new Date();
|
||||
after = date.getTime();
|
||||
var diff = after - before;
|
||||
console.log(str + ': ' + diff + 'ms');
|
||||
var date = new Date();
|
||||
after = date.getTime();
|
||||
var diff = after - before;
|
||||
console.log(str + ': ' + diff + 'ms');
|
||||
}
|
||||
|
||||
function warn(condition, message) {
|
||||
test(condition, message, true);
|
||||
test(condition, message, true);
|
||||
}
|
||||
|
||||
function test(condition, message, warn) {
|
||||
if(!condition) {
|
||||
if(warn) {
|
||||
testCounter.style.backgroundColor = 'orange';
|
||||
testCounter.style.color = 'black';
|
||||
console.warn(message + ' (NOTE: use Google Chrome for data url comparisons, run on web server for caching and filtering)');
|
||||
}
|
||||
else {
|
||||
testCounter.style.backgroundColor = 'red';
|
||||
testCounter.style.color = 'black';
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if(!condition) {
|
||||
if(warn) {
|
||||
if(testCounter.style.backgroundColor != 'red') {
|
||||
testCounter.style.backgroundColor = 'orange';
|
||||
testCounter.style.color = 'black';
|
||||
}
|
||||
console.warn(message + ' (NOTE: use Google Chrome for data url comparisons, run on web server for caching and filtering)');
|
||||
}
|
||||
else {
|
||||
testCounter.style.backgroundColor = 'red';
|
||||
testCounter.style.color = 'black';
|
||||
throw new Error(message);
|
||||
}
|
||||
numTests++;
|
||||
|
||||
testCounter.innerHTML = numTests;
|
||||
}
|
||||
numTests++;
|
||||
|
||||
testCounter.innerHTML = numTests;
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
console.log("LOG: " + message);
|
||||
console.log("LOG: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor
|
||||
*/
|
||||
function Test() {
|
||||
this.counter = 0;
|
||||
testCounter = document.createElement('div');
|
||||
testCounter.id = 'testCounter';
|
||||
document.getElementsByTagName('body')[0].appendChild(testCounter);
|
||||
this.counter = 0;
|
||||
testCounter = document.createElement('div');
|
||||
testCounter.id = 'testCounter';
|
||||
document.getElementsByTagName('body')[0].appendChild(testCounter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test methods
|
||||
*/
|
||||
Test.prototype = {
|
||||
addTestContainer: function(key) {
|
||||
var row = document.createElement('div');
|
||||
var container = document.createElement('div');
|
||||
var testMessage = document.createElement('p');
|
||||
addTestContainer: function(key) {
|
||||
var row = document.createElement('div');
|
||||
var container = document.createElement('div');
|
||||
var testMessage = document.createElement('p');
|
||||
|
||||
container.id = key;
|
||||
container.id = key;
|
||||
|
||||
document.body.appendChild(testMessage);
|
||||
row.appendChild(container);
|
||||
row.className = "row";
|
||||
document.body.appendChild(row);
|
||||
document.body.appendChild(testMessage);
|
||||
row.appendChild(container);
|
||||
row.className = "row";
|
||||
document.body.appendChild(row);
|
||||
|
||||
return {
|
||||
testMessage: testMessage
|
||||
};
|
||||
},
|
||||
run: function() {
|
||||
var tests = this.tests;
|
||||
return {
|
||||
testMessage: testMessage
|
||||
};
|
||||
},
|
||||
run: function() {
|
||||
var tests = this.tests;
|
||||
|
||||
var testOnlySpecial = false;
|
||||
var testOnlySpecial = false;
|
||||
|
||||
/*
|
||||
* if a test key has a star in front of it, then
|
||||
* only run special tests. This lets us easily run
|
||||
* specific tests without running all of them
|
||||
*/
|
||||
for(var key in tests) {
|
||||
if(key.charAt(0) === '*') {
|
||||
testOnlySpecial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(var key in tests) {
|
||||
if(!testOnlySpecial || key.charAt(0) === '*') {
|
||||
var obj = this.addTestContainer(key);
|
||||
this.counter++;
|
||||
console.log(this.counter + ") " + key);
|
||||
tests[key](key);
|
||||
obj.testMessage.innerHTML = this.counter + ") " + key + ': PASSED';
|
||||
obj.testMessage.setAttribute("class", "green");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* if a test key has a star in front of it, then
|
||||
* only run special tests. This lets us easily run
|
||||
* specific tests without running all of them
|
||||
*/
|
||||
for(var key in tests) {
|
||||
if(key.charAt(0) === '*') {
|
||||
testOnlySpecial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(var key in tests) {
|
||||
if(!testOnlySpecial || key.charAt(0) === '*') {
|
||||
var obj = this.addTestContainer(key);
|
||||
this.counter++;
|
||||
console.log(this.counter + ") " + key);
|
||||
tests[key](key);
|
||||
obj.testMessage.innerHTML = this.counter + ") " + key + ': PASSED';
|
||||
obj.testMessage.setAttribute("class", "green");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user