1 | "use strict";
|
2 | var __rest = (this && this.__rest) || function (s, e) {
|
3 | var t = {};
|
4 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
5 | t[p] = s[p];
|
6 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
7 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
8 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
9 | t[p[i]] = s[p[i]];
|
10 | }
|
11 | return t;
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | const quibble = require("quibble");
|
15 | const imitate_1 = require("../../imitate");
|
16 | const jest_module_1 = require("./jest-module");
|
17 | const require_actual_1 = require("./require-actual");
|
18 | const fake_name_1 = require("./fake-name");
|
19 | quibble.ignoreCallsFromThisFile();
|
20 | function replaceCjsModule(path, stub) {
|
21 | if (typeof jest === 'object')
|
22 | return jest_module_1.default(...arguments);
|
23 | if (arguments.length > 1) {
|
24 | return quibble(path, stub);
|
25 | }
|
26 | const realThing = require_actual_1.default(path);
|
27 | const fakeThing = imitate_1.default(realThing, fake_name_1.default(path, realThing));
|
28 | quibble(path, fakeThing);
|
29 | return fakeThing;
|
30 | }
|
31 | exports.default = replaceCjsModule;
|
32 | async function replaceEsModule(path, namedExportsStub, defaultExportStub) {
|
33 | if (typeof jest === 'object') {
|
34 | throw new Error(`stubbing ES modules (${path}) under Jest is not yet supported`);
|
35 | }
|
36 | if (arguments.length > 1) {
|
37 | return quibble.esm(path, namedExportsStub, defaultExportStub);
|
38 | }
|
39 | const { modulePath, module } = await quibble.esmImportWithPath(path);
|
40 | const _a = imitate_1.default(module, fake_name_1.default(path, module)), { default: fakeDefaultExport = undefined } = _a, fakeNamedExports = __rest(_a, ["default"]);
|
41 | await quibble.esm(modulePath, fakeNamedExports, fakeDefaultExport);
|
42 | return Object.assign({ default: fakeDefaultExport }, fakeNamedExports);
|
43 | }
|
44 | exports.replaceEsModule = replaceEsModule;
|