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

Commit

Permalink
Merge pull request #153 from mocks-server/release
Browse files Browse the repository at this point in the history
Release v2.0.0
  • Loading branch information
javierbrea authored Feb 17, 2021
2 parents 7ca4cf9 + 46c613b commit cbf22f1
Show file tree
Hide file tree
Showing 41 changed files with 973 additions and 2,665 deletions.
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

0 comments on commit cbf22f1

Please sign in to comment.