Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
seglo edited this page Dec 29, 2014 · 13 revisions

connect-prism wiki

Welcome to the connect-prism wiki. Since connect-prism has so many features I've provided several common use cases to get new users started.

FAQ

How do I record mocks so that I can play them back while developing my front end application?

When you create a new prism set the mode config to record or mockrecord.

How do I prototype an API for my front end application without a backend server?

When you create a new prism set the mode config to mock. Start making calls to your backend and let prism capture the request and return a 404. When in mock mode, prism will create a stub request in your mocksPath. The stub will have an extension of .404 so that it's easy to identify. Open the file, return the response you want in the data parameter and finally remove the .404 extension to indicate that you wish to use this mocked response. See Stubbing new mocks in the README for more details.

How do I switch the mode I'm using without restarting my development server?

When the prism API is enabled in configuration then you can call setmode to change the mode of a prism configuration using HTTP calls.

For example, you may be in development mode and you want to switch from mock to record mode. To do this you would make a call to the API. To change the mode of a prism configuration named server to record I would make the following call.

POST http://localhost:9000/_prism/setmode/server/record

A response of OK is returned to indicate success.

How do I get more readable mock filenames?

It's a common request that users want more readable mock response filenames instead of the default SHA1 hash. To allow for this I created a humanReadable option for the mockFilenameGenerator configuration. This will attempt to use the request URL in conjunction with the SHA1 hash (to better achieve uniqueness).

i.e.)

./mocks/serve/_is_this_url_really=that&readable=at&all_09b2ed55fb2b388fbe02c69e94bca5d86ff7247c.json

How do I run my front end test suite with a mocked server?

Typically you'll web shops will run an end to end integration test using selenium. This is fairly slow because it involves spinning up a real server and making real calls to it. A common use case for prism is to run your e2e tests against a set of mocked responses. See the prism-sample-project for an example of how to run a protactor testsuite with connect-prism.

How do I programmatically configure prism in my testsuite and override mocks?

When the prism API is enabled in configuration then you can call a set of endpoints to create and remove mock responses. This is useful during testing when you want to simulate different server responses to the same HTTP call.

See the prism-sample-project for an example of how to program different server responses with the connect-prism API.

Clone this wiki locally