From b54e86d3619eba480ef01cb07855b425c84d0f83 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 7 Aug 2015 21:00:31 -0700 Subject: [PATCH] call screen.destroy instead of process.exit in tests. --- example/multiplex.js | 6 +++++- test/widget-autopad.js | 2 +- test/widget-bigtext.js | 2 +- test/widget-csr.js | 2 +- test/widget-dock-noborder.js | 2 +- test/widget-dock.js | 2 +- test/widget-exit.js | 2 +- test/widget-file.js | 2 +- test/widget-form.js | 2 +- test/widget-image.js | 2 +- test/widget-insert.js | 2 +- test/widget-layout.js | 2 +- test/widget-listbar.js | 2 +- test/widget-listtable.js | 2 +- test/widget-log.js | 2 +- test/widget-nested-attr.js | 2 +- test/widget-noalt.js | 4 ++-- test/widget-nowrap.js | 2 +- test/widget-obscure-sides.js | 2 +- test/widget-padding.js | 2 +- test/widget-play.js | 7 +++++-- test/widget-png.js | 2 +- test/widget-pos.js | 2 +- test/widget-prompt.js | 4 ++-- test/widget-record.js | 14 ++++++-------- test/widget-scrollable-boxes.js | 2 +- test/widget-shadow.js | 2 +- test/widget-shrink-fail-2.js | 2 +- test/widget-shrink-fail.js | 4 ++-- test/widget-shrink-padding.js | 2 +- test/widget-table.js | 2 +- test/widget-termswitch.js | 2 +- test/widget-textarea.js | 2 +- test/widget-unicode.js | 2 +- test/widget-valign.js | 2 +- test/widget-video.js | 2 +- 36 files changed, 52 insertions(+), 47 deletions(-) diff --git a/example/multiplex.js b/example/multiplex.js index cb11843..7cfee00 100755 --- a/example/multiplex.js +++ b/example/multiplex.js @@ -127,7 +127,11 @@ var bottomright = blessed.terminal({ topleft.focus(); screen.key('C-q', function() { - return process.exit(0); + topleft.kill(); + topright.kill(); + bottomleft.kill(); + bottomright.kill(); + return screen.destroy(); }); screen.program.key('S-tab', function() { diff --git a/test/widget-autopad.js b/test/widget-autopad.js index 81bb817..d877e1f 100644 --- a/test/widget-autopad.js +++ b/test/widget-autopad.js @@ -27,7 +27,7 @@ var box2 = blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-bigtext.js b/test/widget-bigtext.js index 806a87a..eb3bc3d 100644 --- a/test/widget-bigtext.js +++ b/test/widget-bigtext.js @@ -26,7 +26,7 @@ var box = blessed.bigtext({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-csr.js b/test/widget-csr.js index 02768d3..553348d 100644 --- a/test/widget-csr.js +++ b/test/widget-csr.js @@ -84,7 +84,7 @@ text.scroll = function(offset, always) { text.focus(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-dock-noborder.js b/test/widget-dock-noborder.js index 4517e1e..edcaec2 100644 --- a/test/widget-dock-noborder.js +++ b/test/widget-dock-noborder.js @@ -82,7 +82,7 @@ blessed.listtable({ // }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-dock.js b/test/widget-dock.js index 79f2658..af2a4db 100644 --- a/test/widget-dock.js +++ b/test/widget-dock.js @@ -119,7 +119,7 @@ var over = blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-exit.js b/test/widget-exit.js index d6bb9f5..9a1d06f 100644 --- a/test/widget-exit.js +++ b/test/widget-exit.js @@ -32,5 +32,5 @@ box.input('Input: ', '', function(err, data) { }); screen.key('C-q', function(ch, key) { - return process.exit(0); + return screen.destroy(); }); diff --git a/test/widget-file.js b/test/widget-file.js index 3b9c549..6fcd00c 100644 --- a/test/widget-file.js +++ b/test/widget-file.js @@ -47,7 +47,7 @@ fm.refresh(); screen.render(); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); screen.key(['s', 'p'], function() { diff --git a/test/widget-form.js b/test/widget-form.js index 2e6ca56..b601e71 100644 --- a/test/widget-form.js +++ b/test/widget-form.js @@ -243,7 +243,7 @@ var bottom = blessed.line({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); form.focus(); diff --git a/test/widget-image.js b/test/widget-image.js index 50f15f3..24611d0 100644 --- a/test/widget-image.js +++ b/test/widget-image.js @@ -64,7 +64,7 @@ screen.key('i', function() { }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-insert.js b/test/widget-insert.js index 657d32a..b0af042 100644 --- a/test/widget-insert.js +++ b/test/widget-insert.js @@ -33,5 +33,5 @@ setTimeout(function() { }, 2000); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); diff --git a/test/widget-layout.js b/test/widget-layout.js index ae32ce4..46e447b 100644 --- a/test/widget-layout.js +++ b/test/widget-layout.js @@ -159,7 +159,7 @@ if (process.argv[2] !== 'grid') { } screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-listbar.js b/test/widget-listbar.js index 661ec17..f9983af 100644 --- a/test/widget-listbar.js +++ b/test/widget-listbar.js @@ -116,7 +116,7 @@ screen.append(bar); bar.focus(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-listtable.js b/test/widget-listtable.js index a9a0be1..caafef3 100644 --- a/test/widget-listtable.js +++ b/test/widget-listtable.js @@ -83,7 +83,7 @@ data2[1][0] = '{red-fg}' + data2[1][0] + '{/red-fg}'; data2[2][0] += ' (' + DU + JUAN + ')'; screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); table.focus(); diff --git a/test/widget-log.js b/test/widget-log.js index cd6d36a..e7a6a8a 100644 --- a/test/widget-log.js +++ b/test/widget-log.js @@ -42,7 +42,7 @@ setInterval(function() { }, 1000).unref(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-nested-attr.js b/test/widget-nested-attr.js index fc75e9b..50fbac9 100644 --- a/test/widget-nested-attr.js +++ b/test/widget-nested-attr.js @@ -23,7 +23,7 @@ blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-noalt.js b/test/widget-noalt.js index 2cb41d5..ed5f490 100644 --- a/test/widget-noalt.js +++ b/test/widget-noalt.js @@ -38,11 +38,11 @@ list.select(0); list.on('select', function(item) { console.log(item.getText()); - process.exit(0); + screen.destroy(); }); screen.key('C-c', function() { - process.exit(0); + screen.destroy(); }); list.focus(); diff --git a/test/widget-nowrap.js b/test/widget-nowrap.js index 6259a71..f94b9ff 100644 --- a/test/widget-nowrap.js +++ b/test/widget-nowrap.js @@ -23,7 +23,7 @@ var box = blessed.box({ box.focus(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-obscure-sides.js b/test/widget-obscure-sides.js index 4265e37..df629dc 100644 --- a/test/widget-obscure-sides.js +++ b/test/widget-obscure-sides.js @@ -68,5 +68,5 @@ box.focus(); screen.render(); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); diff --git a/test/widget-padding.js b/test/widget-padding.js index 9a0ae54..f3f542e 100644 --- a/test/widget-padding.js +++ b/test/widget-padding.js @@ -22,7 +22,7 @@ blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-play.js b/test/widget-play.js index 3d29b05..a8e689a 100644 --- a/test/widget-play.js +++ b/test/widget-play.js @@ -8,7 +8,10 @@ var screen = blessed.screen({ var frames = require(__dirname + '/frames.json'); -setInterval(function() { - if (!frames.length) return process.exit(0); +var timer = setInterval(function() { + if (!frames.length) { + clearInterval(timer); + return screen.destroy(); + } process.stdout.write(frames.shift()); }, 100); diff --git a/test/widget-png.js b/test/widget-png.js index 9725cc9..bb6b6f5 100644 --- a/test/widget-png.js +++ b/test/widget-png.js @@ -94,7 +94,7 @@ var png = blessed.image({ screen.render(); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); var timeout = setInterval(function() { diff --git a/test/widget-pos.js b/test/widget-pos.js index 8d8ab19..68631b8 100644 --- a/test/widget-pos.js +++ b/test/widget-pos.js @@ -107,7 +107,7 @@ assert.equal(inner.rtop, 4); screen.on('keypress', function(ch, key) { if (key.name === 'escape' || key.name === 'q') { - return process.exit(0); + return screen.destroy(); } }); diff --git a/test/widget-prompt.js b/test/widget-prompt.js index 58be369..35f5879 100644 --- a/test/widget-prompt.js +++ b/test/widget-prompt.js @@ -69,7 +69,7 @@ prompt.input('Question?', '', function(err, value) { loader.load('Loading...'); setTimeout(function() { loader.stop(); - process.exit(0); + screen.destroy(); }, 3000); }); }); @@ -77,7 +77,7 @@ prompt.input('Question?', '', function(err, value) { }); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); screen.render(); diff --git a/test/widget-record.js b/test/widget-record.js index f992021..d15a7d0 100644 --- a/test/widget-record.js +++ b/test/widget-record.js @@ -36,18 +36,16 @@ var text = blessed.scrollabletext({ text.focus(); -screen.key('q', function() { - return process.exit(0); -}); - -screen.render(); - var frames = []; -setInterval(function() { +var timer = setInterval(function() { frames.push(screen.screenshot()); }, 100); -process.on('exit', function() { +screen.key('C-q', function() { fs.writeFileSync(__dirname + '/frames.json', JSON.stringify(frames)); + clearInterval(timer); + return screen.destroy(); }); + +screen.render(); diff --git a/test/widget-scrollable-boxes.js b/test/widget-scrollable-boxes.js index 09598b3..742c288 100644 --- a/test/widget-scrollable-boxes.js +++ b/test/widget-scrollable-boxes.js @@ -120,7 +120,7 @@ var box3 = blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); box.focus(); diff --git a/test/widget-shadow.js b/test/widget-shadow.js index b819237..cee7261 100644 --- a/test/widget-shadow.js +++ b/test/widget-shadow.js @@ -75,7 +75,7 @@ over.key('down', function() { over.focus(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); var lorem = 'Non eram nescius Brute cum quae summis ingeniis exquisitaque' diff --git a/test/widget-shrink-fail-2.js b/test/widget-shrink-fail-2.js index 98ea134..694e9b1 100644 --- a/test/widget-shrink-fail-2.js +++ b/test/widget-shrink-fail-2.js @@ -37,7 +37,7 @@ tab._.data = blessed.text({ tab._.data.setContent(require('util').inspect(process, null, 6)); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); screen.render(); diff --git a/test/widget-shrink-fail.js b/test/widget-shrink-fail.js index 2132e4c..fcb6dc3 100644 --- a/test/widget-shrink-fail.js +++ b/test/widget-shrink-fail.js @@ -151,11 +151,11 @@ form._.submit.on('press', function() { form.on('submit', function(data) { screen.leave(); console.log(data); - process.exit(0); + screen.destroy(); }); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); screen.render(); diff --git a/test/widget-shrink-padding.js b/test/widget-shrink-padding.js index 145203b..016ecaf 100644 --- a/test/widget-shrink-padding.js +++ b/test/widget-shrink-padding.js @@ -37,7 +37,7 @@ var inner = blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-table.js b/test/widget-table.js index 8f6786e..a152576 100644 --- a/test/widget-table.js +++ b/test/widget-table.js @@ -58,7 +58,7 @@ data2[1][0] = '{red-fg}' + data2[1][0] + '{/red-fg}'; data2[2][0] += ' (' + DU + JUAN + ')'; screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); table.setData(data2); diff --git a/test/widget-termswitch.js b/test/widget-termswitch.js index 3a8752c..9ff5d36 100644 --- a/test/widget-termswitch.js +++ b/test/widget-termswitch.js @@ -39,7 +39,7 @@ var text = blessed.scrollabletext({ text.focus(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-textarea.js b/test/widget-textarea.js index 70e3822..a0d89ee 100644 --- a/test/widget-textarea.js +++ b/test/widget-textarea.js @@ -24,7 +24,7 @@ var box = blessed.textarea({ screen.render(); screen.key('q', function() { - process.exit(0); + screen.destroy(); }); screen.key('i', function() { diff --git a/test/widget-unicode.js b/test/widget-unicode.js index 08aa213..74a0b8b 100644 --- a/test/widget-unicode.js +++ b/test/widget-unicode.js @@ -105,7 +105,7 @@ var main = blessed.box({ main.focus(); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-valign.js b/test/widget-valign.js index c87f094..3289ca3 100644 --- a/test/widget-valign.js +++ b/test/widget-valign.js @@ -22,7 +22,7 @@ var box = blessed.box({ }); screen.key('q', function() { - return process.exit(0); + return screen.destroy(); }); screen.render(); diff --git a/test/widget-video.js b/test/widget-video.js index 880f8d8..66f23c7 100644 --- a/test/widget-video.js +++ b/test/widget-video.js @@ -23,5 +23,5 @@ video.focus(); screen.render(); screen.key(['q', 'C-q', 'C-c'], function() { - process.exit(0); + screen.destroy(); });