• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/restart.
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  cli.waitForInitialBreak()
24    .then(() => cli.waitForPrompt())
25    .then(() => cli.stepCommand('n'))
26    .then(() => {
27      assert.ok(
28        cli.output.includes(`break in ${script}:2`),
29        'steps to the 2nd line'
30      );
31    })
32    .then(() => cli.command('cont'))
33    .then(() => cli.waitFor(/disconnect/))
34    .then(() => {
35      assert.match(
36        cli.output,
37        /Waiting for the debugger to disconnect/,
38        'the child was done');
39    })
40    .then(() => {
41      // On windows the socket won't close by itself
42      return cli.command('kill');
43    })
44    .then(() => cli.command('cont'))
45    .then(() => cli.waitFor(/start the app/))
46    .then(() => {
47      assert.match(cli.output, /Use `run` to start the app again/);
48    })
49    .then(() => cli.stepCommand('run'))
50    .then(() => cli.waitForInitialBreak())
51    .then(() => cli.waitForPrompt())
52    .then(() => {
53      assert.deepStrictEqual(
54        cli.breakInfo,
55        { filename: script, line: 1 },
56      );
57    })
58    .then(() => cli.stepCommand('n'))
59    .then(() => {
60      assert.deepStrictEqual(
61        cli.breakInfo,
62        { filename: script, line: 2 },
63      );
64    })
65    .then(() => cli.stepCommand('restart'))
66    .then(() => cli.waitForInitialBreak())
67    .then(() => {
68      assert.deepStrictEqual(
69        cli.breakInfo,
70        { filename: script, line: 1 },
71      );
72    })
73    .then(() => cli.command('kill'))
74    .then(() => cli.command('cont'))
75    .then(() => cli.waitFor(/start the app/))
76    .then(() => {
77      assert.match(cli.output, /Use `run` to start the app again/);
78    })
79    .then(() => cli.stepCommand('run'))
80    .then(() => cli.waitForInitialBreak())
81    .then(() => cli.waitForPrompt())
82    .then(() => {
83      assert.deepStrictEqual(
84        cli.breakInfo,
85        { filename: script, line: 1 },
86      );
87    })
88    .then(() => cli.quit())
89    .then(null, onFatal);
90}
91