@hectorjs/stub-cli
Command line for stub-backend library
Last updated 6 months ago by hectorjs .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @hectorjs/stub-cli 
SYNC missed versions from official npm registry.

@hectorjs/stub-cli

Releases documentation

Description

The aim of this project is to mock backend services building different responses for a given authentication, cookie or request among others.

stub-cli is a command line which helps you to create new projects, generate methods and test template.

Keep it simple :smile:

Install

Install the library:

Globally (recommended):

npm install -g @hectorjs/stub-cli

or locally:

npm install @hectorjs/stub-cli --save-dev

Verify your hjs command is installed correctly.

hjs --version
hjs --help

Commands

1) hjs --help

It will display posible options available in the library.

2) hjs new/n [name-mock-service]

It creates a new project with the name provided in the brakets.

Example: hjs new mock-service

You can add the option --vs or --idea to open the IDE.

If you execute the command without project name (hjs new), the terminal will ask you for a new project (Create new project? [Yn]). Response y when you want to create it (This is like hjs new [name-project]) or response n when you want to set in your own package.json project.

MORE INFO: hjs new --help

3) hjs generate/g [method] [name-path]

It will generate a method template resource with a test. For example , hjs g get customers/{id}/business?product={param}). More info: hjs g --help. You can generate different methods like get, head, post, delete among others.

For each method, it creates a test with dummy data. It will reduce the time to test the mock. Give it a try.

The request and response are json by default. If you want to create a scenario for xml, you have to include --xml in you cli.

NOTE: The endpoint should not start with '/' for the cli and you should escape '&' like the next example:

hjs g post customers/{id}/products?query={param1}\&identifier={identifier} MORE INFO: hjs generate --help

4) hjs test

Execute the tests which have been created by each method generate command (hjs g get ...). You can add different properties to the command as port, logs or profile.

NOTE: you can run npm test as well. MORE INFO: hjs test --help

5) hjs config [prop]

Create a config file (.hjs.config.json) where you can set the logs, port, among others settings.

hjs config --port 8090 --logs tiny --banner

The library use morgan library for the logs, so you can add different kind of logs as tiny, common...

MORE INFO: hjs config --help

6) hjs start

If you want to run the mock hjs start. Also if you want to run the mocks with nodemon listening the changes under the resources folder, execute hjs start --dev.

NOTE: you can run npm start as well. MORE INFO: hjs start --help

UI

This section is in progress at this moment.

You can run the application and navigate to http://localhost:3005/ and have a look.

Example

Once you create a new project, it is adding a health check endpoint by default with its test.

Let's create a project called mock-service

hjs new mock-service

We navigate to the mock-service root and execute the test:

hjs test

You will see there is already a health check endpoint by default.

If you want to run the server and test it. You need to execute the start command:

hjs start

The service will be running in the port 3005 waiting for a request.

Make a request:

curl http://localhost:3005/health

The response will be like this:

{
    "STATUS": "UP"
}

Now you can start adding new methods for your project.

Enjoy! :heart:

Respository

https://github.com/HecJimSan/stub-cli

Current Tags

  • 1.1.0                                ...           latest (a month ago)
  • 0.18.0-0                                ...           next (6 months ago)

34 Versions

  • 1.1.0                                ...           a month ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.1                                ...           2 months ago
  • 1.0.0                                ...           2 months ago
  • 0.26.0                                ...           3 months ago
  • 0.25.0                                ...           3 months ago
  • 0.24.0                                ...           3 months ago
  • 0.23.0                                ...           4 months ago
  • 0.22.1                                ...           4 months ago
  • 0.22.0                                ...           4 months ago
  • 0.21.0                                ...           4 months ago
  • 0.20.0                                ...           5 months ago
  • 0.19.1                                ...           5 months ago
  • 0.19.0                                ...           5 months ago
  • 0.18.0                                ...           6 months ago
  • 0.18.0-0                                ...           6 months ago
  • 0.17.0                                ...           6 months ago
  • 0.16.0                                ...           6 months ago
  • 0.15.0                                ...           6 months ago
  • 0.14.0                                ...           6 months ago
  • 0.13.0                                ...           6 months ago
  • 0.12.0                                ...           6 months ago
  • 0.11.0                                ...           6 months ago
  • 0.10.0                                ...           6 months ago
  • 0.9.0                                ...           7 months ago
  • 0.8.0                                ...           7 months ago
  • 0.7.0                                ...           7 months ago
  • 0.6.0                                ...           7 months ago
  • 0.5.0                                ...           7 months ago
  • 0.4.0                                ...           7 months ago
  • 0.3.0                                ...           7 months ago
  • 0.2.0                                ...           7 months ago
  • 0.1.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (4)
Dev Dependencies (8)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |