1'use strict'; 2const common = require('../common'); 3 4common.skipIfInspectorDisabled(); 5 6const fixtures = require('../common/fixtures'); 7const startCLI = require('../common/debugger'); 8 9const assert = require('assert'); 10const path = require('path'); 11 12// Break on (uncaught) exceptions. 13{ 14 const scriptFullPath = fixtures.path('debugger', 'exceptions.js'); 15 const script = path.relative(process.cwd(), scriptFullPath); 16 const cli = startCLI(['--port=0', script]); 17 18 (async () => { 19 try { 20 await cli.waitForInitialBreak(); 21 await cli.waitForPrompt(); 22 await cli.waitForPrompt(); 23 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); 24 25 // Making sure it will die by default: 26 await cli.command('c'); 27 await cli.waitFor(/disconnect/); 28 29 // Next run: With `breakOnException` it pauses in both places. 30 await cli.stepCommand('r'); 31 await cli.waitForInitialBreak(); 32 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); 33 await cli.command('breakOnException'); 34 await cli.stepCommand('c'); 35 assert.ok(cli.output.includes(`exception in ${script}:3`)); 36 await cli.stepCommand('c'); 37 assert.ok(cli.output.includes(`exception in ${script}:9`)); 38 39 // Next run: With `breakOnUncaught` it only pauses on the 2nd exception. 40 await cli.command('breakOnUncaught'); 41 await cli.stepCommand('r'); // Also, the setting survives the restart. 42 await cli.waitForInitialBreak(); 43 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); 44 await cli.stepCommand('c'); 45 assert.ok(cli.output.includes(`exception in ${script}:9`)); 46 47 // Next run: Back to the initial state! It should die again. 48 await cli.command('breakOnNone'); 49 await cli.stepCommand('r'); 50 await cli.waitForInitialBreak(); 51 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); 52 await cli.command('c'); 53 await cli.waitFor(/disconnect/); 54 } finally { 55 cli.quit(); 56 } 57 })().then(common.mustCall()); 58} 59