From 9d6d1616285a42940571a272be721bc40c0eea91 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 28 May 2018 14:19:12 +0800 Subject: [PATCH] DEV: Take screenshot when smoke test fails. --- test/smoke_test.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/smoke_test.js b/test/smoke_test.js index a5eb288016c..c8914c970a8 100644 --- a/test/smoke_test.js +++ b/test/smoke_test.js @@ -25,23 +25,31 @@ const path = require('path'); height: 768 }); + const takeFailureScreenshot = function() { + const screenshotPath = '/tmp/smoke-test.png'; + console.log(`Screenshot of failure taken at ${screenshotPath}`); + return page.screenshot({ path: screenshotPath, fullPage: true }); + }; + const exec = (description, fn, assertion) => { const start = +new Date(); - return fn.call().then(output => { + return fn.call().then(async output => { if (assertion) { if (assertion.call(this, output)) { console.log(`PASSED: ${description} - ${(+new Date()) - start}ms`); } else { console.log(`FAILED: ${description} - ${(+new Date()) - start}ms`); + await takeFailureScreenshot(); console.log("SMOKE TEST FAILED"); process.exit(1); } } else { console.log(`PASSED: ${description} - ${(+new Date()) - start}ms`); } - }).catch(error => { + }).catch(async error => { console.log(`ERROR (${description}): ${error.message} - ${(+new Date()) - start}ms`); + await takeFailureScreenshot(); console.log("SMOKE TEST FAILED"); process.exit(1); });