Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 69d2f0b

Browse files
committed
docs: update docs
1 parent 1abf83e commit 69d2f0b

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

README.md

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
[![NPM downloads][npm-downloads-image]][npm-downloads-url] [![License][license-image]][license-url]
66

77

8-
# Mocks server Cypress commands
8+
# Mocks Server Cypress commands
99

10-
This solution provides you commands for easily changing [@mocks-server settings][mocks-server-options-url], such as current behavior, delay time, etc.
10+
Extends Cypress' cy commands with methods for easily changing [Mocks Server settings][mocks-server-options-url], such as current mock, route variants, delay time, etc.
1111

1212
## Installation
1313

@@ -31,51 +31,48 @@ You can now use all next commands:
3131

3232
### Commands
3333

34-
Set current behavior:
34+
##### `cy.mocksSetMock("users-error")`
3535

36-
```js
37-
cy.mocksServerSetBehavior("admin-user");
38-
```
36+
Sets current mock.
3937

40-
Set delay time:
38+
##### `cy.mocksUseRouteVariant("users:success")`
4139

42-
```js
43-
cy.mocksServerSetDelay(2000);
44-
```
40+
Sets a specific route variant to be used by current mock.
4541

46-
Set any setting:
42+
##### `cy.mocksRestoreRoutesVariants()`
4743

48-
```js
49-
cy.mocksServerSetSettings({
50-
watch: false,
51-
delay: 0,
52-
behavior: "catalog-error"
53-
});
54-
```
44+
Restore routes variants to those defined in current mock.
5545

56-
## Configuration
46+
##### `cy.mocksSetDelay(2000)`
5747

58-
By default, the client is configured to request to http://localhost:3100/admin, based in the [default options of @mocks-server][mocks-server-options-url]
48+
Sets delay time.
5949

60-
You can change both the base url of the "@mocks-server", and the admin api path of the "@mocks-server/plugin-admin-api" using the `config` method in your project's `cypress/support/commands.js`:
50+
##### `cy.mocksSetSettings({ watch: false, delay: 0 })`
6151

62-
```js
63-
import { config } from "@mocks-server/cypress-commands";
52+
Sets any [Mocks Server setting][mocks-server-options-url].
6453

65-
config({
66-
adminApiPath: "/foo-admin",
67-
baseUrl: "http://my-mocks-server:3200"
68-
});
69-
```
54+
##### `cy.mocksConfig({ adminApiPath: "/foo", baseUrl: "http://localhost:3000" })`
55+
56+
Configures the [Mocks Server administration API client](https://github.com/mocks-server/admin-api-client), used under the hood.
57+
58+
## Configuration
59+
60+
By default, the API client is configured to request to `http://localhost:3100/admin`, based in the [default Mocks Server options][mocks-server-options-url]
61+
62+
You can change both the base url of Mocks Server, and the api path of the administration API using the `cy.mocksConfig` command mentioned above, or the plugin environment variables:
63+
64+
* __`MOCKS_SERVER_BASE_URL`__: Modifies the base url of Mocks Server. Default is `http://localhost:3100`.
65+
* __`MOCKS_SERVER_ADMIN_API_PATH`__: Modifies the path of the Mocks Server administration API. Default is `/admin`.
66+
* __`MOCKS_SERVER_ENABLED`__: Disables requests to Mocks Server, so the commands will not fail even when Mocks Server is not running. This is useful to reuse same tests with mocks and a real API, because commands to change Mocks Server settings will be ignored.
7067

7168
### Using commands
7269

73-
You should usually change the mock server settings in a `before` statement:
70+
You should usually change Mocks Server settings in a `before` statement:
7471

7572
```js
7673
describe("user with default role", () => {
7774
before(() => {
78-
cy.mocksServerSetBehavior("normal-user");
75+
cy.mocksSetMock("normal-user");
7976
cy.visit("/");
8077
});
8178

@@ -86,7 +83,7 @@ describe("user with default role", () => {
8683

8784
describe("user with admin role", () => {
8885
before(() => {
89-
cy.mocksServerSetBehavior("admin-user");
86+
cy.mocksSetMock("admin-user");
9087
cy.visit("/");
9188
});
9289

0 commit comments

Comments
 (0)