Skip to content

Commit 02d664b

Browse files
aduh95RafaelGSS
authored andcommitted
test: fix improper path to URL conversion
PR-URL: #54509 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1800a58 commit 02d664b

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

test/fixtures/permission/fs-read.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ const common = require('../../common');
55
const assert = require('assert');
66
const fs = require('fs');
77
const path = require('path');
8+
const { pathToFileURL } = require('url');
89

910
const blockedFile = process.env.BLOCKEDFILE;
1011
const bufferBlockedFile = Buffer.from(process.env.BLOCKEDFILE);
11-
const blockedFileURL = new URL('file://' + process.env.BLOCKEDFILE);
12+
const blockedFileURL = pathToFileURL(process.env.BLOCKEDFILE);
1213
const blockedFolder = process.env.BLOCKEDFOLDER;
1314
const allowedFolder = process.env.ALLOWEDFOLDER;
1415
const regularFile = __filename;

test/parallel/test-diagnostics-channel-module-import-error.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const dc = require('diagnostics_channel');
5+
const { pathToFileURL } = require('url');
56

67
const trace = dc.tracingChannel('module.import');
78
const events = [];
@@ -30,10 +31,7 @@ trace.subscribe({
3031
import('does-not-exist').then(
3132
common.mustNotCall(),
3233
common.mustCall((error) => {
33-
let expectedParentURL = module.filename.replaceAll('\\', '/');
34-
expectedParentURL = common.isWindows ?
35-
`file:///${expectedParentURL}` :
36-
`file://${expectedParentURL}`;
34+
const expectedParentURL = pathToFileURL(module.filename).href;
3735
// Verify order and contents of each event
3836
assert.deepStrictEqual(events, [
3937
{

test/parallel/test-diagnostics-channel-module-import.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const dc = require('diagnostics_channel');
5+
const { pathToFileURL } = require('url');
56

67
const trace = dc.tracingChannel('module.import');
78
const events = [];
@@ -29,10 +30,7 @@ trace.subscribe({
2930

3031
import('http').then(
3132
common.mustCall((result) => {
32-
let expectedParentURL = module.filename.replaceAll('\\', '/');
33-
expectedParentURL = common.isWindows ?
34-
`file:///${expectedParentURL}` :
35-
`file://${expectedParentURL}`;
33+
const expectedParentURL = pathToFileURL(module.filename).href;
3634
// Verify order and contents of each event
3735
assert.deepStrictEqual(events, [
3836
{

0 commit comments

Comments
 (0)