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// Run after quit. 13{ 14 const scriptFullPath = fixtures.path('debugger', 'three-lines.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 return cli.waitForInitialBreak() 24 .then(() => cli.waitForPrompt()) 25 .then(() => cli.command('breakpoints')) 26 .then(() => { 27 assert.match(cli.output, /No breakpoints yet/); 28 }) 29 .then(() => cli.command('sb(2)')) 30 .then(() => cli.command('sb(3)')) 31 .then(() => cli.command('breakpoints')) 32 .then(() => { 33 assert.ok(cli.output.includes(`#0 ${script}:2`)); 34 assert.ok(cli.output.includes(`#1 ${script}:3`)); 35 }) 36 .then(() => cli.stepCommand('c')) // hit line 2 37 .then(() => cli.stepCommand('c')) // hit line 3 38 .then(() => { 39 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 }); 40 }) 41 .then(() => cli.command('restart')) 42 .then(() => cli.waitForInitialBreak()) 43 .then(() => { 44 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); 45 }) 46 .then(() => cli.stepCommand('c')) 47 .then(() => { 48 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 }); 49 }) 50 .then(() => cli.stepCommand('c')) 51 .then(() => { 52 assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 }); 53 }) 54 .then(() => cli.command('breakpoints')) 55 .then(() => { 56 const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`; 57 assert.ok(cli.output.includes(`#0 ${script}:2`), msg); 58 assert.ok(cli.output.includes(`#1 ${script}:3`), msg); 59 }) 60 .then(() => cli.quit()) 61 .then(null, onFatal); 62} 63