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// Stepping through breakpoints. 13{ 14 const scriptFullPath = fixtures.path('debugger', 'break.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( 27 cli.breakInfo, 28 { filename: script, line: 1 }, 29 ); 30 assert.match( 31 cli.output, 32 /> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/, 33 'shows the source and marks the current line'); 34 }) 35 .then(() => cli.stepCommand('n')) 36 .then(() => { 37 assert.ok( 38 cli.output.includes(`break in ${script}:2`), 39 'pauses in next line of the script'); 40 assert.match( 41 cli.output, 42 /> 2 let name = 'World';/, 43 'marks the 2nd line'); 44 }) 45 .then(() => cli.stepCommand('next')) 46 .then(() => { 47 assert.ok( 48 cli.output.includes(`break in ${script}:3`), 49 'pauses in next line of the script'); 50 assert.match( 51 cli.output, 52 /> 3 name = 'Robin';/, 53 'marks the 3nd line'); 54 }) 55 .then(() => cli.stepCommand('cont')) 56 .then(() => { 57 assert.ok( 58 cli.output.includes(`break in ${script}:10`), 59 'pauses on the next breakpoint'); 60 assert.match( 61 cli.output, 62 />10 debugger;/, 63 'marks the debugger line'); 64 }) 65 66 // Prepare additional breakpoints 67 .then(() => cli.command('sb("break.js", 6)')) 68 .then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/)) 69 .then(() => cli.command('sb("otherFunction()")')) 70 .then(() => cli.command('sb(16)')) 71 .then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/)) 72 .then(() => cli.command('breakpoints')) 73 .then(() => { 74 assert.ok(cli.output.includes(`#0 ${script}:6`)); 75 assert.ok(cli.output.includes(`#1 ${script}:16`)); 76 }) 77 78 .then(() => cli.command('list()')) 79 .then(() => { 80 assert.match( 81 cli.output, 82 />10 debugger;/, 83 'prints and marks current line' 84 ); 85 assert.deepStrictEqual( 86 cli.parseSourceLines(), 87 [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 88 ); 89 }) 90 .then(() => cli.command('list(2)')) 91 .then(() => { 92 assert.match( 93 cli.output, 94 />10 debugger;/, 95 'prints and marks current line' 96 ); 97 assert.deepStrictEqual( 98 cli.parseSourceLines(), 99 [8, 9, 10, 11, 12], 100 ); 101 }) 102 103 .then(() => cli.stepCommand('s')) 104 .then(() => cli.stepCommand('')) 105 .then(() => { 106 assert.match( 107 cli.output, 108 /break in timers/, 109 'entered timers.js'); 110 }) 111 .then(() => cli.stepCommand('cont')) 112 .then(() => { 113 assert.ok( 114 cli.output.includes(`break in ${script}:16`), 115 'found breakpoint we set above w/ line number only'); 116 }) 117 .then(() => cli.stepCommand('cont')) 118 .then(() => { 119 assert.ok( 120 cli.output.includes(`break in ${script}:6`), 121 'found breakpoint we set above w/ line number & script'); 122 }) 123 .then(() => cli.stepCommand('')) 124 .then(() => { 125 assert.ok( 126 cli.output.includes(`debugCommand in ${script}:14`), 127 'found function breakpoint we set above'); 128 }) 129 .then(() => cli.quit()) 130 .then(null, onFatal); 131} 132