@drakensoftware/magicmock
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,1 +0,1 @@ | ||
export { mockFunction, mockClass } from './Loader'; | ||
export { mockFunction, mockClass, callMocked } from './Loader'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mockClass = exports.mockFunction = void 0; | ||
exports.callMocked = exports.mockClass = exports.mockFunction = void 0; | ||
var Loader_1 = require("./Loader"); | ||
Object.defineProperty(exports, "mockFunction", { enumerable: true, get: function () { return Loader_1.mockFunction; } }); | ||
Object.defineProperty(exports, "mockClass", { enumerable: true, get: function () { return Loader_1.mockClass; } }); | ||
Object.defineProperty(exports, "callMocked", { enumerable: true, get: function () { return Loader_1.callMocked; } }); | ||
//# sourceMappingURL=index.js.map |
type GenericAsyncFunction<T> = (...args: unknown[]) => Promise<T>; | ||
export declare function mockFunction<T>(thisArg: unknown, identifier: string, fn: GenericAsyncFunction<T>): GenericAsyncFunction<T>; | ||
export declare function mockClass<T>(thisArg: unknown, identifier: string, obj: T): T; | ||
export declare function callMocked<T>(func: GenericAsyncFunction<T>, identifier?: string): Promise<T>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mockClass = exports.mockFunction = void 0; | ||
exports.callMocked = exports.mockClass = exports.mockFunction = void 0; | ||
function mockFunction(thisArg, identifier, fn) { | ||
@@ -24,2 +24,8 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV !== 'test') | ||
exports.mockClass = mockClass; | ||
function callMocked(func, identifier) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const module = require('./MagicMock'); | ||
return module.callMocked(func, identifier); | ||
} | ||
exports.callMocked = callMocked; | ||
//# sourceMappingURL=Loader.js.map |
@@ -5,2 +5,3 @@ type GenericAsyncFunction<T> = (...args: unknown[]) => Promise<T>; | ||
export declare function mockClass<T>(thisArg: unknown, identifier: string, obj: T): T; | ||
export declare function callMocked<T>(func: GenericAsyncFunction<T>, identifier?: string): Promise<T>; | ||
export {}; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mockClass = exports.mockFunction = exports.resetInvocations = void 0; | ||
exports.callMocked = exports.mockClass = exports.mockFunction = exports.resetInvocations = void 0; | ||
const fs = __importStar(require("fs")); | ||
@@ -107,2 +107,12 @@ const path = __importStar(require("path")); | ||
exports.mockClass = mockClass; | ||
function extractFunctionName(functionSource) { | ||
const functions = functionSource.match(/[a-zA-Z0-9_$]+(?:\s*\.\s*[a-zA-Z0-9_$]+)*\(/g); | ||
const lastFunctionSegments = functions[functions.length - 1].match(/[a-zA-Z0-9_$]+/g); | ||
return lastFunctionSegments.join('_'); | ||
} | ||
async function callMocked(func, identifier) { | ||
const newFunc = mockFunction(null, identifier ?? extractFunctionName(func.toString()), func); | ||
return await newFunc(); | ||
} | ||
exports.callMocked = callMocked; | ||
//# sourceMappingURL=MagicMock.js.map |
type GenericAsyncFunction<T> = (...args: unknown[]) => Promise<T>; | ||
export declare function mm<T>(identifier: string, fn: GenericAsyncFunction<T>): GenericAsyncFunction<T>; | ||
export declare function mockFunction<T>(thisArg: unknown, identifier: string, fn: GenericAsyncFunction<T>): GenericAsyncFunction<T>; | ||
export declare function mockClass<T>(thisArg: unknown, identifier: string, obj: T): T; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mm = void 0; | ||
function mm(identifier, fn) { | ||
exports.mockClass = exports.mockFunction = void 0; | ||
function mockFunction(thisArg, identifier, fn) { | ||
return fn; | ||
} | ||
exports.mm = mm; | ||
exports.mockFunction = mockFunction; | ||
function mockClass(thisArg, identifier, obj) { | ||
return obj; | ||
} | ||
exports.mockClass = mockClass; | ||
//# sourceMappingURL=Nothing.js.map |
{ | ||
"name": "@drakensoftware/magicmock", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Create your mocks automagically", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20617
275