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 12const scriptFullPath = fixtures.path('debugger', 'break.js'); 13const script = path.relative(process.cwd(), scriptFullPath); 14const cli = startCLI(['--port=0', script]); 15 16(async () => { 17 await cli.waitForInitialBreak(); 18 await cli.waitForPrompt(); 19 assert.deepStrictEqual( 20 cli.breakInfo, 21 { filename: script, line: 1 }, 22 ); 23 assert.match( 24 cli.output, 25 /> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/, 26 'shows the source and marks the current line'); 27 28 await cli.stepCommand('n'); 29 assert.ok( 30 cli.output.includes(`break in ${script}:2`), 31 'pauses in next line of the script'); 32 assert.match( 33 cli.output, 34 /> 2 let name = 'World';/, 35 'marks the 2nd line'); 36 37 await cli.stepCommand('next'); 38 assert.ok( 39 cli.output.includes(`break in ${script}:3`), 40 'pauses in next line of the script'); 41 assert.match( 42 cli.output, 43 /> 3 name = 'Robin';/, 44 'marks the 3nd line'); 45 46 await cli.stepCommand('cont'); 47 assert.ok( 48 cli.output.includes(`break in ${script}:10`), 49 'pauses on the next breakpoint'); 50 assert.match( 51 cli.output, 52 />10 debugger;/, 53 'marks the debugger line'); 54 55 await cli.command('sb("break.js", 6)'); 56 assert.doesNotMatch(cli.output, /Could not resolve breakpoint/); 57 58 await cli.command('sb("otherFunction()")'); 59 await cli.command('sb(16)'); 60 assert.doesNotMatch(cli.output, /Could not resolve breakpoint/); 61 62 await cli.command('breakpoints'); 63 assert.ok(cli.output.includes(`#0 ${script}:6`)); 64 assert.ok(cli.output.includes(`#1 ${script}:16`)); 65 66 await cli.command('list()'); 67 assert.match( 68 cli.output, 69 />10 debugger;/, 70 'prints and marks current line' 71 ); 72 assert.deepStrictEqual( 73 cli.parseSourceLines(), 74 [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 75 ); 76 77 await cli.command('list(2)'); 78 assert.match( 79 cli.output, 80 />10 debugger;/, 81 'prints and marks current line' 82 ); 83 assert.deepStrictEqual( 84 cli.parseSourceLines(), 85 [8, 9, 10, 11, 12], 86 ); 87 88 await cli.stepCommand('s'); 89 await cli.stepCommand(''); 90 assert.match( 91 cli.output, 92 /break in node:timers/, 93 'entered timers.js'); 94 95 await cli.stepCommand('cont'); 96 assert.ok( 97 cli.output.includes(`break in ${script}:16`), 98 'found breakpoint we set above w/ line number only'); 99 100 await cli.stepCommand('cont'); 101 assert.ok( 102 cli.output.includes(`break in ${script}:6`), 103 'found breakpoint we set above w/ line number & script'); 104 105 await cli.stepCommand(''); 106 assert.ok( 107 cli.output.includes(`debugCommand in ${script}:14`), 108 'found function breakpoint we set above'); 109})().finally(() => cli.quit()) 110 .then(common.mustCall()); 111