mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Tests: Show SVG path data when boolean results are different.
This commit is contained in:
parent
2a090bc0d1
commit
7448aedf67
1 changed files with 19 additions and 10 deletions
|
@ -189,11 +189,11 @@ var comparePixels = function(actual, expected, message, options) {
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
actual = rasterize(actual, group, resolution),
|
actualRaster = rasterize(actual, group, resolution),
|
||||||
expected = rasterize(expected, group, resolution);
|
expectedRaster = rasterize(expected, group, resolution);
|
||||||
if (!actual || !expected) {
|
if (!actualRaster || !expectedRaster) {
|
||||||
QUnit.push(false, null, null, 'Unable to compare rasterized items: ' +
|
QUnit.push(false, null, null, 'Unable to compare rasterized items: ' +
|
||||||
(!actual ? 'actual' : 'expected') + ' item is null',
|
(!actualRaster ? 'actual' : 'expected') + ' item is null',
|
||||||
QUnit.stack(2));
|
QUnit.stack(2));
|
||||||
} else {
|
} else {
|
||||||
// Use resemble.js to compare the two rasterized items.
|
// Use resemble.js to compare the two rasterized items.
|
||||||
|
@ -208,8 +208,8 @@ var comparePixels = function(actual, expected, message, options) {
|
||||||
transparency: 1
|
transparency: 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
resemble(actual.getImageData())
|
resemble(actualRaster.getImageData())
|
||||||
.compareTo(expected.getImageData())
|
.compareTo(expectedRaster.getImageData())
|
||||||
.ignoreAntialiasing()
|
.ignoreAntialiasing()
|
||||||
// When working with imageData, this call is synchronous:
|
// When working with imageData, this call is synchronous:
|
||||||
.onComplete(function(data) { result = data; });
|
.onComplete(function(data) { result = data; });
|
||||||
|
@ -218,7 +218,16 @@ var comparePixels = function(actual, expected, message, options) {
|
||||||
fixed = tolerance < 1 ? ((1 / tolerance) + '').length - 1 : 0,
|
fixed = tolerance < 1 ? ((1 / tolerance) + '').length - 1 : 0,
|
||||||
identical = result ? 100 - result.misMatchPercentage : 0,
|
identical = result ? 100 - result.misMatchPercentage : 0,
|
||||||
ok = Math.abs(100 - identical) <= tolerance,
|
ok = Math.abs(100 - identical) <= tolerance,
|
||||||
text = identical.toFixed(fixed) + '% identical';
|
text = identical.toFixed(fixed) + '% identical',
|
||||||
|
detail = text;
|
||||||
|
if (!ok) {
|
||||||
|
console.log(actual, expected);
|
||||||
|
}
|
||||||
|
if (!ok &&
|
||||||
|
actual instanceof PathItem && expected instanceof PathItem) {
|
||||||
|
detail += '\nExpected:\n' + expected.pathData +
|
||||||
|
'\nActual:\n' + actual.pathData;
|
||||||
|
}
|
||||||
QUnit.push(ok, text, (100).toFixed(fixed) + '% identical', message);
|
QUnit.push(ok, text, (100).toFixed(fixed) + '% identical', message);
|
||||||
if (!ok && result && !isNode) {
|
if (!ok && result && !isNode) {
|
||||||
// Get the right entry for this unit test and assertion, and
|
// Get the right entry for this unit test and assertion, and
|
||||||
|
@ -227,10 +236,10 @@ var comparePixels = function(actual, expected, message, options) {
|
||||||
.querySelector('li:nth-child(' + (index) + ')'),
|
.querySelector('li:nth-child(' + (index) + ')'),
|
||||||
bounds = result.diffBounds;
|
bounds = result.diffBounds;
|
||||||
entry.querySelector('.test-expected td').innerHTML =
|
entry.querySelector('.test-expected td').innerHTML =
|
||||||
getImageTag(expected);
|
getImageTag(expectedRaster);
|
||||||
entry.querySelector('.test-actual td').innerHTML =
|
entry.querySelector('.test-actual td').innerHTML =
|
||||||
getImageTag(actual);
|
getImageTag(actualRaster);
|
||||||
entry.querySelector('.test-diff td').innerHTML = '<pre>' + text
|
entry.querySelector('.test-diff td').innerHTML = '<pre>' + detail
|
||||||
+ '</pre><br>'
|
+ '</pre><br>'
|
||||||
+ '<img src="' + result.getImageDataUrl() + '">';
|
+ '<img src="' + result.getImageDataUrl() + '">';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue