From 0f7e3f017fd624265a2bb118977594bbc8fe2cd4 Mon Sep 17 00:00:00 2001 From: "Edigleysson Silva (Edy)" Date: Sun, 6 Oct 2024 16:47:00 -0300 Subject: [PATCH] test_runner: assert entry is a valid object PR-URL: https://github.com/nodejs/node/pull/55231 Reviewed-By: Colin Ihrig Reviewed-By: Moshe Atlow Reviewed-By: Matteo Collina --- lib/internal/test_runner/test.js | 2 +- .../test-runner-enable-source-maps-issue.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-runner-enable-source-maps-issue.js diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 0bc24bae54496a..3a2a2b1383ff30 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -560,7 +560,7 @@ class Test extends AsyncResource { const map = lazyFindSourceMap(this.loc.file); const entry = map?.findEntry(this.loc.line - 1, this.loc.column - 1); - if (entry !== undefined) { + if (entry?.originalSource !== undefined) { this.loc.line = entry.originalLine + 1; this.loc.column = entry.originalColumn + 1; this.loc.file = entry.originalSource; diff --git a/test/parallel/test-runner-enable-source-maps-issue.js b/test/parallel/test-runner-enable-source-maps-issue.js new file mode 100644 index 00000000000000..95112ca4471c1f --- /dev/null +++ b/test/parallel/test-runner-enable-source-maps-issue.js @@ -0,0 +1,16 @@ +'use strict'; +require('../common'); +const assert = require('node:assert'); +const { spawnSync } = require('node:child_process'); +const { test } = require('node:test'); +const fixtures = require('../common/fixtures'); + +test('ensures --enable-source-maps does not throw an error', () => { + const fixture = fixtures.path('test-runner', 'coverage', 'stdin.test.js'); + const args = ['--enable-source-maps', fixture]; + + const result = spawnSync(process.execPath, args); + + assert.strictEqual(result.stderr.toString(), ''); + assert.strictEqual(result.status, 0); +});