11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 71cb0ef41Sopenharmony_ciconst startCLI = require('../common/debugger'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst path = require('path'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst scriptFullPath = fixtures.path('debugger', 'break.js'); 131cb0ef41Sopenharmony_ciconst script = path.relative(process.cwd(), scriptFullPath); 141cb0ef41Sopenharmony_ciconst cli = startCLI(['--port=0', script]); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci(async () => { 171cb0ef41Sopenharmony_ci await cli.waitForInitialBreak(); 181cb0ef41Sopenharmony_ci await cli.waitForPrompt(); 191cb0ef41Sopenharmony_ci assert.deepStrictEqual( 201cb0ef41Sopenharmony_ci cli.breakInfo, 211cb0ef41Sopenharmony_ci { filename: script, line: 1 }, 221cb0ef41Sopenharmony_ci ); 231cb0ef41Sopenharmony_ci assert.match( 241cb0ef41Sopenharmony_ci cli.output, 251cb0ef41Sopenharmony_ci /> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/, 261cb0ef41Sopenharmony_ci 'shows the source and marks the current line'); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci await cli.stepCommand('n'); 291cb0ef41Sopenharmony_ci assert.ok( 301cb0ef41Sopenharmony_ci cli.output.includes(`break in ${script}:2`), 311cb0ef41Sopenharmony_ci 'pauses in next line of the script'); 321cb0ef41Sopenharmony_ci assert.match( 331cb0ef41Sopenharmony_ci cli.output, 341cb0ef41Sopenharmony_ci /> 2 let name = 'World';/, 351cb0ef41Sopenharmony_ci 'marks the 2nd line'); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci await cli.stepCommand('next'); 381cb0ef41Sopenharmony_ci assert.ok( 391cb0ef41Sopenharmony_ci cli.output.includes(`break in ${script}:3`), 401cb0ef41Sopenharmony_ci 'pauses in next line of the script'); 411cb0ef41Sopenharmony_ci assert.match( 421cb0ef41Sopenharmony_ci cli.output, 431cb0ef41Sopenharmony_ci /> 3 name = 'Robin';/, 441cb0ef41Sopenharmony_ci 'marks the 3nd line'); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci await cli.stepCommand('cont'); 471cb0ef41Sopenharmony_ci assert.ok( 481cb0ef41Sopenharmony_ci cli.output.includes(`break in ${script}:10`), 491cb0ef41Sopenharmony_ci 'pauses on the next breakpoint'); 501cb0ef41Sopenharmony_ci assert.match( 511cb0ef41Sopenharmony_ci cli.output, 521cb0ef41Sopenharmony_ci />10 debugger;/, 531cb0ef41Sopenharmony_ci 'marks the debugger line'); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci await cli.command('sb("break.js", 6)'); 561cb0ef41Sopenharmony_ci assert.doesNotMatch(cli.output, /Could not resolve breakpoint/); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci await cli.command('sb("otherFunction()")'); 591cb0ef41Sopenharmony_ci await cli.command('sb(16)'); 601cb0ef41Sopenharmony_ci assert.doesNotMatch(cli.output, /Could not resolve breakpoint/); 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci await cli.command('breakpoints'); 631cb0ef41Sopenharmony_ci assert.ok(cli.output.includes(`#0 ${script}:6`)); 641cb0ef41Sopenharmony_ci assert.ok(cli.output.includes(`#1 ${script}:16`)); 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci await cli.command('list()'); 671cb0ef41Sopenharmony_ci assert.match( 681cb0ef41Sopenharmony_ci cli.output, 691cb0ef41Sopenharmony_ci />10 debugger;/, 701cb0ef41Sopenharmony_ci 'prints and marks current line' 711cb0ef41Sopenharmony_ci ); 721cb0ef41Sopenharmony_ci assert.deepStrictEqual( 731cb0ef41Sopenharmony_ci cli.parseSourceLines(), 741cb0ef41Sopenharmony_ci [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 751cb0ef41Sopenharmony_ci ); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci await cli.command('list(2)'); 781cb0ef41Sopenharmony_ci assert.match( 791cb0ef41Sopenharmony_ci cli.output, 801cb0ef41Sopenharmony_ci />10 debugger;/, 811cb0ef41Sopenharmony_ci 'prints and marks current line' 821cb0ef41Sopenharmony_ci ); 831cb0ef41Sopenharmony_ci assert.deepStrictEqual( 841cb0ef41Sopenharmony_ci cli.parseSourceLines(), 851cb0ef41Sopenharmony_ci [8, 9, 10, 11, 12], 861cb0ef41Sopenharmony_ci ); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci await cli.stepCommand('s'); 891cb0ef41Sopenharmony_ci await cli.stepCommand(''); 901cb0ef41Sopenharmony_ci assert.match( 911cb0ef41Sopenharmony_ci cli.output, 921cb0ef41Sopenharmony_ci /break in node:timers/, 931cb0ef41Sopenharmony_ci 'entered timers.js'); 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci await cli.stepCommand('cont'); 961cb0ef41Sopenharmony_ci assert.ok( 971cb0ef41Sopenharmony_ci cli.output.includes(`break in ${script}:16`), 981cb0ef41Sopenharmony_ci 'found breakpoint we set above w/ line number only'); 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci await cli.stepCommand('cont'); 1011cb0ef41Sopenharmony_ci assert.ok( 1021cb0ef41Sopenharmony_ci cli.output.includes(`break in ${script}:6`), 1031cb0ef41Sopenharmony_ci 'found breakpoint we set above w/ line number & script'); 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci await cli.stepCommand(''); 1061cb0ef41Sopenharmony_ci assert.ok( 1071cb0ef41Sopenharmony_ci cli.output.includes(`debugCommand in ${script}:14`), 1081cb0ef41Sopenharmony_ci 'found function breakpoint we set above'); 1091cb0ef41Sopenharmony_ci})().finally(() => cli.quit()) 1101cb0ef41Sopenharmony_ci .then(common.mustCall()); 111