• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const { spawn } = require('child_process');
3const Path = require('path');
4
5const { test } = require('tap');
6
7const startCLI = require('./start-cli');
8
9function launchTarget(...args) {
10  const childProc = spawn(process.execPath, args);
11  return Promise.resolve(childProc);
12}
13
14// process.debugPort is our proxy for "the version of node used to run this
15// test suite doesn't support SIGUSR1 for enabling --inspect for a process".
16const defaultsToOldProtocol = process.debugPort === 5858;
17
18test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => {
19  const script = Path.join('examples', 'alive.js');
20  let cli = null;
21  let target = null;
22
23  function cleanup(error) {
24    if (cli) {
25      cli.quit();
26      cli = null;
27    }
28    if (target) {
29      target.kill();
30      target = null;
31    }
32    if (error) throw error;
33  }
34
35  return launchTarget(script)
36    .then((childProc) => {
37      target = childProc;
38      cli = startCLI(['-p', `${target.pid}`]);
39      return cli.waitForPrompt();
40    })
41    .then(() => cli.command('sb("alive.js", 3)'))
42    .then(() => cli.waitFor(/break/))
43    .then(() => cli.waitForPrompt())
44    .then(() => {
45      t.match(
46        cli.output,
47        '> 3   ++x;',
48        'marks the 3rd line');
49    })
50    .then(() => cleanup())
51    .then(null, cleanup);
52});
53