-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd97845
commit 4427f0a
Showing
5 changed files
with
92 additions
and
3 deletions.
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,7 @@ | ||
const isMocked = false | ||
const isCustomResolverChild = true | ||
|
||
export default { | ||
isCustomResolverChild, | ||
isMocked | ||
} |
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,5 @@ | ||
import child from 'RESOLVECUSTOM' | ||
|
||
export { | ||
child | ||
} |
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,39 @@ | ||
import path from 'path' | ||
import test from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import module from 'node:module' | ||
import esmock from 'esmock' | ||
|
||
function resolverCustom (moduleId, parent) { | ||
return /RESOLVECUSTOM$/.test(moduleId) && new URL( | ||
path.resolve( | ||
new URL(parent).pathname, | ||
'../../local/customResolverChild.js'), | ||
parent | ||
).href | ||
} | ||
|
||
async function resolve (specifier, context, next) { | ||
return next( | ||
specifier === 'RESOLVECUSTOM' | ||
? resolverCustom(specifier, context.parentURL) | ||
: specifier, context) | ||
} | ||
|
||
module.register(` | ||
data:text/javascript, | ||
import path from 'node:path'; | ||
${encodeURIComponent(resolverCustom)} | ||
export ${encodeURIComponent(resolve)}`.slice(1)) | ||
|
||
test('should use custom resolver', async () => { | ||
const customResolverParent = await esmock( | ||
'../local/customResolverParent.js', {}, { | ||
RESOLVECUSTOM: ({ isMocked: true }) | ||
}, { | ||
resolvers: [resolverCustom] | ||
}) | ||
|
||
assert.ok(customResolverParent.child.isCustomResolverChild) | ||
assert.ok(customResolverParent.child.isMocked) | ||
}) |
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