Skip to content

Commit 7ca0671

Browse files
johncowenschogges
andauthored
chore(ci): disable mocks by default everywhere apart from PR previews (#5099)
See title Note: locally during development you probably never need to use the KUMA_MOCK_API_ENABLED cookie anymore as it will use the local node server for mocks which is much more reliable. I guess thew only time you might need to set it is if you happen to have no internet connection and you want the call to `https://kuma.io/latest_version` to resolve with a mock response. In this case you can still enable the MSW mocks. TL;DR and most importantly, we no longer have to explicitly set `KUMA_MOCK_API_ENABLED` to `false` locally. In a preview its built with the MSW mocks enabled by default (but you can turn them off whilst previewing with cookies should we need to) --------- Signed-off-by: John Cowen <john.cowen@konghq.com> Signed-off-by: John Cowen <johncowen@users.noreply.github.com> Co-authored-by: Mo <24444046+schogges@users.noreply.github.com>
1 parent 700eabf commit 7ca0671

6 files changed

Lines changed: 37 additions & 32 deletions

File tree

packages/config/src/mk/build.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
.PHONY: build/preview
1010
build/preview: VITE ?= $(shell $(MAKE) resolve/bin BIN=vite)
11-
build/preview:
12-
@$(VITE) \
11+
build/preview: ## Dev: Create preview build with mocks on by default
12+
@KUMA_MOCK_API_ENABLED=true $(VITE) \
1313
--configLoader runner \
1414
-c ./vite.config.production.ts \
1515
--mode preview \

packages/config/src/vite/config/vite.config.base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { UserConfig, UserConfigFn } from 'vite'
77

88
export const defineConfig: UserConfigFn = () => ({
99
base: './',
10+
envPrefix: 'KUMA_',
1011
server: {
1112
port: 8080,
1213
},

packages/gherkin-web/src/cypress/steps/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ export async function setupSteps<TMock extends BaseMock>({ mock, client = getCli
120120
// act
121121

122122
When('I visit the {string} URL', function (path: string) {
123-
// turn off MSW in dev environments so we can use cy.intercept
124-
cy.setCookie('KUMA_MOCK_API_ENABLED', 'false')
125-
//
126123
cy.getAllCookies().then((cookies) => {
127124
cy.visit(`${path}`)
128125
const sel = client.waitForVisit(`${path}`, cookies, cy)

packages/gherkin-web/src/playwright/steps/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ export async function setupSteps({
7878
selectors = {}
7979
localStorage = new Set()
8080
await context.unrouteAll()
81-
await context.addCookies([
82-
{
83-
name: 'KUMA_MOCK_API_ENABLED',
84-
value: 'false',
85-
url: `${baseURL}`,
86-
},
87-
])
8881
const p = Object.keys(fs).map(route => {
8982
return context.route(
9083
(u) => routeToRegexp(route).test(u.toString()),

packages/kuma-gui/README.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Install the project’s dependencies.
3838
make install
3939
```
4040

41+
> [!NOTE]
42+
> `make install` will also run every time you run `make run`, so you generally
43+
> don't need to use `make install`.
44+
45+
4146
## Starting the development server
4247

4348
Start a development server (runs on [localhost:8080](http://localhost:8080/) by
@@ -47,8 +52,8 @@ default):
4752
make run
4853
```
4954

50-
The default development mode uses [msw](https://mswjs.io/) with custom mock
51-
data so you dont have to run anything else to start exploring.
55+
The default development mode uses a local vite based server with custom mock
56+
data so you don't have to run anything else to start exploring.
5257

5358
Alternatively, make the development mode use a real Kuma installation running
5459
at <http://localhost:5681>.
@@ -59,17 +64,28 @@ at <http://localhost:5681>.
5964
> [github.com/kumahq/kuma](https://github.com/kumahq/kuma/) to find out how to do
6065
> that.
6166
>
67+
> In order to allow your locally running GUI (on port 8080) to use the real Kuma
68+
> HTTP API (on port 5681) you should use `KUMA_API_SERVER_CORS_ALLOWED_DOMAINS`
69+
> when starting the Kuma Control Plane.
70+
>
6271
> You can confirm Kuma is running by accessing its API:
6372
>
6473
> ```sh
6574
> curl http://localhost:5681/
6675
> ```
6776
68-
Once installed you can make the development server/GUI use Kuma by adding a
69-
`KUMA_MOCK_API_ENABLED=false` cookie to your browser. You can do this my using
70-
the browser's Application/Cookies settings in Web Inspector, or by clicking
71-
<http://localhost:8080/gui/#KUMA_MOCK_API_ENABLED=false> (and set it back again
72-
by clicking <http://localhost:8080/gui/#KUMA_MOCK_API_ENABLED=true>)
77+
Once Kuma is running you can make the development server/GUI use Kuma by adding
78+
a `KUMA_API_URL=http://localhost:5681` cookie to your browser. You can do this
79+
by using the browser's Application/Cookies settings in Web Inspector. We also
80+
provide bookmarklets to let you toggle this easily.
81+
82+
If the development GUI cannot contact Kuma's HTTP API, please check Kuma's
83+
`KUMA_API_SERVER_CORS_ALLOWED_DOMAINS` setting.
84+
85+
> [!NOTE]
86+
> We generate a full static preview for every PR. These are fully static and
87+
> therefore cannot use a local (or remote) vite server to serve the HTTP API
88+
> mocks. Instead, only on PR previews, we use MSW to serve the very same mocks.
7389
7490
### Disabling anonymous reports in Kuma
7591
@@ -87,8 +103,8 @@ echo "export KUMA_REPORTS_ENABLED=false" >> ~/.profile
87103
make build
88104
```
89105
90-
> [!TIP]
91-
> NOTE In production environments, the GUI application is typically served at
106+
> [!NOTE]
107+
> In production environments, the GUI application is typically served at
92108
> [localhost:5681/gui/](http://localhost:5681/gui/).
93109
94110
## Run unit tests
@@ -108,28 +124,26 @@ make run
108124
Run the browser test UI in another terminal window:
109125
110126
```sh
111-
KUMA_BASE_URL=http://localhost:8080/gui KUMA_TEST_BROWSER=chrome make
112-
test/e2e
127+
KUMA_TEST_BROWSER=chrome make test/e2e
113128
```
114129
115-
The above environment variables:
116-
117-
1. Point the e2e tests to use the locally running GUI on localhost:8080
118-
2. Tell the e2e tests to open and run in Chrome
130+
The above environment variable tells the e2e tests to open and run in Chrome.
119131
120132
> [!TIP]
121-
> NOTE If you are running tests often you should consider adding these
133+
> If you are running tests often you should consider adding these
122134
> environment variables to your shell profile:
123135
>
124136
> ```sh
125-
> export KUMA_BASE_URL=http://localhost:8080/gui export
126-
> KUMA_TEST_BROWSER=chrome make test/e2e
137+
> export KUMA_TEST_BROWSER=chrome
127138
> ```
128139
>
129140
> You can then just run:
130141
>
131142
> ```sh
132-
> make run make test/e2e
143+
> # in one terminal
144+
> make run
145+
> # in another terminal
146+
> make test/e2e
133147
> ```
134148
>
135149

packages/kuma-gui/src/app/kuma/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const services = (app: Record<string, Token>): ServiceDefinition[] => [
5252
[token('kuma.debug.env.vars'), {
5353
service: () => {
5454
return {
55-
KUMA_MOCK_API_ENABLED: () => 'true',
55+
KUMA_MOCK_API_ENABLED: () => import.meta.env.KUMA_MOCK_API_ENABLED ?? '',
5656
}
5757
},
5858
labels: [

0 commit comments

Comments
 (0)