Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ebe797

Browse files
committed
robustify error handling in px comparison test
- add handle for request errors, to catch connections errors that can happen when the image server blows up - log error messages directly to stdout, so that they are written to the stdout as they happen in a child process exec block.
1 parent 7a492cf commit 3ebe797

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

test/image/compare_pixels_test.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ function comparePixels(mockName, cb) {
212212
imagePaths = getImagePaths(mockName),
213213
saveImageStream = fs.createWriteStream(imagePaths.test);
214214

215+
function log(msg) {
216+
process.stdout.write('Error for', mockName + ':', msg);
217+
}
218+
215219
function checkImage() {
216220

217221
// baseline image must be generated first
@@ -253,8 +257,8 @@ function comparePixels(mockName, cb) {
253257
function onEqualityCheck(err, isEqual) {
254258
if(err) {
255259
common.touch(imagePaths.diff);
256-
console.error(err);
257-
return;
260+
log(err)
261+
return cb(false, mockName);
258262
}
259263
if(isEqual) {
260264
fs.unlinkSync(imagePaths.diff);
@@ -266,12 +270,20 @@ function comparePixels(mockName, cb) {
266270
// 525 means a plotly.js error
267271
function onResponse(response) {
268272
if(+response.statusCode === 525) {
269-
console.error('plotly.js error while generating', mockName);
270-
cb(false, mockName);
273+
log('plotly.js error')
274+
return cb(false, mockName);
271275
}
272276
}
273277

278+
// this catches connection errors
279+
// e.g. when the image server blows up
280+
function onError(err) {
281+
log(err)
282+
return cb(false, mockName);
283+
}
284+
274285
request(requestOpts)
286+
.on('error', onError)
275287
.on('response', onResponse)
276288
.pipe(saveImageStream)
277289
.on('close', checkImage);

0 commit comments

Comments
 (0)