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

Address regressions due to changes in node #67

Merged
merged 1 commit into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/internal/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Path = require('path');
const Repl = require('repl');
const util = require('util');
const vm = require('vm');
const fileURLToPath = require('url').fileURLToPath;

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

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

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

const filename = filenameOrURL.startsWith('file://') ?
fileURLToPath(filenameOrURL) : filenameOrURL;

// Change path to relative, if possible
if (filename.indexOf(dir) === 0) {
return filename.slice(dir.length);
Expand Down
6 changes: 3 additions & 3 deletions test/cli/break.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ test('stepping through breakpoints', (t) => {
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
cli.output,
`break in ${script}:1`,
cli.breakInfo,
{ filename: script, line: 1 },
'pauses in the first line of the script');
t.match(
cli.output,
/> 1 \(function \([^)]+\) \{ const x = 10;/,
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
'shows the source and marks the current line');
})
.then(() => cli.stepCommand('n'))
Expand Down
8 changes: 4 additions & 4 deletions test/cli/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('break on (uncaught) exceptions', (t) => {
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.breakInfo, { filename: script, line: 1 });
})
// making sure it will die by default:
.then(() => cli.command('c'))
Expand All @@ -28,7 +28,7 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.stepCommand('r'))
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.breakInfo, { filename: script, line: 1 });
})
.then(() => cli.command('breakOnException'))
.then(() => cli.stepCommand('c'))
Expand All @@ -45,7 +45,7 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.stepCommand('r')) // also, the setting survives the restart
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.breakInfo, { filename: script, line: 1 });
})
.then(() => cli.stepCommand('c'))
.then(() => {
Expand All @@ -57,7 +57,7 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.stepCommand('r'))
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.breakInfo, { filename: script, line: 1 });
})
.then(() => cli.command('c'))
// TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore
Expand Down
16 changes: 8 additions & 8 deletions test/cli/launch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,23 @@ test('run after quit / restart', (t) => {
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
cli.output,
`break in ${script}:1`,
cli.breakInfo,
{ filename: script, line: 1 },
'is back at the beginning');
})
.then(() => cli.stepCommand('n'))
.then(() => {
t.match(
cli.output,
`break in ${script}:2`,
cli.breakInfo,
{ filename: script, line: 2 },
'steps to the 2nd line');
})
.then(() => cli.stepCommand('restart'))
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(
cli.output,
`break in ${script}:1`,
cli.breakInfo,
{ filename: script, line: 1 },
'is back at the beginning');
})
.then(() => cli.command('kill'))
Expand All @@ -167,8 +167,8 @@ test('run after quit / restart', (t) => {
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
cli.output,
`break in ${script}:1`,
cli.breakInfo,
{ filename: script, line: 1 },
'is back at the beginning');
})
.then(() => cli.quit())
Expand Down
2 changes: 1 addition & 1 deletion test/cli/low-level.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('Debugger agent direct access', (t) => {
.then(() => {
t.match(
cli.output,
/scriptSource: '\(function \(/);
/scriptSource:[ \n]*'(?:\(function \(|let x = 1)/);
t.match(
cli.output,
/let x = 1;/);
Expand Down
8 changes: 4 additions & 4 deletions test/cli/preserve-breaks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ test('run after quit / restart', (t) => {
.then(() => cli.stepCommand('c')) // hit line 2
.then(() => cli.stepCommand('c')) // hit line 3
.then(() => {
t.match(cli.output, `break in ${script}:3`);
t.match(cli.breakInfo, { filename: script, line: 3 });
})
.then(() => cli.command('restart'))
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.breakInfo, { filename: script, line: 1 });
})
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `break in ${script}:2`);
t.match(cli.breakInfo, { filename: script, line: 2 });
})
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `break in ${script}:3`);
t.match(cli.breakInfo, { filename: script, line: 3 });
})
.then(() => cli.command('breakpoints'))
.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('list scripts', (t) => {
'lists the user script');
t.notMatch(
cli.output,
/\d+: module\.js <native>/,
/\d+: buffer\.js <native>/,
'omits node-internal scripts');
})
.then(() => cli.command('scripts(true)'))
Expand All @@ -35,7 +35,7 @@ test('list scripts', (t) => {
'lists the user script');
t.match(
cli.output,
/\d+: module\.js <native>/,
/\d+: buffer\.js <native>/,
'includes node-internal scripts');
})
.then(() => cli.quit())
Expand Down
31 changes: 26 additions & 5 deletions test/cli/start-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const BREAK_MESSAGE = new RegExp('(?:' + [
'exception', 'other', 'promiseRejection',
].join('|') + ') in', 'i');

function isPreBreak(output) {
return /Break on start/.test(output) && /1 \(function \(exports/.test(output);
}

function startCLI(args, flags = []) {
const child = spawn(process.execPath, [...flags, CLI, ...args]);
let isFirstStdoutChunk = true;
Expand Down Expand Up @@ -101,13 +105,25 @@ function startCLI(args, flags = []) {
waitForInitialBreak(timeout = 2000) {
return this.waitFor(/break (?:on start )?in/i, timeout)
.then(() => {
if (/Break on start/.test(this.output)) {
if (isPreBreak(this.output)) {
return this.command('next', false)
.then(() => this.waitFor(/break in/, timeout));
}
});
},

get breakInfo() {
const output = this.output;
const breakMatch =
output.match(/break (?:on start )?in ([^\n]+):(\d+)\n/i);

if (breakMatch === null) {
throw new Error(
`Could not find breakpoint info in ${JSON.stringify(output)}`);
}
return { filename: breakMatch[1], line: +breakMatch[2] };
},

ctrlC() {
return this.command('.interrupt');
},
Expand All @@ -127,19 +143,24 @@ function startCLI(args, flags = []) {
.map((match) => +match[1]);
},

command(input, flush = true) {
writeLine(input, flush = true) {
if (flush) {
this.flushOutput();
}
if (process.env.VERBOSE === '1') {
process.stderr.write(`< ${input}\n`);
}
child.stdin.write(input);
child.stdin.write('\n');
},

command(input, flush = true) {
this.writeLine(input, flush);
return this.waitForPrompt();
},

stepCommand(input) {
this.flushOutput();
child.stdin.write(input);
child.stdin.write('\n');
this.writeLine(input, true);
return this
.waitFor(BREAK_MESSAGE)
.then(() => this.waitForPrompt());
Expand Down
5 changes: 3 additions & 2 deletions test/cli/use-strict.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ test('for whiles that starts with strict directive', (t) => {
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
const brk = cli.breakInfo;
t.match(
cli.output,
/break in [^:]+:(?:1|2)[^\d]/,
`${brk.line}`,
/^(1|2)$/,
'pauses either on strict directive or first "real" line');
})
.then(() => cli.quit())
Expand Down