egg-mock
Advanced tools
Comparing version 5.10.8 to 5.10.9
@@ -66,2 +66,5 @@ const mm = require('mm'); | ||
const MOCK_CONFIGS = Symbol('MOCK_CONFIGS'); | ||
const MOCK_CONFIG_INDEX = Symbol('MOCK_CONFIG_INDEX'); | ||
return function mockHttpclient(mockUrl, mockMethod, mockResult) { | ||
@@ -78,2 +81,9 @@ if (!mockResult) { | ||
// use MockAgent on undici | ||
let mockConfigs = app[MOCK_CONFIGS]; | ||
if (!mockConfigs) { | ||
mockConfigs = []; | ||
mm(app, MOCK_CONFIGS, mockConfigs); | ||
} | ||
let mockConfigIndex = -1; | ||
let origin = mockUrl; | ||
@@ -98,4 +108,12 @@ let pathname = mockUrl; | ||
pathname = path => { | ||
return mockUrl.test(`${requestOrigin}${path}`); | ||
for (const config of mockConfigs) { | ||
if (config.mockUrl.test(`${requestOrigin}${path}`)) { | ||
mm(app, MOCK_CONFIG_INDEX, config.mockConfigIndex); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
mockConfigIndex = mockConfigs.length; | ||
mockConfigs.push({ mockUrl, mockResult, mockConfigIndex }); | ||
} | ||
@@ -115,3 +133,9 @@ const mockPool = mockAgent.getAgent().get(origin); | ||
const requestUrl = `${options.origin}${options.path}`; | ||
const mockRequestResult = is.function(mockResult) ? mockResult(requestUrl, options) : mockResult; | ||
let mockRequestResult; | ||
if (mockConfigIndex >= 0) { | ||
mockResult = mockConfigs[app[MOCK_CONFIG_INDEX]].mockResult; | ||
mockRequestResult = is.function(mockResult) ? mockResult(requestUrl, options) : mockResult; | ||
} else { | ||
mockRequestResult = is.function(mockResult) ? mockResult(requestUrl, options) : mockResult; | ||
} | ||
const result = extend(true, {}, normalizeResult(mockRequestResult)); | ||
@@ -118,0 +142,0 @@ return { |
{ | ||
"name": "egg-mock", | ||
"version": "5.10.8", | ||
"version": "5.10.9", | ||
"eggPlugin": { | ||
@@ -5,0 +5,0 @@ "name": "egg-mock" |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
107599
2489
49