MCPcopy Index your code
hub / github.com/nodejs/node / normalizeModuleMockOptions

Function normalizeModuleMockOptions

lib/internal/test_runner/mock/mock.js:825–879  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

823}
824
825function normalizeModuleMockOptions(options) {
826 const { cache = false } = options;
827 validateBoolean(cache, 'options.cache');
828
829 const hasExports = 'exports' in options;
830 const hasNamedExports = 'namedExports' in options;
831 const hasDefaultExport = 'defaultExport' in options;
832
833 deprecateNamedExports(options);
834 deprecateDefaultExport(options);
835
836 const moduleExports = { __proto__: null };
837
838 if (hasExports) {
839 validateObject(options.exports, 'options.exports');
840 }
841
842 if (hasNamedExports) {
843 validateObject(options.namedExports, 'options.namedExports');
844 }
845
846 if (hasExports && (hasNamedExports || hasDefaultExport)) {
847 let reason = "cannot be used with 'options.namedExports'";
848
849 if (hasDefaultExport) {
850 reason = hasNamedExports ?
851 "cannot be used with 'options.namedExports' or 'options.defaultExport'" :
852 "cannot be used with 'options.defaultExport'";
853 }
854
855 throw new ERR_INVALID_ARG_VALUE('options.exports', options.exports, reason);
856 }
857
858 if (hasExports) {
859 copyOwnProperties(options.exports, moduleExports);
860 }
861
862 if (hasNamedExports) {
863 copyOwnProperties(options.namedExports, moduleExports);
864 }
865
866 if (hasDefaultExport) {
867 ObjectDefineProperty(
868 moduleExports,
869 'default',
870 ObjectAssign({ __proto__: null }, ObjectGetOwnPropertyDescriptor(options, 'defaultExport')),
871 );
872 }
873
874 return {
875 __proto__: null,
876 cache,
877 moduleExports,
878 };
879}
880
881
882function copyOwnProperties(from, to) {

Callers 1

moduleMethod · 0.85

Calls 2

ObjectAssignFunction · 0.85
copyOwnPropertiesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…