Skip to content
Open
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
8 changes: 6 additions & 2 deletions test/parallel/test-debugger-extract-function-name.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import startCLI from '../common/debugger.js';

import assert from 'assert';

const cli = startCLI([fixtures.path('debugger', 'three-lines.js')]);
const env = {
...process.env,
NODE_INSPECT_RESUME_ON_START: '1',
};
const cli = startCLI(
[fixtures.path('debugger', 'alive.js')], [], { env });

try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('exec a = function func() {}; a;');
assert.match(cli.output, /\[Function: func\]/);
Expand Down
30 changes: 21 additions & 9 deletions test/parallel/test-repl-user-error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ const { PassThrough } = require('node:stream');
const { once } = require('node:events');
const test = require('node:test');
const { spawn } = require('node:child_process');
const vm = require('node:vm');

common.skipIfInspectorDisabled();

function evaluate(code, context, filename, callback) {
try {
callback(null, vm.runInContext(code, context, { filename }));
} catch (err) {
callback(err);
}
}

function* generateCases() {
for (const async of [false, true]) {
for (const handleErrorReturn of ['ignore', 'print', 'unhandled', 'badvalue']) {
Expand All @@ -23,13 +32,12 @@ function* generateCases() {

for (const { async, handleErrorReturn } of generateCases()) {
test(`async: ${async}, handleErrorReturn: ${handleErrorReturn}`, async () => {
let err;
const options = {
input: new PassThrough(),
output: new PassThrough().setEncoding('utf8'),
handleError: common.mustCall((e) => {
err = e;
queueMicrotask(() => repl.emit('handled-error'));
eval: evaluate,
handleError: common.mustCall((err) => {
queueMicrotask(() => repl.emit('handled-error', err));
return handleErrorReturn;
})
};
Expand All @@ -45,13 +53,16 @@ for (const { async, handleErrorReturn } of generateCases()) {
let outputString = '';
options.output.on('data', (chunk) => { outputString += chunk; });

const inputString = async ?
'setImmediate(() => { throw new Error("testerror") })\n42\n' :
'throw new Error("testerror")\n42\n';
options.input.end(inputString);
const errorInput = async ?
'setImmediate(() => { throw new Error("testerror") })\n' :
'throw new Error("testerror")\n';
const handledErrorEvent = once(repl, 'handled-error');
options.input.write(errorInput);

await once(repl, 'handled-error');
const [err] = await handledErrorEvent;
assert.strictEqual(err.message, 'testerror');
const exitEvent = once(repl, 'exit');
options.input.end('42\n');
while (!/42/.test(outputString)) {
await once(options.output, 'data');
}
Expand All @@ -66,6 +77,7 @@ for (const { async, handleErrorReturn } of generateCases()) {
const [uncaughtErr] = await uncaughtExceptionEvent;
assert.strictEqual(uncaughtErr, err);
}
await exitEvent;
});
}

Expand Down
Loading