From eeddbfae6ccc1ec6aabd2659e96f76400998e658 Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Tue, 22 Aug 2023 01:42:03 +0900 Subject: [PATCH] test,benchmark: use `tmpdir.fileURL()` PR-URL: https://github.com/nodejs/node/pull/49138 Refs: https://github.com/nodejs/node/pull/49040 Reviewed-By: Luigi Pinca --- benchmark/esm/esm-loader-import.js | 4 +--- test/es-module/test-esm-dynamic-import-mutating-fs.js | 5 +---- test/es-module/test-esm-dynamic-import-mutating-fs.mjs | 5 +---- test/node-api/test_policy/test_policy.js | 5 ----- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/benchmark/esm/esm-loader-import.js b/benchmark/esm/esm-loader-import.js index 9967cd95275..025afbf616b 100644 --- a/benchmark/esm/esm-loader-import.js +++ b/benchmark/esm/esm-loader-import.js @@ -2,13 +2,11 @@ // general startup, does not test lazy operations 'use strict'; const fs = require('node:fs'); -const path = require('node:path'); const common = require('../common.js'); const tmpdir = require('../../test/common/tmpdir.js'); -const { pathToFileURL } = require('node:url'); -const benchmarkDirectory = pathToFileURL(path.resolve(tmpdir.path, 'benchmark-import')); +const benchmarkDirectory = tmpdir.fileURL('benchmark-import'); const configs = { n: [1e3], diff --git a/test/es-module/test-esm-dynamic-import-mutating-fs.js b/test/es-module/test-esm-dynamic-import-mutating-fs.js index 09cbffe4879..b3e3bd899a9 100644 --- a/test/es-module/test-esm-dynamic-import-mutating-fs.js +++ b/test/es-module/test-esm-dynamic-import-mutating-fs.js @@ -4,12 +4,9 @@ const tmpdir = require('../common/tmpdir'); const assert = require('node:assert'); const fs = require('node:fs/promises'); -const { pathToFileURL } = require('node:url'); tmpdir.refresh(); -const tmpDir = pathToFileURL(tmpdir.path); - -const target = new URL(`./${Math.random()}.mjs`, tmpDir); +const target = tmpdir.fileURL(`${Math.random()}.mjs`); (async () => { diff --git a/test/es-module/test-esm-dynamic-import-mutating-fs.mjs b/test/es-module/test-esm-dynamic-import-mutating-fs.mjs index 7eb79337065..74a75ddd1c4 100644 --- a/test/es-module/test-esm-dynamic-import-mutating-fs.mjs +++ b/test/es-module/test-esm-dynamic-import-mutating-fs.mjs @@ -4,12 +4,9 @@ import tmpdir from '../common/tmpdir.js'; import assert from 'node:assert'; import fs from 'node:fs/promises'; import { execPath } from 'node:process'; -import { pathToFileURL } from 'node:url'; tmpdir.refresh(); -const tmpDir = pathToFileURL(tmpdir.path); - -const target = new URL(`./${Math.random()}.mjs`, tmpDir); +const target = tmpdir.fileURL(`${Math.random()}.mjs`); await assert.rejects(import(target), { code: 'ERR_MODULE_NOT_FOUND' }); diff --git a/test/node-api/test_policy/test_policy.js b/test/node-api/test_policy/test_policy.js index 428dd905c2e..f14ceff3c45 100644 --- a/test/node-api/test_policy/test_policy.js +++ b/test/node-api/test_policy/test_policy.js @@ -23,11 +23,6 @@ const policyFilepath = tmpdir.resolve('policy'); const depFilepath = require.resolve(`./build/${common.buildType}/binding.node`); const depURL = pathToFileURL(depFilepath); -const tmpdirURL = pathToFileURL(tmpdir.path); -if (!tmpdirURL.pathname.endsWith('/')) { - tmpdirURL.pathname += '/'; -} - const depBody = fs.readFileSync(depURL); function writePolicy(...resources) { const manifest = { resources: {} };