• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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([script]);
17
18  function onFatal(error) {
19    cli.quit();
20    throw error;
21  }
22
23  cli.waitForInitialBreak()
24    .then(() => cli.waitForPrompt())
25    .then(() => {
26      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
27    })
28    // Making sure it will die by default:
29    .then(() => cli.command('c'))
30    // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore.
31    .then(() => cli.waitFor(/disconnect|FATAL ERROR/))
32
33    // Next run: With `breakOnException` it pauses in both places.
34    .then(() => cli.stepCommand('r'))
35    .then(() => cli.waitForInitialBreak())
36    .then(() => {
37      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
38    })
39    .then(() => cli.command('breakOnException'))
40    .then(() => cli.stepCommand('c'))
41    .then(() => {
42      assert.ok(cli.output.includes(`exception in ${script}:3`));
43    })
44    .then(() => cli.stepCommand('c'))
45    .then(() => {
46      assert.ok(cli.output.includes(`exception in ${script}:9`));
47    })
48
49    // Next run: With `breakOnUncaught` it only pauses on the 2nd exception.
50    .then(() => cli.command('breakOnUncaught'))
51    .then(() => cli.stepCommand('r')) // Also, the setting survives the restart.
52    .then(() => cli.waitForInitialBreak())
53    .then(() => {
54      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
55    })
56    .then(() => cli.stepCommand('c'))
57    .then(() => {
58      assert.ok(cli.output.includes(`exception in ${script}:9`));
59    })
60
61    // Next run: Back to the initial state! It should die again.
62    .then(() => cli.command('breakOnNone'))
63    .then(() => cli.stepCommand('r'))
64    .then(() => cli.waitForInitialBreak())
65    .then(() => {
66      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
67    })
68    .then(() => cli.command('c'))
69    // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore
70    .then(() => cli.waitFor(/disconnect|FATAL ERROR/))
71
72    .then(() => cli.quit())
73    .then(null, onFatal);
74}
75