1'use strict'; 2const Path = require('path'); 3 4const { test } = require('tap'); 5 6const startCLI = require('./start-cli'); 7 8test('break on (uncaught) exceptions', (t) => { 9 const script = Path.join('examples', 'exceptions.js'); 10 const cli = startCLI([script]); 11 12 function onFatal(error) { 13 cli.quit(); 14 throw error; 15 } 16 17 return cli.waitForInitialBreak() 18 .then(() => cli.waitForPrompt()) 19 .then(() => { 20 t.match(cli.breakInfo, { filename: script, line: 1 }); 21 }) 22 // making sure it will die by default: 23 .then(() => cli.command('c')) 24 // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore 25 .then(() => cli.waitFor(/disconnect|FATAL ERROR/)) 26 27 // Next run: With `breakOnException` it pauses in both places 28 .then(() => cli.stepCommand('r')) 29 .then(() => cli.waitForInitialBreak()) 30 .then(() => { 31 t.match(cli.breakInfo, { filename: script, line: 1 }); 32 }) 33 .then(() => cli.command('breakOnException')) 34 .then(() => cli.stepCommand('c')) 35 .then(() => { 36 t.match(cli.output, `exception in ${script}:3`); 37 }) 38 .then(() => cli.stepCommand('c')) 39 .then(() => { 40 t.match(cli.output, `exception in ${script}:9`); 41 }) 42 43 // Next run: With `breakOnUncaught` it only pauses on the 2nd exception 44 .then(() => cli.command('breakOnUncaught')) 45 .then(() => cli.stepCommand('r')) // also, the setting survives the restart 46 .then(() => cli.waitForInitialBreak()) 47 .then(() => { 48 t.match(cli.breakInfo, { filename: script, line: 1 }); 49 }) 50 .then(() => cli.stepCommand('c')) 51 .then(() => { 52 t.match(cli.output, `exception in ${script}:9`); 53 }) 54 55 // Next run: Back to the initial state! It should die again. 56 .then(() => cli.command('breakOnNone')) 57 .then(() => cli.stepCommand('r')) 58 .then(() => cli.waitForInitialBreak()) 59 .then(() => { 60 t.match(cli.breakInfo, { filename: script, line: 1 }); 61 }) 62 .then(() => cli.command('c')) 63 // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore 64 .then(() => cli.waitFor(/disconnect|FATAL ERROR/)) 65 66 .then(() => cli.quit()) 67 .then(null, onFatal); 68}); 69