| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 48c25b1 commit adb9280
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | + const { pathToFileURL } = require('url'); | ||
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | ||
| 5 | 6 | const relativePath = '../fixtures/es-modules/test-esm-ok.mjs'; | |
| 6 | - const absolutePath = require.resolve('../fixtures/es-modules/test-esm-ok.mjs'); | ||
| 7 | - const targetURL = new URL('file:///'); | ||
| 8 | - targetURL.pathname = absolutePath; | ||
| 7 | + const absolutePath = require.resolve(relativePath); | ||
| 8 | + const targetURL = pathToFileURL(absolutePath); | ||
| 9 | 9 | ||
| 10 | 10 | function expectModuleError(result, code, message) { | |
| 11 | 11 | Promise.resolve(result).catch(common.mustCall((error) => { | |
@@ -41,7 +41,7 @@ function expectFsNamespace(result) { | |||
| 41 | 41 | // expectOkNamespace(import(relativePath)); | |
| 42 | 42 | expectOkNamespace(eval(`import("${relativePath}")`)); | |
| 43 | 43 | expectOkNamespace(eval(`import("${relativePath}")`)); | |
| 44 | - expectOkNamespace(eval(`import("${targetURL}")`)); | ||
| 44 | + expectOkNamespace(eval(`import(${JSON.stringify(targetURL)})`)); | ||
| 45 | 45 | ||
| 46 | 46 | // Importing a built-in, both direct & via eval | |
| 47 | 47 | expectFsNamespace(import('fs')); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => { | |||
| 28 | 28 | fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), | |
| 29 | 29 | '--input-type=module', | |
| 30 | 30 | '--eval', | |
| 31 | - `import '${fixtures.fileURL('/es-modules/file.unknown')}'`, | ||
| 31 | + `import ${JSON.stringify(fixtures.fileURL('/es-modules/file.unknown'))}`, | ||
| 32 | 32 | ]); | |
| 33 | 33 | ||
| 34 | 34 | assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/); | |
@@ -142,7 +142,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => { | |||
| 142 | 142 | `import assert from 'node:assert'; | |
| 143 | 143 | await Promise.allSettled([ | |
| 144 | 144 | import('nonexistent/file.mjs'), | |
| 145 | - import('${fixtures.fileURL('/es-modules/file.unknown')}'), | ||
| 145 | + import(${JSON.stringify(fixtures.fileURL('/es-modules/file.unknown'))}), | ||
| 146 | 146 | import('esmHook/badReturnVal.mjs'), | |
| 147 | 147 | import('esmHook/format.false'), | |
| 148 | 148 | import('esmHook/format.true'), | |
@@ -170,7 +170,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => { | |||
| 170 | 170 | '--input-type=module', | |
| 171 | 171 | '--eval', | |
| 172 | 172 | `import assert from 'node:assert'; | |
| 173 | - await import('${fixtures.fileURL('/es-module-loaders/js-as-esm.js')}') | ||
| 173 | + await import(${JSON.stringify(fixtures.fileURL('/es-module-loaders/js-as-esm.js'))}) | ||
| 174 | 174 | .then((parsedModule) => { | |
| 175 | 175 | assert.strictEqual(typeof parsedModule, 'object'); | |
| 176 | 176 | assert.strictEqual(parsedModule.namedExport, 'named-export'); | |
@@ -191,7 +191,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => { | |||
| 191 | 191 | '--input-type=module', | |
| 192 | 192 | '--eval', | |
| 193 | 193 | `import assert from 'node:assert'; | |
| 194 | - await import('${fixtures.fileURL('/es-modules/file.ext')}') | ||
| 194 | + await import(${JSON.stringify(fixtures.fileURL('/es-modules/file.ext'))}) | ||
| 195 | 195 | .then((parsedModule) => { | |
| 196 | 196 | assert.strictEqual(typeof parsedModule, 'object'); | |
| 197 | 197 | const { default: defaultExport } = parsedModule; | |
@@ -258,7 +258,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => { | |||
| 258 | 258 | '--input-type=module', | |
| 259 | 259 | '--eval', | |
| 260 | 260 | `import assert from 'node:assert'; | |
| 261 | - await import('${fixtures.fileURL('/es-modules/stateful.mjs')}') | ||
| 261 | + await import(${JSON.stringify(fixtures.fileURL('/es-modules/stateful.mjs'))}) | ||
| 262 | 262 | .then(({ default: count }) => { | |
| 263 | 263 | assert.strictEqual(count(), 1); | |
| 264 | 264 | });`, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const common = require('../common'); | |||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const fs = require('fs'); | |
| 6 | 6 | const path = require('path'); | |
| 7 | + const { pathToFileURL } = require('url'); | ||
| 7 | 8 | ||
| 8 | 9 | const tmpdir = require('../common/tmpdir'); | |
| 9 | 10 | tmpdir.refresh(); | |
@@ -40,7 +41,7 @@ function handler(err, folder) { | |||
| 40 | 41 | ||
| 41 | 42 | // Test with URL object | |
| 42 | 43 | { | |
| 43 | - tmpdir.url = new URL(`file://${tmpdir.path}`); | ||
| 44 | + tmpdir.url = pathToFileURL(tmpdir.path); | ||
| 44 | 45 | const urljoin = (base, path) => new URL(path, base); | |
| 45 | 46 | ||
| 46 | 47 | const tmpFolder = fs.mkdtempSync(urljoin(tmpdir.url, 'foo.')); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,7 +58,7 @@ checkStack(err.stack); | |||
| 58 | 58 | // Verify that the stack is only decorated once for uncaught exceptions. | |
| 59 | 59 | const args = [ | |
| 60 | 60 | '-e', | |
| 61 | - `require('${badSyntaxPath}')`, | ||
| 61 | + `require(${JSON.stringify(badSyntaxPath)})`, | ||
| 62 | 62 | ]; | |
| 63 | 63 | const result = spawnSync(process.argv[0], args, { encoding: 'utf8' }); | |
| 64 | 64 | checkStack(result.stderr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,6 @@ child.on('exit', common.mustCall(() => { | |||
| 19 | 19 | ||
| 20 | 20 | child.stdin.write('const isObject = (obj) => obj.constructor === Object;\n'); | |
| 21 | 21 | child.stdin.write('isObject({});\n'); | |
| 22 | - child.stdin.write(`require('${fixture}').isObject({});\n`); | ||
| 22 | + child.stdin.write(`require(${JSON.stringify(fixture)}).isObject({});\n`); | ||
| 23 | 23 | child.stdin.write('.exit'); | |
| 24 | 24 | child.stdin.end(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ fs.writeFileSync(fakeModulePath, '', 'utf8'); | |||
| 22 | 22 | ||
| 23 | 23 | stream.on('open', () => { | |
| 24 | 24 | spawnSync(process.execPath, { | |
| 25 | - input: `require("${fakeModulePath.replace(/\\/g, '/')}")`, | ||
| 25 | + input: `require(${JSON.stringify(fakeModulePath)})`, | ||
| 26 | 26 | stdio: ['pipe', 'pipe', stream] | |
| 27 | 27 | }); | |
| 28 | 28 | const stderr = fs.readFileSync(stderrOutputPath, 'utf8').trim(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const { isMainThread } = require('worker_threads'); | |||
| 7 | 7 | ||
| 8 | 8 | if (isMainThread) { | |
| 9 | 9 | const CODE = 'const { Worker } = require(\'worker_threads\'); ' + | |
| 10 | - `new Worker('${__filename.replace(/\\/g, '/')}', { name: 'foo' })`; | ||
| 10 | + `new Worker(${JSON.stringify(__filename)}, { name: 'foo' })`; | ||
| 11 | 11 | const FILE_NAME = 'node_trace.1.log'; | |
| 12 | 12 | const tmpdir = require('../common/tmpdir'); | |
| 13 | 13 | tmpdir.refresh(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const { isMainThread } = require('worker_threads'); | |||
| 7 | 7 | ||
| 8 | 8 | if (isMainThread) { | |
| 9 | 9 | const CODE = 'const { Worker } = require(\'worker_threads\'); ' + | |
| 10 | - `new Worker('${__filename.replace(/\\/g, '/')}')`; | ||
| 10 | + `new Worker(${JSON.stringify(__filename)})`; | ||
| 11 | 11 | const FILE_NAME = 'node_trace.1.log'; | |
| 12 | 12 | const tmpdir = require('../common/tmpdir'); | |
| 13 | 13 | tmpdir.refresh(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ import { describe, it } from 'node:test'; | |||
| 7 | 7 | import { spawn } from 'node:child_process'; | |
| 8 | 8 | import { writeFileSync, readFileSync, mkdirSync } from 'node:fs'; | |
| 9 | 9 | import { inspect } from 'node:util'; | |
| 10 | + import { pathToFileURL } from 'node:url'; | ||
| 10 | 11 | import { createInterface } from 'node:readline'; | |
| 11 | 12 | ||
| 12 | 13 | if (common.isIBMi) | |
@@ -188,7 +189,7 @@ console.log("don't show me");`); | |||
| 188 | 189 | it('should watch changes to dependencies - cjs', async () => { | |
| 189 | 190 | const dependency = createTmpFile('module.exports = {};'); | |
| 190 | 191 | const file = createTmpFile(` | |
| 191 | - const dependency = require('${dependency.replace(/\\/g, '/')}'); | ||
| 192 | + const dependency = require(${JSON.stringify(dependency)}); | ||
| 192 | 193 | console.log(dependency); | |
| 193 | 194 | `); | |
| 194 | 195 | const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: dependency }); | |
@@ -206,7 +207,7 @@ console.log(dependency); | |||
| 206 | 207 | it('should watch changes to dependencies - esm', async () => { | |
| 207 | 208 | const dependency = createTmpFile('module.exports = {};'); | |
| 208 | 209 | const file = createTmpFile(` | |
| 209 | - import dependency from 'file://${dependency.replace(/\\/g, '/')}'; | ||
| 210 | + import dependency from ${JSON.stringify(pathToFileURL(dependency))}; | ||
| 210 | 211 | console.log(dependency); | |
| 211 | 212 | `, '.mjs'); | |
| 212 | 213 | const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: dependency }); | |
@@ -278,7 +279,7 @@ console.log(values.random); | |||
| 278 | 279 | skip: 'enable once --import is backported', | |
| 279 | 280 | }, async () => { | |
| 280 | 281 | const file = createTmpFile(); | |
| 281 | - const imported = `file://${createTmpFile('setImmediate(() => process.exit(0));')}`; | ||
| 282 | + const imported = pathToFileURL(createTmpFile('setImmediate(() => process.exit(0));')); | ||
| 282 | 283 | const args = ['--import', imported, file]; | |
| 283 | 284 | const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file, args }); | |
| 284 | 285 | ||
@@ -320,9 +321,9 @@ console.log(values.random); | |||
| 320 | 321 | it('should watch changes to previously missing ESM dependency', { | |
| 321 | 322 | skip: !supportsRecursive | |
| 322 | 323 | }, async () => { | |
| 323 | - const dependency = path.join(tmpdir.path, `${tmpFiles++}.mjs`); | ||
| 324 | - const relativeDependencyPath = `./${path.basename(dependency)}`; | ||
| 325 | - const dependant = createTmpFile(`import '${relativeDependencyPath}'`, '.mjs'); | ||
| 324 | + const relativeDependencyPath = `./${tmpFiles++}.mjs`; | ||
| 325 | + const dependency = path.join(tmpdir.path, relativeDependencyPath); | ||
| 326 | + const dependant = createTmpFile(`import ${JSON.stringify(relativeDependencyPath)}`, '.mjs'); | ||
| 326 | 327 | ||
| 327 | 328 | await failWriteSucceed({ file: dependant, watchedFile: dependency }); | |
| 328 | 329 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments