2016-12-11 14:36:58 -08:00
|
|
|
'use strict';
|
2021-04-08 23:55:45 -07:00
|
|
|
const common = require('../common');
|
2016-12-11 14:36:58 -08:00
|
|
|
|
2021-04-08 23:55:45 -07:00
|
|
|
common.skipIfInspectorDisabled();
|
2016-12-11 14:36:58 -08:00
|
|
|
|
2021-04-08 23:55:45 -07:00
|
|
|
const fixtures = require('../common/fixtures');
|
2021-05-03 21:58:42 -07:00
|
|
|
const startCLI = require('../common/debugger');
|
2016-12-11 14:36:58 -08:00
|
|
|
|
2021-04-08 23:55:45 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
// Break on (uncaught) exceptions.
|
|
|
|
{
|
2021-06-25 22:11:59 -07:00
|
|
|
const scriptFullPath = fixtures.path('debugger', 'exceptions.js');
|
2021-04-08 23:55:45 -07:00
|
|
|
const script = path.relative(process.cwd(), scriptFullPath);
|
2016-12-11 14:36:58 -08:00
|
|
|
const cli = startCLI([script]);
|
|
|
|
|
|
|
|
function onFatal(error) {
|
|
|
|
cli.quit();
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2021-04-08 23:55:45 -07:00
|
|
|
cli.waitForInitialBreak()
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => cli.waitForPrompt())
|
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
2021-04-08 23:55:45 -07:00
|
|
|
// Making sure it will die by default:
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => cli.command('c'))
|
2022-01-25 07:08:05 +05:30
|
|
|
.then(() => cli.waitFor(/disconnect/))
|
2016-12-11 14:36:58 -08:00
|
|
|
|
2021-04-08 23:55:45 -07:00
|
|
|
// Next run: With `breakOnException` it pauses in both places.
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => cli.stepCommand('r'))
|
2017-04-04 09:47:43 -07:00
|
|
|
.then(() => cli.waitForInitialBreak())
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
|
|
|
.then(() => cli.command('breakOnException'))
|
|
|
|
.then(() => cli.stepCommand('c'))
|
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.ok(cli.output.includes(`exception in ${script}:3`));
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
|
|
|
.then(() => cli.stepCommand('c'))
|
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.ok(cli.output.includes(`exception in ${script}:9`));
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
|
|
|
|
2021-04-08 23:55:45 -07:00
|
|
|
// Next run: With `breakOnUncaught` it only pauses on the 2nd exception.
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => cli.command('breakOnUncaught'))
|
2021-04-08 23:55:45 -07:00
|
|
|
.then(() => cli.stepCommand('r')) // Also, the setting survives the restart.
|
2017-04-04 09:47:43 -07:00
|
|
|
.then(() => cli.waitForInitialBreak())
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
|
|
|
.then(() => cli.stepCommand('c'))
|
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.ok(cli.output.includes(`exception in ${script}:9`));
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
// Next run: Back to the initial state! It should die again.
|
|
|
|
.then(() => cli.command('breakOnNone'))
|
|
|
|
.then(() => cli.stepCommand('r'))
|
2017-04-04 09:47:43 -07:00
|
|
|
.then(() => cli.waitForInitialBreak())
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => {
|
2021-04-08 23:55:45 -07:00
|
|
|
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
|
2016-12-11 14:36:58 -08:00
|
|
|
})
|
|
|
|
.then(() => cli.command('c'))
|
2022-01-25 07:08:05 +05:30
|
|
|
.then(() => cli.waitFor(/disconnect/))
|
2016-12-11 14:36:58 -08:00
|
|
|
.then(() => cli.quit())
|
|
|
|
.then(null, onFatal);
|
2021-04-08 23:55:45 -07:00
|
|
|
}
|