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

Commit a7738ff

Browse files
authored
Merge pull request #152 from mocks-server/pre-release
Release v2.0.0
2 parents 710d258 + d65f230 commit a7738ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+717
-2553
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"env": {
3-
"node": true
3+
"node": true,
4+
"es6": true
45
},
56
"parserOptions": {
67
"ecmaVersion": "2018"

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches:
55
- master
66
- release
7+
- pre-release
78
pull_request:
89
jobs:
910
test:

.github/workflows/publish-to-github.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
registry-url: 'https://npm.pkg.github.com'
1414
# Defaults to the user or organization that owns the workflow file
1515
scope: '@mocks-server'
16-
- run: npm publish
16+
- run: npm publish --tag beta
1717
env:
1818
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish-to-npm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
with:
1212
node-version: '12.x'
1313
registry-url: 'https://registry.npmjs.org/'
14-
- run: npm publish
14+
- run: npm publish --tag beta
1515
env:
1616
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
### Changed
1010
### Fixed
1111
### Removed
12+
### Breaking changes
13+
14+
## [2.0.0-beta.1] - 2021-02-16
15+
16+
### Added
17+
- feat: Add `mocksConfig`, `mocksSetMock`, `mocksUseRouteVariant` and `mocksRestoreRoutesVariants` commands
18+
- feat: Add support for environment variables `MOCKS_SERVER_ENABLED`, `MOCKS_SERVER_BASE_URL` and `MOCKS_SERVER_ADMIN_API_PATH` (#3)
19+
20+
### Changed
21+
- feat: Rename `mocksServerSetBehavior` command to `mocksSetBehavior`
22+
- feat: Rename `mocksServerSetDelay` command to `mocksSetDelay`
23+
- feat: Rename `mocksServerSetSettings` command to `mocksSetSettings`
24+
- chore(deps): Update dependencies to mocks-server v2 compatible versions
25+
26+
### Removed
27+
- feat: Remove `config` method, `cy.mocksConfig` command should be used instead
28+
- test(e2e): Remove e2e tests using data-provider, as it does not concern to this package
29+
30+
### Breaking changes
31+
- Rename `mocksServerSetBehavior` command to `mocksSetBehavior`
32+
- Rename `mocksServerSetDelay` command to `mocksSetDelay`
33+
- Rename `mocksServerSetSettings` command to `mocksSetSettings`
34+
- Remove `config` method, `cy.mocksConfig` command should be used instead
1235

1336
## [1.0.8] - 2020-12-21
1437

README.md

Lines changed: 32 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,52 @@ 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+
##### `cy.mocksSetBehavior("foo")`
59+
60+
Legacy method that sets behavior in Mocks Server v1.x
61+
62+
## Configuration
63+
64+
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]
65+
66+
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:
67+
68+
* __`MOCKS_SERVER_BASE_URL`__: Modifies the base url of Mocks Server. Default is `http://localhost:3100`.
69+
* __`MOCKS_SERVER_ADMIN_API_PATH`__: Modifies the path of the Mocks Server administration API. Default is `/admin`.
70+
* __`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.
7071

7172
### Using commands
7273

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

7576
```js
7677
describe("user with default role", () => {
7778
before(() => {
78-
cy.mocksServerSetBehavior("normal-user");
79+
cy.mocksSetMock("normal-user");
7980
cy.visit("/");
8081
});
8182

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

8788
describe("user with admin role", () => {
8889
before(() => {
89-
cy.mocksServerSetBehavior("admin-user");
90+
cy.mocksSetMock("admin-user");
9091
cy.visit("/");
9192
});
9293

index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/* global Cypress */
22

3-
const { config } = require("./src/commands");
43
const register = require("./src/register");
54

65
register(Cypress);
7-
8-
module.exports = {
9-
config,
10-
};

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module.exports = {
2525
},
2626

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

3031
// The test environment that will be used for testing
3132
testEnvironment: "node",

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "@mocks-server/cypress-commands",
3-
"version": "1.0.8",
4-
"description": "Extends Cypress' cy commands with methods for administrating mocks-server",
3+
"version": "2.0.0-beta.1",
4+
"description": "Extends Cypress' cy commands with methods for administrating Mocks Server",
55
"keywords": [
66
"cypress",
77
"commands",
88
"mocks-server",
9-
"mock-server",
9+
"mock",
10+
"server",
1011
"administration",
1112
"admin",
1213
"api",
@@ -26,15 +27,15 @@
2627
],
2728
"main": "index.js",
2829
"scripts": {
29-
"lint": "eslint src test *.js jest.config.js test-e2e/cypress test-e2e/mocks test-e2e/app-fetch/public test-e2e/app-data-provider/src test-e2e/app-data-provider/webpack.config.js",
30+
"lint": "eslint src test *.js jest.config.js test-e2e/cypress test-e2e/mocks-legacy test-e2e/app/*.js",
3031
"lint-staged": "lint-staged",
3132
"test": "jest",
3233
"test:e2e": "cd test-e2e && npm run test:ci",
3334
"test:e2e:ci": "cd test-e2e && npm i && npm run apps:install && npm run test:ci",
3435
"test:unit": "npm run test"
3536
},
3637
"dependencies": {
37-
"@mocks-server/admin-api-client": "2.0.4"
38+
"@mocks-server/admin-api-client": "3.0.0"
3839
},
3940
"devDependencies": {
4041
"babel-eslint": "10.1.0",
@@ -51,10 +52,8 @@
5152
"cypress": "2.x || 3.x || 4.x || 5.x || 6.x"
5253
},
5354
"lint-staged": {
54-
"test-e2e/app-data-provider/*.js": "eslint",
55-
"test-e2e/app-data-provider/src/*.js": "eslint",
56-
"test-e2e/app-fetch/public/*.js": "eslint",
57-
"test-e2e/mocks/**/*.js": "eslint",
55+
"test-e2e/app/*.js": "eslint",
56+
"test-e2e/mocks-legacy/**/*.js": "eslint",
5857
"test-e2e/cypress/**/*.js": "eslint",
5958
"*.js": "eslint",
6059
"src/**/*.js": "eslint",

0 commit comments

Comments
 (0)