From b2fa795159190e96bab2a4c13e91fab6e1aa8e6b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 5 Jul 2021 07:55:49 -0700 Subject: [PATCH] test: add test for debugger restart message issue Running "restart" in the debugger confusingly prints an out-of-date "Debugger listening on..." message before printing a second updated one. Refs: https://github.com/nodejs/node/issues/39272 PR-URL: https://github.com/nodejs/node/pull/39273 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- .../test-debugger-restart-message.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/known_issues/test-debugger-restart-message.js diff --git a/test/known_issues/test-debugger-restart-message.js b/test/known_issues/test-debugger-restart-message.js new file mode 100644 index 00000000000000..478806effbb39c --- /dev/null +++ b/test/known_issues/test-debugger-restart-message.js @@ -0,0 +1,57 @@ +'use strict'; + +// Refs: https://github.com/nodejs/node/issues/39272 + +const common = require('../common'); + +const assert = require('assert'); + +// When this is moved out of known_issues, this skip can be removed. +if (common.isOSX) { + assert.fail('does not fail reliably on macOS in CI'); +} + +// When this is moved out of known_issues, this can be removed and replaced with +// the commented-out use of common.skipIfInspectorDisabled() below. +if (!process.features.inspector) { + assert.fail('Known issues test should fail, so if the inspector is disabled'); +} + +// Will need to uncomment this when moved out of known_issues. +// common.skipIfInspectorDisabled(); + +// This can be reduced to 2 or even 1 (and the loop removed) once the debugger +// is fixed. It's set higher to make sure that the error is tripped reliably +// in CI. On most systems, the error will be tripped on the first test, but +// on a few platforms in CI, it needs to be many times. +const RESTARTS = 16; + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +// Using `restart` should result in only one "Connect/For help" message. +{ + const script = fixtures.path('debugger', 'three-lines.js'); + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + const listeningRegExp = /Debugger listening on/g; + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => { + assert.strictEqual(cli.output.match(listeningRegExp).length, 1); + }) + .then(async () => { + for (let i = 0; i < RESTARTS; i++) { + await cli.stepCommand('restart'); + assert.strictEqual(cli.output.match(listeningRegExp).length, 1); + } + }) + .then(() => cli.quit()) + .then(null, onFatal); +}