From 90e2d5528d127d0b0618d8972fb69db5fe95236a 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 7c99999a68dfad..fcd3b7e98a5dd4 100644 --- a/test/parallel/test-fs-whatwg-url.js +++ b/test/parallel/test-fs-whatwg-url.js @@ -3,19 +3,9 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); const assert = require('assert'); -const path = require('path'); const fs = require('fs'); -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 });