@@ -853,6 +853,30 @@ declare module "node:test" {
853853 type FunctionPropertyNames < T > = {
854854 [ K in keyof T ] : T [ K ] extends Function ? K : never ;
855855 } [ keyof T ] ;
856+ interface MockModuleOptions {
857+ /**
858+ * If false, each call to `require()` or `import()` generates a new mock module.
859+ * If true, subsequent calls will return the same module mock, and the mock module is inserted into the CommonJS cache.
860+ * @default false
861+ */
862+ cache ?: boolean | undefined ;
863+ /**
864+ * The value to use as the mocked module's default export.
865+ *
866+ * If this value is not provided, ESM mocks do not include a default export.
867+ * If the mock is a CommonJS or builtin module, this setting is used as the value of `module.exports`.
868+ * If this value is not provided, CJS and builtin mocks use an empty object as the value of `module.exports`.
869+ */
870+ defaultExport ?: any ;
871+ /**
872+ * An object whose keys and values are used to create the named exports of the mock module.
873+ *
874+ * If the mock is a CommonJS or builtin module, these values are copied onto `module.exports`.
875+ * Therefore, if a mock is created with both named exports and a non-object default export,
876+ * the mock will throw an exception when used as a CJS or builtin module.
877+ */
878+ namedExports ?: object | undefined ;
879+ }
856880 /**
857881 * The `MockTracker` class is used to manage mocking functionality. The test runner
858882 * module provides a top level `mock` export which is a `MockTracker` instance.
@@ -1015,6 +1039,19 @@ declare module "node:test" {
10151039 implementation ?: Implementation ,
10161040 options ?: MockFunctionOptions ,
10171041 ) : Mock < ( ( value : MockedObject [ MethodName ] ) => void ) | Implementation > ;
1042+
1043+ /**
1044+ * This function is used to mock the exports of ECMAScript modules, CommonJS modules, and Node.js builtin modules.
1045+ * Any references to the original module prior to mocking are not impacted.
1046+ *
1047+ * Only available through the [--experimental-test-module-mocks](https://nodejs.org/api/cli.html#--experimental-test-module-mocks) flag.
1048+ * @since v20.18.0
1049+ * @experimental
1050+ * @param specifier A string identifying the module to mock.
1051+ * @param options Optional configuration options for the mock module.
1052+ */
1053+ module ( specifier : string , options ?: MockModuleOptions ) : MockModuleContext ;
1054+
10181055 /**
10191056 * This function restores the default behavior of all mocks that were previously
10201057 * created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be
@@ -1173,6 +1210,18 @@ declare module "node:test" {
11731210 */
11741211 restore ( ) : void ;
11751212 }
1213+ /**
1214+ * @since v20.18.0
1215+ * @experimental
1216+ */
1217+ class MockModuleContext {
1218+ /**
1219+ * Resets the implementation of the mock module.
1220+ * @since v20.18.0
1221+ */
1222+ restore ( ) : void ;
1223+ }
1224+
11761225 type Timer = "setInterval" | "setTimeout" | "setImmediate" | "Date" ;
11771226
11781227 interface MockTimersOptions {
0 commit comments