Skip to content
This repository has been archived by the owner. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c0a6b0e
chore(deps): update dependency eslint-config-prettier to v7
renovate-bot Jan 18, 2021
3679342
chore(deps): Upgrade dependencies
javierbrea Feb 15, 2021
f091765
feat: add mocksSetMock, mocksUseRouteVariant and mocksRestoreRoutesVa…
javierbrea Feb 15, 2021
485bb56
chore(ci): Build pre-release branch. publish with beta tag
javierbrea Feb 15, 2021
b463264
chore: fix lint config
javierbrea Feb 15, 2021
b990868
feat: add environment variables
javierbrea Feb 16, 2021
8452158
test(e2e): Create app code from template to allow customize api port
javierbrea Feb 16, 2021
e95841b
test(e2e): Test configuration using environment vars (#3)
javierbrea Feb 16, 2021
9b48cac
chore: fix eslint config
javierbrea Feb 16, 2021
1abf83e
chore: fix sonar config
javierbrea Feb 16, 2021
69d2f0b
docs: update docs
javierbrea Feb 16, 2021
eb155b2
Merge pull request #140 from mocks-server/renovate/eslint-config-pret…
javierbrea Feb 16, 2021
1fa9418
chore: Update dependencies. Adapt tests
javierbrea Feb 16, 2021
4dd7db0
chore(deps): update dependencies
javierbrea Feb 16, 2021
523678e
fix: do not call to set config when env vars are not defined
javierbrea Feb 16, 2021
a75f1b8
docs: fix method name
javierbrea Feb 16, 2021
faadeb0
chore(release): upgrade version
javierbrea Feb 16, 2021
0b7a578
chore(deps): update dependency @mocks-server/main to v1.9.0
renovate-bot Feb 16, 2021
6e8ffab
Merge pull request #147 from mocks-server/renovate/mocks-server-main-1.x
renovate[bot] Feb 16, 2021
0d14182
chore(deps): update dependency @testing-library/cypress to v7.0.3
renovate-bot Feb 16, 2021
4564b4f
Merge pull request #148 from mocks-server/renovate/testing-library-cy…
renovate[bot] Feb 17, 2021
1ea8527
chore(deps): update dependency babel-plugin-module-resolver to v4.1.0
renovate-bot Feb 17, 2021
218e940
chore: merge
javierbrea Feb 17, 2021
03975f9
Merge pull request #149 from mocks-server/renovate/babel-plugin-modul…
renovate[bot] Feb 17, 2021
1f869a2
chore(deps): update dependency eslint to v7.20.0
renovate-bot Feb 17, 2021
312b4fe
Merge pull request #150 from mocks-server/renovate/eslint-7.x
renovate[bot] Feb 17, 2021
7ddc372
chore(deps): update dependency eslint-plugin-prettier to v3.3.1
renovate-bot Feb 17, 2021
710d258
Merge pull request #151 from mocks-server/renovate/eslint-plugin-pret…
renovate[bot] Feb 17, 2021
4a19df6
chore(deps): Update dependencies
javierbrea Feb 17, 2021
d65f230
chore: merge
javierbrea Feb 17, 2021
a7738ff
Merge pull request #152 from mocks-server/pre-release
javierbrea Feb 17, 2021
57e1017
Merge branch 'master' into release
javierbrea Feb 17, 2021
73e819a
chore: remove publish tags
javierbrea Feb 17, 2021
10818f1
chore(release): Upgrade version
javierbrea Feb 17, 2021
46c613b
chore: add plugin tag to package.json
javierbrea Feb 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"node": true
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": "2018"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- master
- release
- pre-release
pull_request:
jobs:
test:
Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,52 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
### Fixed
### Removed
### Breaking changes

## [2.0.0] - 2021-02-17

### Added
- feat: Add `mocksConfig`, `mocksSetMock`, `mocksUseRouteVariant` and `mocksRestoreRoutesVariants` commands
- feat: Add support for environment variables `MOCKS_SERVER_ENABLED`, `MOCKS_SERVER_BASE_URL` and `MOCKS_SERVER_ADMIN_API_PATH` (#3)

### Changed
- feat: Rename `mocksServerSetBehavior` command to `mocksSetBehavior`
- feat: Rename `mocksServerSetDelay` command to `mocksSetDelay`
- feat: Rename `mocksServerSetSettings` command to `mocksSetSettings`
- chore(deps): Update dependencies to mocks-server v2 compatible versions
- chore(deps): Update Cypress to v6 in tests

### Removed
- feat: Remove `config` method, `cy.mocksConfig` command should be used instead
- test(e2e): Remove e2e tests using data-provider, as it does not concern to this package

### Breaking changes
- Rename `mocksServerSetBehavior` command to `mocksSetBehavior`
- Rename `mocksServerSetDelay` command to `mocksSetDelay`
- Rename `mocksServerSetSettings` command to `mocksSetSettings`
- Remove `config` method, `cy.mocksConfig` command should be used instead

## [2.0.0-beta.1] - 2021-02-16

### Added
- feat: Add `mocksConfig`, `mocksSetMock`, `mocksUseRouteVariant` and `mocksRestoreRoutesVariants` commands
- feat: Add support for environment variables `MOCKS_SERVER_ENABLED`, `MOCKS_SERVER_BASE_URL` and `MOCKS_SERVER_ADMIN_API_PATH` (#3)

### Changed
- feat: Rename `mocksServerSetBehavior` command to `mocksSetBehavior`
- feat: Rename `mocksServerSetDelay` command to `mocksSetDelay`
- feat: Rename `mocksServerSetSettings` command to `mocksSetSettings`
- chore(deps): Update dependencies to mocks-server v2 compatible versions

### Removed
- feat: Remove `config` method, `cy.mocksConfig` command should be used instead
- test(e2e): Remove e2e tests using data-provider, as it does not concern to this package

### Breaking changes
- Rename `mocksServerSetBehavior` command to `mocksSetBehavior`
- Rename `mocksServerSetDelay` command to `mocksSetDelay`
- Rename `mocksServerSetSettings` command to `mocksSetSettings`
- Remove `config` method, `cy.mocksConfig` command should be used instead

## [1.0.8] - 2020-12-21

Expand Down
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[![NPM downloads][npm-downloads-image]][npm-downloads-url] [![License][license-image]][license-url]


# Mocks server Cypress commands
# Mocks Server Cypress commands

This solution provides you commands for easily changing [@mocks-server settings][mocks-server-options-url], such as current behavior, delay time, etc.
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.

## Installation

Expand All @@ -31,51 +31,52 @@ You can now use all next commands:

### Commands

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

```js
cy.mocksServerSetBehavior("admin-user");
```
Sets current mock.

Set delay time:
##### `cy.mocksUseRouteVariant("users:success")`

```js
cy.mocksServerSetDelay(2000);
```
Sets a specific route variant to be used by current mock.

Set any setting:
##### `cy.mocksRestoreRoutesVariants()`

```js
cy.mocksServerSetSettings({
watch: false,
delay: 0,
behavior: "catalog-error"
});
```
Restore routes variants to those defined in current mock.

## Configuration
##### `cy.mocksSetDelay(2000)`

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]
Sets delay time.

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`:
##### `cy.mocksSetSettings({ watch: false, delay: 0 })`

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

config({
adminApiPath: "/foo-admin",
baseUrl: "http://my-mocks-server:3200"
});
```
##### `cy.mocksConfig({ adminApiPath: "/foo", baseUrl: "http://localhost:3000" })`

Configures the [Mocks Server administration API client](https://github.com/mocks-server/admin-api-client), used under the hood.

##### `cy.mocksSetBehavior("foo")`

Legacy method that sets behavior in Mocks Server v1.x

## Configuration

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]

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:

* __`MOCKS_SERVER_BASE_URL`__: Modifies the base url of Mocks Server. Default is `http://localhost:3100`.
* __`MOCKS_SERVER_ADMIN_API_PATH`__: Modifies the path of the Mocks Server administration API. Default is `/admin`.
* __`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.

### Using commands

You should usually change the mock server settings in a `before` statement:
You should usually change Mocks Server settings in a `before` statement:

```js
describe("user with default role", () => {
before(() => {
cy.mocksServerSetBehavior("normal-user");
cy.mocksSetMock("normal-user");
cy.visit("/");
});

Expand All @@ -86,7 +87,7 @@ describe("user with default role", () => {

describe("user with admin role", () => {
before(() => {
cy.mocksServerSetBehavior("admin-user");
cy.mocksSetMock("admin-user");
cy.visit("/");
});

Expand Down
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/* global Cypress */

const { config } = require("./src/commands");
const register = require("./src/register");

register(Cypress);

module.exports = {
config,
};
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = {
},

// The glob patterns Jest uses to detect test files
testMatch: ["**/test/**/?(*.)+(spec|test).js?(x)"],
testMatch: ["<rootDir>/test/**/*.spec.js"],
// testMatch: ["<rootDir>/test/**/commands.spec.js"],

// The test environment that will be used for testing
testEnvironment: "node",
Expand Down
Loading