forked from nodejs/node
/
test-debugger-watchers.mjs
49 lines (40 loc) · 1.27 KB
/
test-debugger-watchers.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import { path } from '../common/fixtures.mjs';
import startCLI from '../common/debugger.js';
import assert from 'assert';
const script = path('debugger', 'break.js');
const cli = startCLI([script]);
function onFatal(error) {
cli.quit();
throw error;
}
// Stepping through breakpoints.
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('watch("x")');
await cli.command('watch("\\"Hello\\"")');
await cli.command('watch("42")');
await cli.command('watch("NaN")');
await cli.command('watch("true")');
await cli.command('watch("[1, 2]")');
await cli.command('watch("process.env")');
await cli.command('watchers');
assert.match(cli.output, /x is not defined/);
await cli.command('unwatch("42")');
await cli.stepCommand('n');
assert.match(cli.output, /0: x = 10/);
assert.match(cli.output, /1: "Hello" = 'Hello'/);
assert.match(cli.output, /2: NaN = NaN/);
assert.match(cli.output, /3: true = true/);
assert.match(cli.output, /4: \[1, 2\] = \[ 1, 2 \]/);
assert.match(
cli.output,
/5: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/,
'shows "..." for process.env'
);
await cli.quit();
} catch (error) {
onFatal(error);
}