Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit cc4da57

Browse files
author
Jan Krems
committed
fix: Address regressions due to changes in node
1 parent 1d94012 commit cc4da57

File tree

9 files changed

+57
-30
lines changed

9 files changed

+57
-30
lines changed

lib/internal/inspect_repl.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Path = require('path');
2525
const Repl = require('repl');
2626
const util = require('util');
2727
const vm = require('vm');
28+
const fileURLToPath = require('url').fileURLToPath;
2829

2930
const debuglog = util.debuglog('inspect');
3031

@@ -89,9 +90,12 @@ function isNativeUrl(url) {
8990
return url.replace('.js', '') in NATIVES || url === 'bootstrap_node.js';
9091
}
9192

92-
function getRelativePath(filename) {
93+
function getRelativePath(filenameOrURL) {
9394
const dir = Path.join(Path.resolve(), 'x').slice(0, -1);
9495

96+
const filename = filenameOrURL.startsWith('file://') ?
97+
fileURLToPath(filenameOrURL) : filenameOrURL;
98+
9599
// Change path to relative, if possible
96100
if (filename.indexOf(dir) === 0) {
97101
return filename.slice(dir.length);

test/cli/break.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ test('stepping through breakpoints', (t) => {
1818
.then(() => cli.waitForPrompt())
1919
.then(() => {
2020
t.match(
21-
cli.output,
22-
`break in ${script}:1`,
21+
cli.breakInfo,
22+
{ filename: script, line: 1 },
2323
'pauses in the first line of the script');
2424
t.match(
2525
cli.output,
26-
/> 1 \(function \([^)]+\) \{ const x = 10;/,
26+
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
2727
'shows the source and marks the current line');
2828
})
2929
.then(() => cli.stepCommand('n'))

test/cli/exceptions.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('break on (uncaught) exceptions', (t) => {
1717
return cli.waitForInitialBreak()
1818
.then(() => cli.waitForPrompt())
1919
.then(() => {
20-
t.match(cli.output, `break in ${script}:1`);
20+
t.match(cli.breakInfo, { filename: script, line: 1 });
2121
})
2222
// making sure it will die by default:
2323
.then(() => cli.command('c'))
@@ -28,7 +28,7 @@ test('break on (uncaught) exceptions', (t) => {
2828
.then(() => cli.stepCommand('r'))
2929
.then(() => cli.waitForInitialBreak())
3030
.then(() => {
31-
t.match(cli.output, `break in ${script}:1`);
31+
t.match(cli.breakInfo, { filename: script, line: 1 });
3232
})
3333
.then(() => cli.command('breakOnException'))
3434
.then(() => cli.stepCommand('c'))
@@ -45,7 +45,7 @@ test('break on (uncaught) exceptions', (t) => {
4545
.then(() => cli.stepCommand('r')) // also, the setting survives the restart
4646
.then(() => cli.waitForInitialBreak())
4747
.then(() => {
48-
t.match(cli.output, `break in ${script}:1`);
48+
t.match(cli.breakInfo, { filename: script, line: 1 });
4949
})
5050
.then(() => cli.stepCommand('c'))
5151
.then(() => {
@@ -57,7 +57,7 @@ test('break on (uncaught) exceptions', (t) => {
5757
.then(() => cli.stepCommand('r'))
5858
.then(() => cli.waitForInitialBreak())
5959
.then(() => {
60-
t.match(cli.output, `break in ${script}:1`);
60+
t.match(cli.breakInfo, { filename: script, line: 1 });
6161
})
6262
.then(() => cli.command('c'))
6363
// TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore

test/cli/launch.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,23 @@ test('run after quit / restart', (t) => {
137137
.then(() => cli.waitForPrompt())
138138
.then(() => {
139139
t.match(
140-
cli.output,
141-
`break in ${script}:1`,
140+
cli.breakInfo,
141+
{ filename: script, line: 1 },
142142
'is back at the beginning');
143143
})
144144
.then(() => cli.stepCommand('n'))
145145
.then(() => {
146146
t.match(
147-
cli.output,
148-
`break in ${script}:2`,
147+
cli.breakInfo,
148+
{ filename: script, line: 2 },
149149
'steps to the 2nd line');
150150
})
151151
.then(() => cli.stepCommand('restart'))
152152
.then(() => cli.waitForInitialBreak())
153153
.then(() => {
154154
t.match(
155-
cli.output,
156-
`break in ${script}:1`,
155+
cli.breakInfo,
156+
{ filename: script, line: 1 },
157157
'is back at the beginning');
158158
})
159159
.then(() => cli.command('kill'))
@@ -167,8 +167,8 @@ test('run after quit / restart', (t) => {
167167
.then(() => cli.waitForPrompt())
168168
.then(() => {
169169
t.match(
170-
cli.output,
171-
`break in ${script}:1`,
170+
cli.breakInfo,
171+
{ filename: script, line: 1 },
172172
'is back at the beginning');
173173
})
174174
.then(() => cli.quit())

test/cli/low-level.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test('Debugger agent direct access', (t) => {
2424
.then(() => {
2525
t.match(
2626
cli.output,
27-
/scriptSource: '\(function \(/);
27+
/scriptSource:[ \n]*'(?:\(function \(|let x = 1)/);
2828
t.match(
2929
cli.output,
3030
/let x = 1;/);

test/cli/preserve-breaks.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ test('run after quit / restart', (t) => {
3030
.then(() => cli.stepCommand('c')) // hit line 2
3131
.then(() => cli.stepCommand('c')) // hit line 3
3232
.then(() => {
33-
t.match(cli.output, `break in ${script}:3`);
33+
t.match(cli.breakInfo, { filename: script, line: 3 });
3434
})
3535
.then(() => cli.command('restart'))
3636
.then(() => cli.waitForInitialBreak())
3737
.then(() => {
38-
t.match(cli.output, `break in ${script}:1`);
38+
t.match(cli.breakInfo, { filename: script, line: 1 });
3939
})
4040
.then(() => cli.stepCommand('c'))
4141
.then(() => {
42-
t.match(cli.output, `break in ${script}:2`);
42+
t.match(cli.breakInfo, { filename: script, line: 2 });
4343
})
4444
.then(() => cli.stepCommand('c'))
4545
.then(() => {
46-
t.match(cli.output, `break in ${script}:3`);
46+
t.match(cli.breakInfo, { filename: script, line: 3 });
4747
})
4848
.then(() => cli.command('breakpoints'))
4949
.then(() => {

test/cli/scripts.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test('list scripts', (t) => {
2424
'lists the user script');
2525
t.notMatch(
2626
cli.output,
27-
/\d+: module\.js <native>/,
27+
/\d+: buffer\.js <native>/,
2828
'omits node-internal scripts');
2929
})
3030
.then(() => cli.command('scripts(true)'))
@@ -35,7 +35,7 @@ test('list scripts', (t) => {
3535
'lists the user script');
3636
t.match(
3737
cli.output,
38-
/\d+: module\.js <native>/,
38+
/\d+: buffer\.js <native>/,
3939
'includes node-internal scripts');
4040
})
4141
.then(() => cli.quit())

test/cli/start-cli.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const BREAK_MESSAGE = new RegExp('(?:' + [
1616
'exception', 'other', 'promiseRejection',
1717
].join('|') + ') in', 'i');
1818

19+
function isPreBreak(output) {
20+
return /Break on start/.test(output) && /1 \(function \(exports/.test(output);
21+
}
22+
1923
function startCLI(args, flags = []) {
2024
const child = spawn(process.execPath, [...flags, CLI, ...args]);
2125
let isFirstStdoutChunk = true;
@@ -101,13 +105,26 @@ function startCLI(args, flags = []) {
101105
waitForInitialBreak(timeout = 2000) {
102106
return this.waitFor(/break (?:on start )?in/i, timeout)
103107
.then(() => {
104-
if (/Break on start/.test(this.output)) {
108+
if (isPreBreak(this.output)) {
109+
console.log({output: this.output});
105110
return this.command('next', false)
106111
.then(() => this.waitFor(/break in/, timeout));
107112
}
108113
});
109114
},
110115

116+
get breakInfo() {
117+
const output = this.output;
118+
const breakMatch =
119+
output.match(/break (?:on start )?in ([^\n]+):(\d+)\n/i);
120+
121+
if (breakMatch === null) {
122+
throw new Error(
123+
`Could not find breakpoint info in ${JSON.stringify(output)}`);
124+
}
125+
return { filename: breakMatch[1], line: +breakMatch[2] };
126+
},
127+
111128
ctrlC() {
112129
return this.command('.interrupt');
113130
},
@@ -127,19 +144,24 @@ function startCLI(args, flags = []) {
127144
.map((match) => +match[1]);
128145
},
129146

130-
command(input, flush = true) {
147+
writeLine(input, flush = true) {
131148
if (flush) {
132149
this.flushOutput();
133150
}
151+
if (process.env.VERBOSE === '1') {
152+
process.stderr.write(`< ${input}\n`);
153+
}
134154
child.stdin.write(input);
135155
child.stdin.write('\n');
156+
},
157+
158+
command(input, flush = true) {
159+
this.writeLine(input, flush);
136160
return this.waitForPrompt();
137161
},
138162

139163
stepCommand(input) {
140-
this.flushOutput();
141-
child.stdin.write(input);
142-
child.stdin.write('\n');
164+
this.writeLine(input, true);
143165
return this
144166
.waitFor(BREAK_MESSAGE)
145167
.then(() => this.waitForPrompt());

test/cli/use-strict.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ test('for whiles that starts with strict directive', (t) => {
1717
return cli.waitForInitialBreak()
1818
.then(() => cli.waitForPrompt())
1919
.then(() => {
20+
const brk = cli.breakInfo;
2021
t.match(
21-
cli.output,
22-
/break in [^:]+:(?:1|2)[^\d]/,
22+
`${brk.line}`,
23+
/^(1|2)$/,
2324
'pauses either on strict directive or first "real" line');
2425
})
2526
.then(() => cli.quit())

0 commit comments

Comments
 (0)