From c1cc29b25f2cddb5ae2153312255a30df89d688b Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 31 Jan 2024 16:06:00 +0300 Subject: [PATCH 1/9] test_runner: convert file URLs to paths in test enqueue method --- lib/internal/test_runner/tests_stream.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/tests_stream.js b/lib/internal/test_runner/tests_stream.js index f7730caac00fa7..a34f572c871261 100644 --- a/lib/internal/test_runner/tests_stream.js +++ b/lib/internal/test_runner/tests_stream.js @@ -71,13 +71,15 @@ class TestsStream extends Readable { } enqueue(nesting, loc, name) { + const file = loc.file.startsWith('file://') ? loc.file.substring(7) : loc.file; this[kEmitMessage]('test:enqueue', { __proto__: null, nesting, name, + file, ...loc, }); - } +} dequeue(nesting, loc, name) { this[kEmitMessage]('test:dequeue', { From 7e568bdb3c2f322dc6bc84818f2f319568cf2c15 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 31 Jan 2024 16:14:27 +0300 Subject: [PATCH 2/9] fix: lint --- lib/internal/test_runner/tests_stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/test_runner/tests_stream.js b/lib/internal/test_runner/tests_stream.js index a34f572c871261..5a421873a20961 100644 --- a/lib/internal/test_runner/tests_stream.js +++ b/lib/internal/test_runner/tests_stream.js @@ -79,7 +79,7 @@ class TestsStream extends Readable { file, ...loc, }); -} + } dequeue(nesting, loc, name) { this[kEmitMessage]('test:dequeue', { From dd15dcf90b5919808651d2c5edaceee0004befcb Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 31 Jan 2024 16:30:48 +0300 Subject: [PATCH 3/9] convert file URLs to paths and handle other events --- lib/internal/test_runner/test.js | 4 ++-- lib/internal/test_runner/tests_stream.js | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index ee2c345e7a0403..dbe83e718cd5cd 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -356,10 +356,10 @@ class Test extends AsyncResource { __proto__: null, line: loc[0], column: loc[1], - file: loc[2], + file: loc[2] ? fileURLToPath(loc[2]) : undefined, }; } - } + } matchesTestNamePatterns() { return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, this.name) !== null) || diff --git a/lib/internal/test_runner/tests_stream.js b/lib/internal/test_runner/tests_stream.js index 5a421873a20961..f7730caac00fa7 100644 --- a/lib/internal/test_runner/tests_stream.js +++ b/lib/internal/test_runner/tests_stream.js @@ -71,12 +71,10 @@ class TestsStream extends Readable { } enqueue(nesting, loc, name) { - const file = loc.file.startsWith('file://') ? loc.file.substring(7) : loc.file; this[kEmitMessage]('test:enqueue', { __proto__: null, nesting, name, - file, ...loc, }); } From 13da73840c210659b2d16f005a2db75247d748b5 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 31 Jan 2024 16:35:09 +0300 Subject: [PATCH 4/9] repair --- lib/internal/test_runner/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index dbe83e718cd5cd..36ef922a1598a5 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -58,6 +58,7 @@ const { const { setTimeout } = require('timers'); const { TIMEOUT_MAX } = require('internal/timers'); const { availableParallelism } = require('os'); +const { fileURLToPath } = require('url'); const { bigint: hrtime } = process.hrtime; const kCallbackAndPromisePresent = 'callbackAndPromisePresent'; const kCancelledByParent = 'cancelledByParent'; @@ -359,7 +360,7 @@ class Test extends AsyncResource { file: loc[2] ? fileURLToPath(loc[2]) : undefined, }; } - } + } matchesTestNamePatterns() { return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, this.name) !== null) || From 68b59da6acdfc922c628918fd9403af8ff0e5f23 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 31 Jan 2024 16:37:17 +0300 Subject: [PATCH 5/9] repair import --- lib/internal/test_runner/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 36ef922a1598a5..1a56c6903192c3 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -58,7 +58,7 @@ const { const { setTimeout } = require('timers'); const { TIMEOUT_MAX } = require('internal/timers'); const { availableParallelism } = require('os'); -const { fileURLToPath } = require('url'); +const { fileURLToPath } = require('internal/url'); const { bigint: hrtime } = process.hrtime; const kCallbackAndPromisePresent = 'callbackAndPromisePresent'; const kCancelledByParent = 'cancelledByParent'; From bfa03f676bf3ce1a5b6a73a97745354221110063 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Fri, 2 Feb 2024 22:23:05 +0300 Subject: [PATCH 6/9] feat: added test for all url test --- test/parallel/file-url-to-path-conversion.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/parallel/file-url-to-path-conversion.js diff --git a/test/parallel/file-url-to-path-conversion.js b/test/parallel/file-url-to-path-conversion.js new file mode 100644 index 00000000000000..894f7a19df060e --- /dev/null +++ b/test/parallel/file-url-to-path-conversion.js @@ -0,0 +1,20 @@ +const { fileURLToPath } = require('url'); +const assert = require('assert'); + +{ + const testCases = [ + 'file:///path/to/file1.js', + 'file:///C:/Users/Username/Documents/file2.js', + ]; + + testCases.forEach((url) => { + let parsedPath; + try { + parsedPath = fileURLToPath(url); + } catch (error) { + parsedPath = null; + } + + assert.ok(parsedPath !== null, `Failed to parse URL: ${url}`); + }); +} From 1ca5cb57d98c7cf724f5cd549c713227debf80ab Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Fri, 2 Feb 2024 22:31:07 +0300 Subject: [PATCH 7/9] fix: lint & repair error catch --- test/parallel/file-url-to-path-conversion.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/parallel/file-url-to-path-conversion.js b/test/parallel/file-url-to-path-conversion.js index 894f7a19df060e..33841823a1e9ad 100644 --- a/test/parallel/file-url-to-path-conversion.js +++ b/test/parallel/file-url-to-path-conversion.js @@ -1,3 +1,5 @@ +'use strict'; +require('../common'); const { fileURLToPath } = require('url'); const assert = require('assert'); @@ -11,10 +13,9 @@ const assert = require('assert'); let parsedPath; try { parsedPath = fileURLToPath(url); + assert.ok(parsedPath !== null, `Failed to parse URL: ${url}`); } catch (error) { - parsedPath = null; + throw new Error(`Failed to parse URL: ${url}. Error: ${error}`); } - - assert.ok(parsedPath !== null, `Failed to parse URL: ${url}`); }); } From 2146824927b4bebb8abc5f489e50bef05b502a8c Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 17 Feb 2024 11:14:32 +0300 Subject: [PATCH 8/9] feat: created normalizeFilePath method --- lib/internal/test_runner/test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 1a56c6903192c3..ddf709c14cdbdc 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -58,7 +58,6 @@ const { const { setTimeout } = require('timers'); const { TIMEOUT_MAX } = require('internal/timers'); const { availableParallelism } = require('os'); -const { fileURLToPath } = require('internal/url'); const { bigint: hrtime } = process.hrtime; const kCallbackAndPromisePresent = 'callbackAndPromisePresent'; const kCancelledByParent = 'cancelledByParent'; @@ -357,11 +356,19 @@ class Test extends AsyncResource { __proto__: null, line: loc[0], column: loc[1], - file: loc[2] ? fileURLToPath(loc[2]) : undefined, + file: this.normalizeFilePath(loc[2]), }; } } + normalizeFilePath(filePath) { + if (process.platform === 'win32') { + return 'file:///' + filePath.replace(/\\/g, '/'); + } else { + return filePath; + } + } + matchesTestNamePatterns() { return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, this.name) !== null) || this.parent?.matchesTestNamePatterns(); From 9c045bbaed506676ac1e7b4730dbd6fcf43989a8 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 17 Feb 2024 11:16:34 +0300 Subject: [PATCH 9/9] feat: refactor normalizeFilePath method --- lib/internal/test_runner/test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index ddf709c14cdbdc..8cd921e69de3bc 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -364,9 +364,8 @@ class Test extends AsyncResource { normalizeFilePath(filePath) { if (process.platform === 'win32') { return 'file:///' + filePath.replace(/\\/g, '/'); - } else { - return filePath; } + return filePath; } matchesTestNamePatterns() {