@mocks-server/core
Advanced tools
Comparing version 3.10.0 to 3.11.0
{ | ||
"name": "@mocks-server/core", | ||
"version": "3.10.0", | ||
"version": "3.11.0", | ||
"description": "Pluggable mock server supporting multiple route variants and mocks", | ||
@@ -41,3 +41,3 @@ "keywords": [ | ||
"@hapi/boom": "9.1.4", | ||
"@mocks-server/config": "1.2.1", | ||
"@mocks-server/config": "1.3.0", | ||
"@mocks-server/logger": "1.1.0", | ||
@@ -44,0 +44,0 @@ "@mocks-server/nested-collections": "2.0.0", |
@@ -16,3 +16,3 @@ /* | ||
const fsExtra = require("fs-extra"); | ||
const { map, debounce } = require("lodash"); | ||
const { map, debounce, isFunction } = require("lodash"); | ||
const isPromise = require("is-promise"); | ||
@@ -148,3 +148,27 @@ | ||
const content = this._require(filePath); | ||
resolve((content && content.default) || content); | ||
const exportedContent = (content && content.default) || content; | ||
if (isFunction(exportedContent)) { | ||
this._logger.debug( | ||
`Function exported by '${filePath}'. Executing it to return its result` | ||
); | ||
const exportedContentResult = exportedContent(); | ||
if (isPromise(exportedContentResult)) { | ||
this._logger.debug( | ||
`Function in '${filePath}' returned a promise. Waiting for it to resolve its result` | ||
); | ||
exportedContentResult | ||
.then((exportedContentPromiseResult) => { | ||
this._logger.silly(`Promise in '${filePath}' was resolved`); | ||
resolve(exportedContentPromiseResult); | ||
}) | ||
.catch((error) => { | ||
this._logger.silly(`Promise in '${filePath}' was rejected`); | ||
reject(error); | ||
}); | ||
} else { | ||
resolve(exportedContentResult); | ||
} | ||
} else { | ||
resolve(exportedContent); | ||
} | ||
} catch (error) { | ||
@@ -151,0 +175,0 @@ reject(error); |
@@ -57,3 +57,3 @@ /* | ||
from: { | ||
type: "string", | ||
type: ["string", "null"], | ||
}, | ||
@@ -78,3 +78,3 @@ routesVariants: { | ||
from: { | ||
type: "string", | ||
type: ["string", "null"], | ||
}, | ||
@@ -99,3 +99,3 @@ routeVariants: { | ||
from: { | ||
type: "string", | ||
type: ["string", "null"], | ||
}, | ||
@@ -252,3 +252,3 @@ routes: { | ||
function validationSingleMessage(schema, data, errors) { | ||
const formattedJson = betterAjvErrors(schema, data, errors, { | ||
const formattedJson = betterAjvErrors(schema, data || {}, errors, { | ||
format: "js", | ||
@@ -255,0 +255,0 @@ }); |
161833
4553
+ Added@mocks-server/config@1.3.0(transitive)
- Removed@mocks-server/config@1.2.1(transitive)
Updated@mocks-server/config@1.3.0