mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 09:50:05 +08:00
created new test method, testDataUrl, which makes it super easy to identify data url comparison failures that resulted from Chrome upgrades. Begain integrating. fixed all synchronous unit test data url comparison failures
This commit is contained in:
@@ -322,7 +322,7 @@
|
||||
Kinetic.Node.addGetterSetter(Kinetic.Text, 'padding', 0);
|
||||
Kinetic.Node.addGetterSetter(Kinetic.Text, 'align', LEFT);
|
||||
Kinetic.Node.addGetterSetter(Kinetic.Text, 'lineHeight', 1);
|
||||
Kinetic.Node.addGetterSetter(Kinetic.Text, 'wrap', NONE);
|
||||
Kinetic.Node.addGetterSetter(Kinetic.Text, 'wrap', WORD);
|
||||
|
||||
Kinetic.Node.addGetter(Kinetic.Text, TEXT, EMPTY_STRING);
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@@ -12,29 +12,47 @@ function endTimer(str) {
|
||||
var diff = after - before;
|
||||
console.log(str + ': ' + diff + 'ms');
|
||||
}
|
||||
function warn(condition, message) {
|
||||
test(condition, message, true);
|
||||
}
|
||||
function test(condition, message, warn) {
|
||||
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);
|
||||
}
|
||||
|
||||
testCounter.style.backgroundColor = 'red';
|
||||
testCounter.style.color = 'black';
|
||||
throw new Error(message);
|
||||
}
|
||||
numTests++;
|
||||
|
||||
testCounter.innerHTML = numTests;
|
||||
}
|
||||
function warn(condition, message) {
|
||||
if(!condition) {
|
||||
if(testCounter.style.backgroundColor != 'red') {
|
||||
testCounter.style.backgroundColor = 'orange';
|
||||
testCounter.style.color = 'black';
|
||||
}
|
||||
console.warn(message);
|
||||
|
||||
}
|
||||
numTests++;
|
||||
testCounter.innerHTML = numTests;
|
||||
}
|
||||
function testDataUrl(actual, key, message) {
|
||||
var expected = dataUrls[key];
|
||||
|
||||
if(actual !== expected) {
|
||||
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)');
|
||||
|
||||
console.log('key: ' + key);
|
||||
console.log('actual:');
|
||||
console.log(actual);
|
||||
console.log('expected:');
|
||||
console.log(expected);
|
||||
}
|
||||
numTests++;
|
||||
testCounter.innerHTML = numTests;
|
||||
}
|
||||
function log(message) {
|
||||
console.log('LOG: ' + message);
|
||||
}
|
||||
|
@@ -124,7 +124,7 @@ Test.Modules.NODE = {
|
||||
|
||||
var dataUrl = layer.toDataURL();
|
||||
|
||||
warn(dataUrl === dataUrls['group to image'], 'group to image data url is incorrect');
|
||||
testDataUrl(dataUrl, 'group to image', 'group to image data url is incorrect');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -367,7 +367,7 @@ Test.Modules.NODE = {
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['clone group'], 'problem cloning group');
|
||||
testDataUrl(layer.toDataURL(), 'clone group', 'problem cloning group');
|
||||
|
||||
},
|
||||
'test on attr change': function(containerId) {
|
||||
@@ -736,7 +736,7 @@ Test.Modules.NODE = {
|
||||
|
||||
layer.draw();
|
||||
//console.log(layer.toDataURL());
|
||||
warn(dataUrls['regular and cached polygon'] === layer.toDataURL(), 'regular and cached polygon layer data url is incorrect');
|
||||
testDataUrl(layer.toDataURL(), 'regular and cached polygon', 'regular and cached polygon layer data url is incorrect');
|
||||
|
||||
});
|
||||
}
|
||||
@@ -839,7 +839,7 @@ Test.Modules.NODE = {
|
||||
var dataUrl = layer.toDataURL();
|
||||
//console.log(dataUrl);
|
||||
|
||||
warn(dataUrl === dataUrls['cache shape, group, layer, and stage'], 'problem caching shape, group, layer, and stage');
|
||||
testDataUrl(dataUrl, 'cache shape, group, layer, and stage', 'problem caching shape, group, layer, and stage');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2092,7 +2092,7 @@ Test.Modules.NODE = {
|
||||
|
||||
//console.log(startDataUrl);
|
||||
|
||||
warn(startDataUrl === dataUrls['serialize stage with custom shape'], 'start data url is incorrect');
|
||||
testDataUrl(startDataUrl, 'serialize stage with custom shape', 'start data url is incorrect');
|
||||
//test(triangle.getId() === 'myTriangle', 'triangle id should be myTriangle');
|
||||
|
||||
//console.log(stage.toJSON());
|
||||
@@ -2108,7 +2108,7 @@ Test.Modules.NODE = {
|
||||
layer.draw();
|
||||
|
||||
var endDataUrl = layer.toDataURL();
|
||||
warn(endDataUrl === dataUrls['serialize stage with custom shape'], 'end data url is incorrect');
|
||||
testDataUrl(endDataUrl,'serialize stage with custom shape', 'end data url is incorrect');
|
||||
|
||||
},
|
||||
'load stage with custom shape using json': function(containerId) {
|
||||
@@ -2549,7 +2549,7 @@ Test.Modules.NODE = {
|
||||
rect.destroy();
|
||||
//test(!rect.transAnim.isRunning(), 'rect trans should not be running after destroying it');
|
||||
layer.draw();
|
||||
warn(layer.toDataURL() === dataUrls['cleared'], 'transitioning rectangle should have been destroyed and removed from the screen');
|
||||
testDataUrl(layer.toDataURL(), 'cleared', 'transitioning rectangle should have been destroyed and removed from the screen');
|
||||
}, 1000);
|
||||
},
|
||||
'hide stage': function(containerId) {
|
||||
|
@@ -24,7 +24,7 @@ Test.Modules.SHAPE = {
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['scaled rect with disabled stroke scale'], 'probem with stroke scale disabling');
|
||||
testDataUrl(layer.toDataURL(), 'scaled rect with disabled stroke scale', 'probem with stroke scale disabling');
|
||||
},
|
||||
'test intersects()': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -113,7 +113,7 @@ Test.Modules.SHAPE = {
|
||||
|
||||
var dataUrl = layer.toDataURL();
|
||||
//console.log(dataUrl);
|
||||
warn(dataUrl === dataUrls['custom shape with two fills and strokes'], 'problem with custom shape with two fills');
|
||||
testDataUrl(dataUrl, 'custom shape with two fills and strokes', 'problem with custom shape with two fills');
|
||||
|
||||
},
|
||||
'custom shape with fill, stroke, and strokeWidth': function(containerId) {
|
||||
@@ -208,7 +208,7 @@ Test.Modules.SHAPE = {
|
||||
var dataUrl = layer.toDataURL();
|
||||
|
||||
//console.log(dataUrl);
|
||||
warn(dataUrls['change custom shape draw func'] === dataUrl, 'problem with setDrawFunc');
|
||||
testDataUrl(dataUrl, 'change custom shape draw func', 'problem with setDrawFunc');
|
||||
},
|
||||
'add star with translated, scaled, rotated fill': function(containerId) {
|
||||
var imageObj = new Image();
|
||||
@@ -415,7 +415,7 @@ Test.Modules.SHAPE = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['everything enabled'], 'should be circle with green fill, dashed stroke, and shadow');
|
||||
testDataUrl(layer.toDataURL(), 'everything enabled', 'should be circle with green fill, dashed stroke, and shadow');
|
||||
},
|
||||
'fill disabled': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -444,7 +444,7 @@ Test.Modules.SHAPE = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['fill disabled'], 'should be circle with no fill, dashed stroke, and shadow');
|
||||
testDataUrl(layer.toDataURL(), 'fill disabled', 'should be circle with no fill, dashed stroke, and shadow');
|
||||
},
|
||||
'stroke disabled': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -473,7 +473,7 @@ Test.Modules.SHAPE = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['stroke disabled'], 'should be circle with green fill, no stroke, and shadow');
|
||||
testDataUrl(layer.toDataURL(), 'stroke disabled', 'should be circle with green fill, no stroke, and shadow');
|
||||
},
|
||||
'dash array disabled': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -502,7 +502,7 @@ Test.Modules.SHAPE = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['dash array disabled'], 'should be circle with green fill, solid stroke, and shadow');
|
||||
testDataUrl(layer.toDataURL(), 'dash array disabled', 'should be circle with green fill, solid stroke, and shadow');
|
||||
},
|
||||
'shadow disabled': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -531,7 +531,7 @@ Test.Modules.SHAPE = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['shadow disabled'], 'should be circle with green fill, dashed stroke, and no shadow');
|
||||
testDataUrl(layer.toDataURL(), 'shadow disabled', 'should be circle with green fill, dashed stroke, and no shadow');
|
||||
},
|
||||
'test enablers and disablers': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -650,17 +650,17 @@ Test.Modules.SHAPE = {
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['red star'], 'star should have red fill');
|
||||
testDataUrl(layer.toDataURL(), 'red star', 'star should have red fill');
|
||||
|
||||
star.setFillPriority('linear-gradient');
|
||||
layer.draw();
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['star with linear gradient fill'], 'star should have linear gradient fill');
|
||||
testDataUrl(layer.toDataURL(), 'star with linear gradient fill', 'star should have linear gradient fill');
|
||||
|
||||
star.setFillPriority('color');
|
||||
layer.draw();
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['red star'], 'star should have red fill again');
|
||||
testDataUrl(layer.toDataURL(), 'red star', 'star should have red fill again');
|
||||
|
||||
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ Test.Modules.BLOB = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['blobs'], 'problem with blobs');
|
||||
testDataUrl(layer.toDataURL(), 'blobs', 'problem with blobs');
|
||||
|
||||
test(blob1.getTension() === 0.8, 'blob1 tension should be 0.8');
|
||||
test(blob2.getTension() === 1.2, 'blob2 tension should be 1.2');
|
||||
|
@@ -77,7 +77,7 @@ Test.Modules.SPLINE = {
|
||||
*/
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['curvy lines'], 'problem with curvy lines');
|
||||
testDataUrl(layer.toDataURL(), 'curvy lines', 'problem with curvy lines');
|
||||
|
||||
test(line1.getShapeType() === 'Spline', 'shape type should be Spline');
|
||||
|
||||
|
@@ -249,7 +249,7 @@ Test.Modules.Text = {
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['multiline text with shadows'], 'multi line text with shadows data url is incorrect');
|
||||
testDataUrl(layer.toDataURL(),'multiline text with shadows', 'multi line text with shadows data url is incorrect');
|
||||
},
|
||||
'change font size should update text data': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -317,7 +317,7 @@ Test.Modules.Text = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['text everything enabled'], 'should be text with blue fill and red stroke');
|
||||
testDataUrl(layer.toDataURL(), 'text everything enabled', 'should be text with blue fill and red stroke');
|
||||
},
|
||||
'text fill disabled': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -347,7 +347,7 @@ Test.Modules.Text = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['text fill disabled'], 'should be text with no fill and red stroke');
|
||||
testDataUrl(layer.toDataURL(), 'text fill disabled', 'should be text with no fill and red stroke');
|
||||
},
|
||||
'text stroke disabled': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -377,7 +377,7 @@ Test.Modules.Text = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['text stroke disabled'], 'should be text with blue fill and no stroke');
|
||||
testDataUrl(layer.toDataURL(),'text stroke disabled', 'should be text with blue fill and no stroke');
|
||||
},
|
||||
'wrapped text': function (containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -403,15 +403,15 @@ Test.Modules.Text = {
|
||||
layer.add(text);
|
||||
stage.add(layer);
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['wrapped text']['wrapping to words'], 'text should be wrapped to words');
|
||||
testDataUrl(layer.toDataURL(),'wrapping to words', 'text should be wrapped to words');
|
||||
|
||||
text.setWrap('none');
|
||||
layer.draw();
|
||||
warn(layer.toDataURL() === dataUrls['wrapped text']['no wrapping'], 'text should not be wrapped');
|
||||
testDataUrl(layer.toDataURL(),'no wrapping', 'text should not be wrapped');
|
||||
|
||||
text.setWrap('char');
|
||||
layer.draw();
|
||||
warn(layer.toDataURL() === dataUrls['wrapped text']['wrapping to chars'], 'text should be wrapped to chars');
|
||||
testDataUrl(layer.toDataURL(), 'wrapping to chars', 'text should be wrapped to chars');
|
||||
|
||||
}
|
||||
};
|
||||
|
@@ -22,7 +22,7 @@ Test.Modules.Wedge = {
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['wedge'], 'problem rendering wedge');
|
||||
testDataUrl(layer.toDataURL(), 'wedge', 'problem rendering wedge');
|
||||
|
||||
test(wedge.getShapeType() === 'Wedge', 'shape type should be Wedge');
|
||||
},
|
||||
@@ -77,6 +77,6 @@ Test.Modules.Wedge = {
|
||||
layer.draw();
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
warn(layer.toDataURL() === dataUrls['rotate wedge'], 'problem with rotated wedge rendering');
|
||||
testDataUrl(layer.toDataURL(), 'rotate wedge', 'problem with rotated wedge rendering');
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user