From 4e68b541fd7ccd9fe1328d5b4dc93a3689aa505d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 24 Aug 2024 22:10:11 +0200 Subject: [PATCH] test: fix improper path to URL conversion PR-URL: https://github.com/nodejs/node/pull/54509 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/fixtures/permission/fs-read.js | 3 ++- .../test-diagnostics-channel-module-import-error.js | 6 ++---- test/parallel/test-diagnostics-channel-module-import.js | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/test/fixtures/permission/fs-read.js b/test/fixtures/permission/fs-read.js index 29594ca8b5d5a2..ddde4593204c82 100644 --- a/test/fixtures/permission/fs-read.js +++ b/test/fixtures/permission/fs-read.js @@ -5,10 +5,11 @@ const common = require('../../common'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); +const { pathToFileURL } = require('url'); const blockedFile = process.env.BLOCKEDFILE; const bufferBlockedFile = Buffer.from(process.env.BLOCKEDFILE); -const blockedFileURL = new URL('file://' + process.env.BLOCKEDFILE); +const blockedFileURL = pathToFileURL(process.env.BLOCKEDFILE); const blockedFolder = process.env.BLOCKEDFOLDER; const allowedFolder = process.env.ALLOWEDFOLDER; const regularFile = __filename; diff --git a/test/parallel/test-diagnostics-channel-module-import-error.js b/test/parallel/test-diagnostics-channel-module-import-error.js index f3518e8fc55ae6..08ac8d0d8ffb0c 100644 --- a/test/parallel/test-diagnostics-channel-module-import-error.js +++ b/test/parallel/test-diagnostics-channel-module-import-error.js @@ -2,6 +2,7 @@ const common = require('../common'); const assert = require('assert'); const dc = require('diagnostics_channel'); +const { pathToFileURL } = require('url'); const trace = dc.tracingChannel('module.import'); const events = []; @@ -30,10 +31,7 @@ trace.subscribe({ import('does-not-exist').then( common.mustNotCall(), common.mustCall((error) => { - let expectedParentURL = module.filename.replaceAll('\\', '/'); - expectedParentURL = common.isWindows ? - `file:///${expectedParentURL}` : - `file://${expectedParentURL}`; + const expectedParentURL = pathToFileURL(module.filename).href; // Verify order and contents of each event assert.deepStrictEqual(events, [ { diff --git a/test/parallel/test-diagnostics-channel-module-import.js b/test/parallel/test-diagnostics-channel-module-import.js index 51ca24ed3d4515..dcd821d3ac789c 100644 --- a/test/parallel/test-diagnostics-channel-module-import.js +++ b/test/parallel/test-diagnostics-channel-module-import.js @@ -2,6 +2,7 @@ const common = require('../common'); const assert = require('assert'); const dc = require('diagnostics_channel'); +const { pathToFileURL } = require('url'); const trace = dc.tracingChannel('module.import'); const events = []; @@ -29,10 +30,7 @@ trace.subscribe({ import('http').then( common.mustCall((result) => { - let expectedParentURL = module.filename.replaceAll('\\', '/'); - expectedParentURL = common.isWindows ? - `file:///${expectedParentURL}` : - `file://${expectedParentURL}`; + const expectedParentURL = pathToFileURL(module.filename).href; // Verify order and contents of each event assert.deepStrictEqual(events, [ {