3.5.2 • Published 4 years ago

simulado v3.5.2

Weekly downloads
5,502
License
ISC
Repository
github
Last release
4 years ago

Simulado CircleCI npm node

Deploy

2.x docs

Install

npm i simulado --save-dev

or

docker run -p <desired_port>:80 ldabiralai/simulado

Usage

CLI

This will keep the server alive until the process is killed (unlike the below).

./node_modules/.bin/simulado
Options

-p, --port - Port number that Simulado should start on.

-f, --file - Path to a JSON file containing mocks to mock on startup.

For HTTPS, use the following options

-c, --cert <filepath> - Path to certificate

-k, --key <filepath> - Path to certificate key

Web Client

Once Simulado has started, going to http://localhost:<SIMULADO_PORT_NUM> will display a list of mocked endpoints and their responses.

Basic Usage (ES6)

import simulado from 'simulado';
import axios from 'axios';

(async function() {
  // Start Simulado server
  await simulado.start();

  // Mock a response
  await simulado.setMock({
    path: '/data',
    body: 'Hello World!'
  });

  // Make a request
  const response = await axios.get('http://localhost:7001/data');
  console.log(response.data); // => 'Hello World!'

  // Stop Simulado server once done
  await simulado.stop();
})();

API

start([options])

Start Simulado

  • options <Object>
    • port <number> - Specify the port number to start Simulado on. Default: 7001
    • https <object> - Enable https support
      • key <string> - path to key file
      • cert <string> - path to cert file

setRemoteServer(url)

Sets the url of a simulado instance on which the client should set mocks, for use if simulado lives on another server.

  • url <String> for example https://my-simulado-server.herokuapp.com

isRunning()

Returns true if simulado is running. Returns false if simulado is not started.

setMock(mockResponse)

Sets a mock response

setMocks(mockResponses)

Sets multiple mock responses

setDefaults(mockResponses)

Clears mocked responses and sets new mocked responses

lastRequests(method, path[, limit])

Fetch the last requests for a path

  • method <String> - The request method for the requests you want to fetch
  • path <String> - The path of the requests you want to fetch
  • limit <number> - Only return the given number of last requests

lastRequest(method, path)

Fetch the last request for a path

  • method <String> - The request method for the requests you want to fetch
  • path <String> - The path of the requests you want to fetch

clearResponse(method, path)

Clear mocked response from the store

  • method <String> - The HTTP request method to clear saved response from
  • path <String> - The path to match against when clearing

clearResponses()

Clear all mocked responses from the store.

clearRequest(method, path)

Clear captured request from the store

  • method <String> - The HTTP request method to clear saved request from
  • path <String> - The path to match against when clearing

clearRequests()

Clear all captured requests from the store.

stop()

Stop Simulado.

Mock Response Options

{
  // Path - Mandatory - The HTTP request path that you want the mock to response to.
  path: '/testPath', // String path
  path: /\/testPath/.*/, // Regex path

  method: 'GET', // Optional (defaults to GET if not set) - The HTTP request method that you want the mock to response to.

  status: 200, // Optional (defaults to 200 if not set) - The HTTP status you want to mock to response with.

  headers: {
    'X-Custom-Header': 'Custom Header Value'
  }, // Optional - The HTTP headers you want the mock to respond with.

  body: {
    data: 'DATA'
  }, // Optional - The HTTP response body you want the mock to respond with.

  conditionalHeaders: {
    needMe: 'true'
  }, // Optional - The mock with only response if the conditional headers are sent in the request.

  conditionalBody: {
    data: 'YouNeedThisData'
  }, // Optional - The mock will only response if the conditional body is sent in the request.

  delay: 5000 // the time (in milliseconds) to wait until responding to a request
}
3.5.2

4 years ago

3.5.1

5 years ago

2.8.3

5 years ago

3.5.0

5 years ago

3.4.0

5 years ago

3.3.1

5 years ago

3.3.0

6 years ago

3.2.3

6 years ago

3.2.2

6 years ago

2.8.2

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

3.0.0-rc.3

6 years ago

3.0.0-rc.2

6 years ago

3.0.0-rc.1

7 years ago

3.0.0-alpha.5

7 years ago

3.0.0-alpha.4

7 years ago

3.0.0-alpha.3

7 years ago

3.0.0-alpha.2

7 years ago

2.8.1

7 years ago

2.8.0

7 years ago

2.7.1

7 years ago

2.7.0

7 years ago

2.6.0

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.1

7 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.9.5

8 years ago

1.9.4

8 years ago

1.9.3

8 years ago

1.9.2

9 years ago

1.9.1

9 years ago

1.9.0

9 years ago

1.8.1

9 years ago

1.8.0

9 years ago

1.7.0

9 years ago

1.6.0

9 years ago

1.5.0

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago