| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,44 +1,44 @@ | |||
| 1 | - // Flags: --loader ./test/fixtures/es-module-loaders/hook-resolve-type.mjs | ||
| 2 | - import { allowGlobals } from '../common/index.mjs'; | ||
| 1 | + import { spawnPromisified } from '../common/index.mjs'; | ||
| 2 | + import * as tmpdir from '../common/tmpdir.js'; | ||
| 3 | 3 | import * as fixtures from '../common/fixtures.mjs'; | |
| 4 | - import { strict as assert } from 'assert'; | ||
| 5 | - import * as fs from 'fs'; | ||
| 6 | - | ||
| 7 | - allowGlobals(global.getModuleTypeStats); | ||
| 8 | - | ||
| 9 | - const { importedESM: importedESMBefore, | ||
| 10 | - importedCJS: importedCJSBefore } = await global.getModuleTypeStats(); | ||
| 11 | - | ||
| 12 | - const basePath = | ||
| 13 | - new URL('./node_modules/', import.meta.url); | ||
| 14 | - | ||
| 15 | - const rel = (file) => new URL(file, basePath); | ||
| 16 | - const createDir = (path) => { | ||
| 17 | - if (!fs.existsSync(path)) { | ||
| 18 | - fs.mkdirSync(path); | ||
| 19 | - } | ||
| 20 | - }; | ||
| 4 | + import { deepStrictEqual } from 'node:assert'; | ||
| 5 | + import { mkdir, rm, cp } from 'node:fs/promises'; | ||
| 6 | + import { execPath } from 'node:process'; | ||
| 21 | 7 | ||
| 8 | + const base = tmpdir.fileURL(`test-esm-loader-resolve-type-${(Math.random() * Date.now()).toFixed(0)}`); | ||
| 22 | 9 | const moduleName = 'module-counter-by-type'; | |
| 23 | - const moduleDir = rel(`${moduleName}`); | ||
| 10 | + const moduleURL = new URL(`${base}/node_modules/${moduleName}`); | ||
| 24 | 11 | try { | |
| 25 | - createDir(basePath); | ||
| 26 | - createDir(moduleDir); | ||
| 27 | - fs.cpSync( | ||
| 28 | - fixtures.path('es-modules', moduleName), | ||
| 29 | - moduleDir, | ||
| 12 | + await mkdir(moduleURL, { recursive: true }); | ||
| 13 | + await cp( | ||
| 14 | + fixtures.path('es-modules', 'module-counter-by-type'), | ||
| 15 | + moduleURL, | ||
| 30 | 16 | { recursive: true } | |
| 31 | 17 | ); | |
| 32 | 18 | ||
| 33 | - | ||
| 34 | - await import(`${moduleName}`); | ||
| 19 | + deepStrictEqual(await spawnPromisified( | ||
| 20 | + execPath, | ||
| 21 | + [ | ||
| 22 | + '--no-warnings', | ||
| 23 | + '--input-type=module', | ||
| 24 | + '--eval', | ||
| 25 | + `import { getModuleTypeStats } from ${JSON.stringify(fixtures.fileURL('es-module-loaders', 'hook-resolve-type.mjs'))}; | ||
| 26 | + const before = getModuleTypeStats(); | ||
| 27 | + await import(${JSON.stringify(moduleName)}); | ||
| 28 | + const after = getModuleTypeStats(); | ||
| 29 | + console.log(JSON.stringify({ before, after }));`, | ||
| 30 | + ], | ||
| 31 | + { cwd: base }, | ||
| 32 | + ), { | ||
| 33 | + stderr: '', | ||
| 34 | + stdout: JSON.stringify({ | ||
| 35 | + before: { importedESM: 0, importedCJS: 0 }, | ||
| 36 | + // Dynamic import in the eval script should increment ESM counter but not CJS counter | ||
| 37 | + after: { importedESM: 1, importedCJS: 0 }, | ||
| 38 | + }) + '\n', | ||
| 39 | + code: 0, | ||
| 40 | + signal: null, | ||
| 41 | + }); | ||
| 35 | 42 | } finally { | |
| 36 | - fs.rmSync(basePath, { recursive: true, force: true }); | ||
| 43 | + await rm(base, { recursive: true, force: true }); | ||
| 37 | 44 | } | |
| 38 | - | ||
| 39 | - const { importedESM: importedESMAfter, | ||
| 40 | - importedCJS: importedCJSAfter } = await global.getModuleTypeStats(); | ||
| 41 | - | ||
| 42 | - // Dynamic import above should increment ESM counter but not CJS counter | ||
| 43 | - assert.strictEqual(importedESMBefore + 1, importedESMAfter); | ||
| 44 | - assert.strictEqual(importedCJSBefore, importedCJSAfter); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // Flags: --experimental-loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs | ||
| 1 | + // Flags: --import ./test/fixtures/es-module-loaders/builtin-named-exports.mjs | ||
| 2 | 2 | import '../common/index.mjs'; | |
| 3 | 3 | import { readFile, __fromLoader } from 'fs'; | |
| 4 | 4 | import assert from 'assert'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,16 +1,9 @@ | |||
| 1 | - import module from 'module'; | ||
| 2 | - | ||
| 3 | - const GET_BUILTIN = `$__get_builtin_hole_${Date.now()}`; | ||
| 4 | - | ||
| 5 | - export function globalPreload() { | ||
| 6 | - return `Object.defineProperty(globalThis, ${JSON.stringify(GET_BUILTIN)}, { | ||
| 7 | - value: (builtinName) => { | ||
| 8 | - return getBuiltin(builtinName); | ||
| 9 | - }, | ||
| 10 | - enumerable: false, | ||
| 11 | - configurable: false, | ||
| 12 | - }); | ||
| 13 | - `; | ||
| 1 | + import module from 'node:module'; | ||
| 2 | + | ||
| 3 | + /** @type {string} */ | ||
| 4 | + let GET_BUILTIN; | ||
| 5 | + export function initialize(data) { | ||
| 6 | + GET_BUILTIN = data.GET_BUILTIN; | ||
| 14 | 7 | } | |
| 15 | 8 | ||
| 16 | 9 | export async function resolve(specifier, context, next) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + import * as fixtures from '../../common/fixtures.mjs'; | ||
| 2 | + import { createRequire, register } from 'node:module'; | ||
| 3 | + | ||
| 4 | + const require = createRequire(import.meta.url); | ||
| 5 | + | ||
| 6 | + const GET_BUILTIN = `$__get_builtin_hole_${Date.now()}`; | ||
| 7 | + Object.defineProperty(globalThis, GET_BUILTIN, { | ||
| 8 | + value: builtinName => require(builtinName), | ||
| 9 | + enumerable: false, | ||
| 10 | + configurable: false, | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + register(fixtures.fileURL('es-module-loaders/builtin-named-exports-loader.mjs'), { | ||
| 14 | + data: { | ||
| 15 | + GET_BUILTIN, | ||
| 16 | + }, | ||
| 17 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments