From b4900497a71c89626853d150d9a25c03d86a30aa Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 7 Mar 2024 22:03:58 -0500 Subject: [PATCH] test_runner: use paths for test locations This commit transforms test locations to paths when V8 provides file URLs (which seems to be for ESM files). Fixes: https://github.com/nodejs/node/issues/51610 PR-URL: https://github.com/nodejs/node/pull/52010 Fixes: https://github.com/nodejs/node/issues/51392 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Marco Ippolito Reviewed-By: Chengzhong Wu Reviewed-By: Chemi Atlow Reviewed-By: Moshe Atlow --- lib/internal/test_runner/test.js | 6 ++++++ .../test-runner/output/source_mapped_locations.snapshot | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 635520783dad9a..80af0f9d978637 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -14,6 +14,7 @@ const { PromisePrototypeThen, PromiseResolve, SafePromisePrototypeFinally, + StringPrototypeStartsWith, StringPrototypeTrim, ReflectApply, RegExpPrototypeExec, @@ -58,6 +59,7 @@ const { } = require('internal/validators'); const { setTimeout } = require('timers'); const { TIMEOUT_MAX } = require('internal/timers'); +const { fileURLToPath } = require('internal/url'); const { availableParallelism } = require('os'); const { bigint: hrtime } = process.hrtime; const kCallbackAndPromisePresent = 'callbackAndPromisePresent'; @@ -383,6 +385,10 @@ class Test extends AsyncResource { this.loc.file = entry.originalSource; } } + + if (StringPrototypeStartsWith(this.loc.file, 'file://')) { + this.loc.file = fileURLToPath(this.loc.file); + } } } diff --git a/test/fixtures/test-runner/output/source_mapped_locations.snapshot b/test/fixtures/test-runner/output/source_mapped_locations.snapshot index c7baee728d0218..24c3ee8d113446 100644 --- a/test/fixtures/test-runner/output/source_mapped_locations.snapshot +++ b/test/fixtures/test-runner/output/source_mapped_locations.snapshot @@ -3,7 +3,7 @@ TAP version 13 not ok 1 - fails --- duration_ms: * - location: 'file:///test/fixtures/test-runner/output/source_mapped_locations.ts:5:1' + location: '/test/fixtures/test-runner/output/source_mapped_locations.ts:5:1' failureType: 'testCodeFailure' error: |- Expected values to be strictly equal: