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
42 changes: 39 additions & 3 deletions test/common/debugger-probe.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
'use strict';

const assert = require('assert');
const fixtures = require('./fixtures');
const path = require('path');

function debuggerFixturePath(name) {
return path.relative(process.cwd(), fixtures.path('debugger', name));
}

function escapeRegex(string) {
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
// Work around a pre-existing inspector issue: if the debuggee exits too quickly
Comment thread
JakobJingleheimer marked this conversation as resolved.
// the inspector can segfault while tearing down. For now normalize the segfault
// back to the expected terminal event (e.g. "completed" or "miss")
// until the upstream bug is fixed.
// See https://github.com/nodejs/node/issues/62765
// https://github.com/nodejs/node/issues/58245
const probeTargetExitSignal = 'SIGSEGV';

function assertProbeJson(output, expected) {
const normalized = JSON.parse(output);
const lastResult = normalized.results?.[normalized.results.length - 1];

if (lastResult?.event === 'error' &&
lastResult.error?.code === 'probe_target_exit' &&
lastResult.error?.signal === probeTargetExitSignal) {
// Log to facilitate debugging if this normalization is occurring.
console.log('Normalizing trailing SIGSEGV in JSON probe output');
normalized.results[normalized.results.length - 1] = expected.results.at(-1);
}

assert.deepStrictEqual(normalized, expected);
}

function assertProbeText(output, expected) {
const signalPrefix = `Target exited with signal ${probeTargetExitSignal}`;
const idx = output.indexOf(signalPrefix);
let normalized;
if (idx !== -1) {
// Log to facilitate debugging if this normalization is occurring.
console.log('Normalizing trailing SIGSEGV in text probe output');
const lineStart = output.lastIndexOf('\n', idx);
normalized = (lineStart === -1 ? '' : output.slice(0, lineStart)) + '\nCompleted';
} else {
normalized = output;
}
assert.strictEqual(normalized, expected);
}

module.exports = {
escapeRegex,
assertProbeJson,
assertProbeText,
missScript: debuggerFixturePath('probe-miss.js'),
probeScript: debuggerFixturePath('probe.js'),
throwScript: debuggerFixturePath('probe-throw.js'),
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-debugger-probe-child-inspect-port-zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeScript } = require('../common/debugger-probe');
const { assertProbeJson, probeScript } = require('../common/debugger-probe');

spawnSyncAndAssert(process.execPath, [
'inspect',
Expand All @@ -18,7 +17,7 @@ spawnSyncAndAssert(process.execPath, [
probeScript,
], {
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [{
expr: 'finalValue',
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-debugger-probe-global-option-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeScript } = require('../common/debugger-probe');
const { assertProbeJson, probeScript } = require('../common/debugger-probe');

spawnSyncAndAssert(process.execPath, [
'inspect',
Expand All @@ -16,7 +15,7 @@ spawnSyncAndAssert(process.execPath, [
probeScript,
], {
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [{
expr: 'finalValue',
Expand Down
8 changes: 5 additions & 3 deletions test/parallel/test-debugger-probe-json-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeTypesScript } = require('../common/debugger-probe');
const {
assertProbeJson,
probeTypesScript,
} = require('../common/debugger-probe');

const location = `${probeTypesScript}:17`;

Expand All @@ -23,7 +25,7 @@ spawnSyncAndAssert(process.execPath, [
probeTypesScript,
], {
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [
{ expr: 'objectValue', target: [probeTypesScript, 17] },
Expand Down
8 changes: 5 additions & 3 deletions test/parallel/test-debugger-probe-json-special-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeTypesScript } = require('../common/debugger-probe');
const {
assertProbeJson,
probeTypesScript,
} = require('../common/debugger-probe');

const location = `${probeTypesScript}:17`;

Expand Down Expand Up @@ -38,7 +40,7 @@ spawnSyncAndAssert(process.execPath, [
probeTypesScript,
], {
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [
{ expr: 'stringValue', target: [probeTypesScript, 17] },
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-debugger-probe-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeScript } = require('../common/debugger-probe');
const { assertProbeJson, probeScript } = require('../common/debugger-probe');

spawnSyncAndAssert(process.execPath, [
'inspect',
Expand All @@ -20,7 +19,7 @@ spawnSyncAndAssert(process.execPath, [
probeScript,
], {
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [
{ expr: 'index', target: [probeScript, 8] },
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-debugger-probe-miss.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { missScript } = require('../common/debugger-probe');
const { assertProbeJson, missScript } = require('../common/debugger-probe');

spawnSyncAndAssert(process.execPath, [
'inspect',
Expand All @@ -16,7 +15,7 @@ spawnSyncAndAssert(process.execPath, [
missScript,
], {
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [{ expr: '42', target: [missScript, 99] }],
results: [{
Expand Down
8 changes: 5 additions & 3 deletions test/parallel/test-debugger-probe-text-special-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeTypesScript } = require('../common/debugger-probe');
const {
assertProbeText,
probeTypesScript,
} = require('../common/debugger-probe');

const location = `${probeTypesScript}:17`;

Expand Down Expand Up @@ -37,7 +39,7 @@ spawnSyncAndAssert(process.execPath, [
probeTypesScript,
], {
stdout(output) {
assert.strictEqual(output, [
assertProbeText(output, [
`Hit 1 at ${location}`,
' stringValue = "hello"',
`Hit 1 at ${location}`,
Expand Down
11 changes: 5 additions & 6 deletions test/parallel/test-debugger-probe-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndAssert } = require('../common/child_process');
const { probeScript } = require('../common/debugger-probe');
const { assertProbeText, probeScript } = require('../common/debugger-probe');

spawnSyncAndAssert(process.execPath, [
'inspect',
Expand All @@ -15,10 +14,10 @@ spawnSyncAndAssert(process.execPath, [
probeScript,
], {
stdout(output) {
assert.strictEqual(output,
`Hit 1 at ${probeScript}:12\n` +
' finalValue = 81\n' +
'Completed');
assertProbeText(output,
`Hit 1 at ${probeScript}:12\n` +
' finalValue = 81\n' +
'Completed');
},
trim: true,
});
5 changes: 2 additions & 3 deletions test/parallel/test-debugger-probe-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSyncAndExit } = require('../common/child_process');
const { timeoutScript } = require('../common/debugger-probe');
const { assertProbeJson, timeoutScript } = require('../common/debugger-probe');

spawnSyncAndExit(process.execPath, [
'inspect',
Expand All @@ -19,7 +18,7 @@ spawnSyncAndExit(process.execPath, [
signal: null,
status: 1,
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
assertProbeJson(output, {
v: 1,
probes: [{ expr: '1', target: [timeoutScript, 99] }],
results: [{
Expand Down
Loading