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

Commit f3d8dcb

Browse files
committed
Add e2e test for checking config method
1 parent 7045760 commit f3d8dcb

File tree

9 files changed

+91
-8
lines changed

9 files changed

+91
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ You can change both the base url of the "@mocks-server", and the base api path o
6363
import { config } from "@mocks-server/cypress-commands";
6464

6565
config({
66-
apiPath: "/foo-admin",
66+
adminApiPath: "/foo-admin",
6767
baseUrl: "http://my-mocks-server:3200"
6868
});
6969
```

src/commands.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ const setSettings = newSettings => {
1616
return settings.update(newSettings);
1717
};
1818

19+
// TODO, remove when admin-api-client supports adminApiPath option
20+
const mapConfig = customConfig => {
21+
const configToSet = customConfig;
22+
if (customConfig.adminApiPath) {
23+
configToSet.apiPath = customConfig.adminApiPath;
24+
}
25+
return config(configToSet);
26+
};
27+
1928
module.exports = {
2029
setBehavior,
2130
setDelay,
2231
setSettings,
23-
config
32+
config: mapConfig
2433
};

test-e2e/app-data-provider/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let $response;
66
let $responseTime;
77

88
const response = new Api("/api/response", {
9-
baseUrl: "http://localhost:3100"
9+
baseUrl: `http://localhost:${process.env.PORT}`
1010
});
1111

1212
const loadResponse = async function() {
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
const webpack = require("webpack");
12
const path = require("path");
23

34
module.exports = {
45
entry: "./src/index.js",
56
output: {
67
path: path.resolve(__dirname, "public"),
78
filename: "main.js"
8-
}
9+
},
10+
plugins: [
11+
new webpack.EnvironmentPlugin({
12+
PORT: 3100
13+
})
14+
]
915
};

test-e2e/cypress.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"baseUrl": "http://localhost:3000",
3-
"video": false
3+
"video": false,
4+
"env": {
5+
"MOCKS_ADMIN_API_PATH": "/admin",
6+
"MOCKS_URL": "http://localhost:3100"
7+
}
48
}

test-e2e/cypress/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"es6": true
55
},
66
"globals": {
7+
"Cypress": true,
78
"cy": true,
89
"afterEach": true,
910
"after": true,
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
import "@mocks-server/cypress-commands";
1+
import { config } from "@mocks-server/cypress-commands";
2+
3+
config({
4+
adminApiPath: Cypress.env("MOCKS_ADMIN_API_PATH"),
5+
baseUrl: Cypress.env("MOCKS_URL")
6+
});

test-e2e/package-lock.json

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

test-e2e/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@
55
"scripts": {
66
"mocks": "mocks-server",
77
"mocks:ci": "mocks-server --cli=false",
8+
"mocks:ci:custom-config": "mocks-server --cli=false --port=3200 --adminApiPath=/foo",
89
"cypress:install": "cypress install",
910
"cypress:verify": "cypress verify",
1011
"cypress:open": "cypress open",
1112
"cypress:run": "cypress run",
13+
"cypress:run:custom-config": "cross-env CYPRESS_MOCKS_URL=http://localhost:3200 CYPRESS_MOCKS_ADMIN_API_PATH=/foo cypress run",
1214
"start:app-fetch": "cd app-fetch && npm run serve",
1315
"start:app-data-provider": "cd app-data-provider && npm run build-and-serve",
16+
"start:app-data-provider:custom-config": "cd app-data-provider && cross-env PORT=3200 npm run build-and-serve",
1417
"mocks:ci-and-start:app-fetch": "start-server-and-test mocks:ci http-get://localhost:3100/admin/about start:app-fetch",
1518
"mocks:ci-and-start:app-data-provider": "start-server-and-test mocks:ci http-get://localhost:3100/admin/about start:app-data-provider",
19+
"mocks:ci:custom-config-and-start:app-data-provider:custom-config": "start-server-and-test mocks:ci:custom-config http-get://localhost:3200/foo/about start:app-data-provider:custom-config",
1620
"test:app-fetch": "start-server-and-test mocks:ci-and-start:app-fetch http-get://localhost:3000 cypress:run",
1721
"test:app-data-provider": "start-server-and-test mocks:ci-and-start:app-data-provider http-get://localhost:3000 cypress:run",
22+
"test:app-data-provider-custom-config": "start-server-and-test mocks:ci:custom-config-and-start:app-data-provider:custom-config http-get://localhost:3000 cypress:run:custom-config",
1823
"apps:install": "cd app-fetch && npm i && cd ../app-data-provider && npm i",
19-
"test:ci": "npm run test:app-fetch && npm run test:app-data-provider"
24+
"test:ci": "npm run test:app-fetch && npm run test:app-data-provider && npm run test:app-data-provider-custom-config"
2025
},
2126
"devDependencies": {
22-
"babel-plugin-module-resolver": "^3.2.0",
2327
"@mocks-server/main": "^1.6.1",
2428
"@testing-library/cypress": "^5.0.2",
29+
"babel-plugin-module-resolver": "^3.2.0",
30+
"cross-env": "^6.0.3",
2531
"cypress": "3.1.5",
2632
"start-server-and-test": "^1.10.6"
2733
}

0 commit comments

Comments
 (0)