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_ci// Run after quit/restart.
131cb0ef41Sopenharmony_ci{
141cb0ef41Sopenharmony_ci  const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
151cb0ef41Sopenharmony_ci  const script = path.relative(process.cwd(), scriptFullPath);
161cb0ef41Sopenharmony_ci  const cli = startCLI(['--port=0', script]);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  function onFatal(error) {
191cb0ef41Sopenharmony_ci    cli.quit();
201cb0ef41Sopenharmony_ci    throw error;
211cb0ef41Sopenharmony_ci  }
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  cli.waitForInitialBreak()
241cb0ef41Sopenharmony_ci    .then(() => cli.waitForPrompt())
251cb0ef41Sopenharmony_ci    .then(() => cli.stepCommand('n'))
261cb0ef41Sopenharmony_ci    .then(() => {
271cb0ef41Sopenharmony_ci      assert.ok(
281cb0ef41Sopenharmony_ci        cli.output.includes(`break in ${script}:2`),
291cb0ef41Sopenharmony_ci        'steps to the 2nd line'
301cb0ef41Sopenharmony_ci      );
311cb0ef41Sopenharmony_ci    })
321cb0ef41Sopenharmony_ci    .then(() => cli.command('cont'))
331cb0ef41Sopenharmony_ci    .then(() => cli.waitFor(/disconnect/))
341cb0ef41Sopenharmony_ci    .then(() => {
351cb0ef41Sopenharmony_ci      assert.match(
361cb0ef41Sopenharmony_ci        cli.output,
371cb0ef41Sopenharmony_ci        /Waiting for the debugger to disconnect/,
381cb0ef41Sopenharmony_ci        'the child was done');
391cb0ef41Sopenharmony_ci    })
401cb0ef41Sopenharmony_ci    .then(() => {
411cb0ef41Sopenharmony_ci      // On windows the socket won't close by itself
421cb0ef41Sopenharmony_ci      return cli.command('kill');
431cb0ef41Sopenharmony_ci    })
441cb0ef41Sopenharmony_ci    .then(() => cli.command('cont'))
451cb0ef41Sopenharmony_ci    .then(() => cli.waitFor(/start the app/))
461cb0ef41Sopenharmony_ci    .then(() => {
471cb0ef41Sopenharmony_ci      assert.match(cli.output, /Use `run` to start the app again/);
481cb0ef41Sopenharmony_ci    })
491cb0ef41Sopenharmony_ci    .then(() => cli.stepCommand('run'))
501cb0ef41Sopenharmony_ci    .then(() => cli.waitForInitialBreak())
511cb0ef41Sopenharmony_ci    .then(() => cli.waitForPrompt())
521cb0ef41Sopenharmony_ci    .then(() => {
531cb0ef41Sopenharmony_ci      assert.deepStrictEqual(
541cb0ef41Sopenharmony_ci        cli.breakInfo,
551cb0ef41Sopenharmony_ci        { filename: script, line: 1 },
561cb0ef41Sopenharmony_ci      );
571cb0ef41Sopenharmony_ci    })
581cb0ef41Sopenharmony_ci    .then(() => cli.stepCommand('n'))
591cb0ef41Sopenharmony_ci    .then(() => {
601cb0ef41Sopenharmony_ci      assert.deepStrictEqual(
611cb0ef41Sopenharmony_ci        cli.breakInfo,
621cb0ef41Sopenharmony_ci        { filename: script, line: 2 },
631cb0ef41Sopenharmony_ci      );
641cb0ef41Sopenharmony_ci    })
651cb0ef41Sopenharmony_ci    .then(() => cli.stepCommand('restart'))
661cb0ef41Sopenharmony_ci    .then(() => cli.waitForInitialBreak())
671cb0ef41Sopenharmony_ci    .then(() => {
681cb0ef41Sopenharmony_ci      assert.deepStrictEqual(
691cb0ef41Sopenharmony_ci        cli.breakInfo,
701cb0ef41Sopenharmony_ci        { filename: script, line: 1 },
711cb0ef41Sopenharmony_ci      );
721cb0ef41Sopenharmony_ci    })
731cb0ef41Sopenharmony_ci    .then(() => cli.command('kill'))
741cb0ef41Sopenharmony_ci    .then(() => cli.command('cont'))
751cb0ef41Sopenharmony_ci    .then(() => cli.waitFor(/start the app/))
761cb0ef41Sopenharmony_ci    .then(() => {
771cb0ef41Sopenharmony_ci      assert.match(cli.output, /Use `run` to start the app again/);
781cb0ef41Sopenharmony_ci    })
791cb0ef41Sopenharmony_ci    .then(() => cli.stepCommand('run'))
801cb0ef41Sopenharmony_ci    .then(() => cli.waitForInitialBreak())
811cb0ef41Sopenharmony_ci    .then(() => cli.waitForPrompt())
821cb0ef41Sopenharmony_ci    .then(() => {
831cb0ef41Sopenharmony_ci      assert.deepStrictEqual(
841cb0ef41Sopenharmony_ci        cli.breakInfo,
851cb0ef41Sopenharmony_ci        { filename: script, line: 1 },
861cb0ef41Sopenharmony_ci      );
871cb0ef41Sopenharmony_ci    })
881cb0ef41Sopenharmony_ci    .then(() => cli.quit())
891cb0ef41Sopenharmony_ci    .then(null, onFatal);
901cb0ef41Sopenharmony_ci}
91