From 3d58e49208399ed146d987fb203fefb3292a4508 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 3 Aug 2023 23:36:13 +0200 Subject: [PATCH] test: use `fixtures.fileURL` when appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/48990 Reviewed-By: Michaƫl Zasso Reviewed-By: Chemi Atlow Reviewed-By: Luigi Pinca --- test/parallel/test-fs-whatwg-url.js | 12 +----------- test/parallel/test-module-create-require.js | 5 ++--- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js index 829cfa92fafebd..5e9ea98a5820ed 100644 --- a/test/parallel/test-fs-whatwg-url.js +++ b/test/parallel/test-fs-whatwg-url.js @@ -3,20 +3,10 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); const assert = require('assert'); -const path = require('path'); const fs = require('fs'); const os = require('os'); -function pathToFileURL(p) { - if (!path.isAbsolute(p)) - throw new Error('Path must be absolute'); - if (common.isWindows && p.startsWith('\\\\')) - p = p.slice(2); - return new URL(`file://${p}`); -} - -const p = path.resolve(fixtures.fixturesDir, 'a.js'); -const url = pathToFileURL(p); +const url = fixtures.fileURL('a.js'); assert(url instanceof URL); diff --git a/test/parallel/test-module-create-require.js b/test/parallel/test-module-create-require.js index e0e34e9f127bd3..30ebf96652390d 100644 --- a/test/parallel/test-module-create-require.js +++ b/test/parallel/test-module-create-require.js @@ -1,13 +1,12 @@ 'use strict'; require('../common'); +const fixtures = require('../common/fixtures'); const assert = require('assert'); -const path = require('path'); const { createRequire } = require('module'); -const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js'); -const u = new URL(`file://${p}`); +const u = fixtures.fileURL('fake.js'); const reqToo = createRequire(u); assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });