-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: remove erroneous
context.parentURL
property passed to load
hook
PR-URL: #41975 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
- Loading branch information
1 parent
9d23419
commit f35b31f
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Flags: --expose-internals | ||
import { mustCall } from '../common/index.mjs'; | ||
import esmLoaderModule from 'internal/modules/esm/loader'; | ||
import assert from 'assert'; | ||
|
||
const { ESMLoader } = esmLoaderModule; | ||
|
||
/** | ||
* Verify custom hooks are called with appropriate arguments. | ||
*/ | ||
{ | ||
const esmLoader = new ESMLoader(); | ||
|
||
const originalSpecifier = 'foo/bar'; | ||
const importAssertions = Object.assign( | ||
Object.create(null), | ||
{ type: 'json' }, | ||
); | ||
const parentURL = 'file:///entrypoint.js'; | ||
const resolvedURL = 'file:///foo/bar.js'; | ||
const suggestedFormat = 'test'; | ||
|
||
function resolve(specifier, context, defaultResolve) { | ||
assert.strictEqual(specifier, originalSpecifier); | ||
// Ensure `context` has all and only the properties it's supposed to | ||
assert.deepStrictEqual(Object.keys(context), [ | ||
'conditions', | ||
'importAssertions', | ||
'parentURL', | ||
]); | ||
assert.ok(Array.isArray(context.conditions)); | ||
assert.deepStrictEqual(context.importAssertions, importAssertions); | ||
assert.strictEqual(context.parentURL, parentURL); | ||
assert.strictEqual(typeof defaultResolve, 'function'); | ||
|
||
return { | ||
format: suggestedFormat, | ||
url: resolvedURL, | ||
}; | ||
} | ||
|
||
function load(resolvedURL, context, defaultLoad) { | ||
assert.strictEqual(resolvedURL, resolvedURL); | ||
assert.ok(new URL(resolvedURL)); | ||
// Ensure `context` has all and only the properties it's supposed to | ||
assert.deepStrictEqual(Object.keys(context), [ | ||
'format', | ||
'importAssertions', | ||
]); | ||
assert.strictEqual(context.format, suggestedFormat); | ||
assert.deepStrictEqual(context.importAssertions, importAssertions); | ||
assert.strictEqual(typeof defaultLoad, 'function'); | ||
|
||
// This doesn't matter (just to avoid errors) | ||
return { | ||
format: 'module', | ||
source: '', | ||
}; | ||
} | ||
|
||
const customLoader = { | ||
// Ensure ESMLoader actually calls the custom hooks | ||
resolve: mustCall(resolve), | ||
load: mustCall(load), | ||
}; | ||
|
||
esmLoader.addCustomLoaders(customLoader); | ||
|
||
// Manually trigger hooks (since ESMLoader is not actually running) | ||
const job = await esmLoader.getModuleJob( | ||
originalSpecifier, | ||
parentURL, | ||
importAssertions, | ||
); | ||
await job.modulePromise; | ||
} |