From 0289794e5da7899f99f66022397ad5eb3f4ba274 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 14 May 2018 19:37:36 +0000 Subject: [PATCH] zjsunit: Give shorter tracebacks for failures. --- frontend_tests/zjsunit/index.js | 45 ++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index 3f1b8e4cae..bd8179a608 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -68,17 +68,44 @@ global.read_fixture_data = (fn) => { return data; }; +function short_tb(tb) { + const lines = tb.split('\n'); + + var i = _.findIndex(lines, (line) => { + return line.includes('run_one_module'); + }); + + if (i === -1) { + return tb; + } + + return lines.splice(0, i+1).join('\n') + '\n(...)\n'; +} + // Set up bugdown comparison helper global.bugdown_assert = require('./bugdown_assert.js'); -files.forEach(function (file) { - global.patch_builtin('setTimeout', noop); - global.patch_builtin('setInterval', noop); - _.throttle = immediate; - _.debounce = immediate; - +function run_one_module(file) { console.info('running tests for ' + file.name); - render.init(); require(file.full_name); - namespace.restore(); -}); +} + +try { + files.forEach(function (file) { + global.patch_builtin('setTimeout', noop); + global.patch_builtin('setInterval', noop); + _.throttle = immediate; + _.debounce = immediate; + + render.init(); + run_one_module(file); + namespace.restore(); + }); +} catch (e) { + if (e.stack) { + console.info(short_tb(e.stack)); + } else { + console.info(e); + } + process.exit(1); +}