@mocks-server/main
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -10,2 +10,4 @@ # Change Log | ||
- Remove "/features" api path. | ||
- Remove "features" getter from Server | ||
- Remove Server and Cli constructors. Use @mocks-server/core instead | ||
@@ -18,2 +20,11 @@ ## [unreleased] | ||
## [1.3.0] - 2019-11-17 | ||
### Added | ||
- Add programmatic Classes end-to-end tests | ||
- Add files watcher end-to-end tests | ||
### Changed | ||
- Full refactor for making it pluggable. | ||
- Split code into core, cli and api main Classes, which are intended to be published separately. | ||
## [1.2.0] - 2019-11-13 | ||
@@ -20,0 +31,0 @@ ### Added |
14
index.js
@@ -14,11 +14,11 @@ /* | ||
const Cli = require("./lib/Cli"); | ||
const Server = require("./lib/Server"); | ||
const Feature = require("./lib/features/Feature"); | ||
const ProgrammaticCli = require("./lib/ProgrammaticCli"); | ||
const ProgrammaticServer = require("./lib/ProgrammaticServer"); | ||
const Behavior = require("./lib/core/mocks/Behavior"); | ||
module.exports = { | ||
Cli, | ||
Server, | ||
Feature, | ||
Behavior: Feature | ||
Cli: ProgrammaticCli, | ||
Server: ProgrammaticServer, | ||
Feature: Behavior, | ||
Behavior | ||
}; |
@@ -16,5 +16,4 @@ /* | ||
const Features = require("./Features"); | ||
const Behaviors = require("./Behaviors"); | ||
const Settings = require("./Settings"); | ||
const tracer = require("../common/tracer"); | ||
@@ -24,8 +23,13 @@ const FEATURES_PATH = "/features"; | ||
class Api { | ||
constructor(features, settings) { | ||
const featuresRouter = new Features(features).router; | ||
this._features = features; | ||
constructor(core) { | ||
this._core = core; | ||
this._tracer = core.tracer; | ||
} | ||
init() { | ||
const behaviorsRouter = new Behaviors(this._core).router; | ||
this._router = express.Router(); | ||
// TODO, deprecate features router | ||
this._router.use(FEATURES_PATH, (req, res, next) => { | ||
tracer.warn( | ||
this._tracer.warn( | ||
`Deprecation warning: "${FEATURES_PATH}" api path will be deprecated. Use "/behaviors" instead` | ||
@@ -35,9 +39,9 @@ ); | ||
}); | ||
this._router.use(FEATURES_PATH, featuresRouter); | ||
this._router.use("/behaviors", featuresRouter); | ||
this._router.use("/settings", new Settings(settings).router); | ||
} | ||
// TODO, deprecate features router | ||
this._router.use(FEATURES_PATH, behaviorsRouter); | ||
this._router.use("/behaviors", behaviorsRouter); | ||
this._router.use("/settings", new Settings(this._core.settings, this._tracer).router); | ||
get router() { | ||
return this._router; | ||
this._core.addCustomRouter("/mocks", this._router); | ||
return Promise.resolve(); | ||
} | ||
@@ -44,0 +48,0 @@ } |
/* | ||
Copyright 2019 Javier Brea | ||
Copyright 2019 XbyOrange | ||
@@ -15,6 +16,5 @@ | ||
const tracer = require("../common/tracer"); | ||
class SettingsApi { | ||
constructor(settings) { | ||
constructor(settings, tracer) { | ||
this._tracer = tracer; | ||
this._settings = settings; | ||
@@ -28,4 +28,4 @@ this._router = express.Router(); | ||
const newDelay = req.body.delay; | ||
tracer.verbose(`Changing delay to "${newDelay}" | ${req.id}`); | ||
this._settings.delay = newDelay; | ||
this._tracer.verbose(`Changing delay to "${newDelay}" | ${req.id}`); | ||
this._settings.set("delay", newDelay); | ||
this.get(req, res); | ||
@@ -35,6 +35,6 @@ } | ||
get(req, res) { | ||
tracer.verbose(`Sending delay to | ${req.id}`); | ||
this._tracer.verbose(`Sending delay to | ${req.id}`); | ||
res.status(200); | ||
res.send({ | ||
delay: this._settings.delay | ||
delay: this._settings.get("delay") | ||
}); | ||
@@ -41,0 +41,0 @@ } |
@@ -14,15 +14,8 @@ /* | ||
const Boom = require("boom"); | ||
const Core = require("./core/Core"); | ||
const AdminApi = require("./api/Api"); | ||
const InquirerCli = require("./cli/Cli"); | ||
const Cli = require("./Cli"); | ||
const Server = require("./Server"); | ||
const options = require("./common/options"); | ||
const tracer = require("./common/tracer"); | ||
const handleError = error => { | ||
if (Boom.isBoom(error)) { | ||
tracer.error(error.message); | ||
} else { | ||
console.log(error); | ||
} | ||
console.error(`Error: ${error.message}`); | ||
process.exitCode = 1; | ||
@@ -32,8 +25,8 @@ }; | ||
const start = () => { | ||
const opts = options.get(); | ||
try { | ||
if (!opts.cli) { | ||
return new Server(opts.features, opts).start(); | ||
} | ||
return new Cli(opts).start().catch(handleError); | ||
const mocksServer = new Core({ | ||
plugins: [AdminApi, InquirerCli] | ||
}); | ||
return mocksServer.start().catch(handleError); | ||
} catch (error) { | ||
@@ -40,0 +33,0 @@ return handleError(error); |
{ | ||
"name": "@mocks-server/main", | ||
"version": "1.2.0", | ||
"description": "Mocks Server able to simulate multiple API behaviors", | ||
"version": "1.3.0", | ||
"description": "Mocks server supporting multiple api behaviors", | ||
"keywords": [ | ||
"mocks", | ||
"server", | ||
"mock", | ||
"fixtures", | ||
@@ -64,3 +65,5 @@ "behaviors", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"fs-extra": "^8.1.0", | ||
"husky": "3.0.9", | ||
"is-promise": "^2.1.0", | ||
"jest": "24.9.0", | ||
@@ -67,0 +70,0 @@ "lint-staged": "^9.4.2", |
@@ -18,3 +18,3 @@ [![Build status][travisci-image]][travisci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Quality Gate][quality-gate-image]][quality-gate-url] | ||
* [Tutorials](https://www.mocks-server.org/docs/tutorials-static) | ||
* [configuration](https://www.mocks-server.org/docs/configuration-command-line-arguments) | ||
* [Configuration](https://www.mocks-server.org/docs/configuration-command-line-arguments) | ||
@@ -21,0 +21,0 @@ ## Why a mocks server? |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
77205
28
1700
13
2