11// This tests that custom conditions can be used in module resolution hooks.
2- import '../common/index.mjs' ;
2+ import * as common from '../common/index.mjs' ;
33import { registerHooks } from 'node:module' ;
44import assert from 'node:assert' ;
55import { cjs , esm } from '../fixtures/es-modules/custom-condition/load.cjs' ;
@@ -12,11 +12,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
1212// allow a CJS to be resolved with that condition.
1313{
1414 const hooks = registerHooks ( {
15- resolve ( specifier , context , nextResolve ) {
15+ resolve : common . mustCall ( ( specifier , context , nextResolve ) => {
1616 assert ( Array . isArray ( context . conditions ) ) ;
1717 context . conditions = [ 'foo' , ...context . conditions ] ;
1818 return nextResolve ( specifier , context ) ;
19- } ,
19+ } , 2 ) ,
2020 } ) ;
2121 assert . strictEqual ( cjs ( 'foo/second' ) . result , 'foo' ) ;
2222 assert . strictEqual ( ( await esm ( 'foo/second' ) ) . result , 'foo' ) ;
@@ -27,11 +27,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
2727// allow a ESM to be resolved with that condition.
2828{
2929 const hooks = registerHooks ( {
30- resolve ( specifier , context , nextResolve ) {
30+ resolve : common . mustCall ( ( specifier , context , nextResolve ) => {
3131 assert ( Array . isArray ( context . conditions ) ) ;
3232 context . conditions = [ 'foo-esm' , ...context . conditions ] ;
3333 return nextResolve ( specifier , context ) ;
34- } ,
34+ } , 2 ) ,
3535 } ) ;
3636 assert . strictEqual ( cjs ( 'foo/third' ) . result , 'foo-esm' ) ;
3737 assert . strictEqual ( ( await esm ( 'foo/third' ) ) . result , 'foo-esm' ) ;
@@ -41,11 +41,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
4141// Duplicating the 'foo' condition in the resolve hook should not change the result.
4242{
4343 const hooks = registerHooks ( {
44- resolve ( specifier , context , nextResolve ) {
44+ resolve : common . mustCall ( ( specifier , context , nextResolve ) => {
4545 assert ( Array . isArray ( context . conditions ) ) ;
4646 context . conditions = [ 'foo' , ...context . conditions , 'foo' ] ;
4747 return nextResolve ( specifier , context ) ;
48- } ,
48+ } , 2 ) ,
4949 } ) ;
5050 assert . strictEqual ( cjs ( 'foo/fourth' ) . result , 'foo' ) ;
5151 assert . strictEqual ( ( await esm ( 'foo/fourth' ) ) . result , 'foo' ) ;
0 commit comments