@@ -5,6 +5,7 @@ const common = require('../common');
55const { registerHooks } = require ( 'node:module' ) ;
66const assert = require ( 'node:assert' ) ;
77const { cjs, esm } = require ( '../fixtures/es-modules/custom-condition/load.cjs' ) ;
8+ const { mustCall } = require ( '../common/index.mjs' ) ;
89
910( async ( ) => {
1011 // Without hooks, the default condition is used.
@@ -15,11 +16,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
1516 // allow a CJS to be resolved with that condition.
1617 {
1718 const hooks = registerHooks ( {
18- resolve ( specifier , context , nextResolve ) {
19+ resolve : mustCall ( ( specifier , context , nextResolve ) => {
1920 assert ( Array . isArray ( context . conditions ) ) ;
2021 context . conditions = [ 'foo' , ...context . conditions ] ;
2122 return nextResolve ( specifier , context ) ;
22- } ,
23+ } , 2 ) ,
2324 } ) ;
2425 assert . strictEqual ( cjs ( 'foo/second' ) . result , 'foo' ) ;
2526 assert . strictEqual ( ( await esm ( 'foo/second' ) ) . result , 'foo' ) ;
@@ -30,11 +31,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
3031 // allow a ESM to be resolved with that condition.
3132 {
3233 const hooks = registerHooks ( {
33- resolve ( specifier , context , nextResolve ) {
34+ resolve : mustCall ( ( specifier , context , nextResolve ) => {
3435 assert ( Array . isArray ( context . conditions ) ) ;
3536 context . conditions = [ 'foo-esm' , ...context . conditions ] ;
3637 return nextResolve ( specifier , context ) ;
37- } ,
38+ } , 2 ) ,
3839 } ) ;
3940 assert . strictEqual ( cjs ( 'foo/third' ) . result , 'foo-esm' ) ;
4041 assert . strictEqual ( ( await esm ( 'foo/third' ) ) . result , 'foo-esm' ) ;
@@ -44,11 +45,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
4445 // Duplicating the 'foo' condition in the resolve hook should not change the result.
4546 {
4647 const hooks = registerHooks ( {
47- resolve ( specifier , context , nextResolve ) {
48+ resolve : mustCall ( ( specifier , context , nextResolve ) => {
4849 assert ( Array . isArray ( context . conditions ) ) ;
4950 context . conditions = [ 'foo' , ...context . conditions , 'foo' ] ;
5051 return nextResolve ( specifier , context ) ;
51- } ,
52+ } , 2 ) ,
5253 } ) ;
5354 assert . strictEqual ( cjs ( 'foo/fourth' ) . result , 'foo' ) ;
5455 assert . strictEqual ( ( await esm ( 'foo/fourth' ) ) . result , 'foo' ) ;
0 commit comments