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

Commit 523678e

Browse files
committed
fix: do not call to set config when env vars are not defined
1 parent 4dd7db0 commit 523678e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/commands.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ function commands(Cypress) {
6868
return apiClient.config(customConfig);
6969
};
7070

71-
config({
72-
adminApiPath: Cypress.env(ADMIN_API_PATH_ENVIRONMENT_VAR),
73-
baseUrl: Cypress.env(BASE_URL_ENVIRONMENT_VAR),
74-
});
71+
if (Cypress.env(ADMIN_API_PATH_ENVIRONMENT_VAR)) {
72+
config({ adminApiPath: Cypress.env(ADMIN_API_PATH_ENVIRONMENT_VAR) });
73+
}
74+
if (Cypress.env(BASE_URL_ENVIRONMENT_VAR)) {
75+
config({ baseUrl: Cypress.env(BASE_URL_ENVIRONMENT_VAR) });
76+
}
7577

7678
return {
7779
setBehavior,

test/commands.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ describe("commands", () => {
3232
sandbox.restore();
3333
});
3434

35+
describe("when initializing", () => {
36+
it("should call to set adminApiPath config if env var is defined", () => {
37+
cypressMock.stubs.env.withArgs("MOCKS_SERVER_ADMIN_API_PATH").returns("foo");
38+
commands(cypressMock.stubs);
39+
expect(
40+
apiClient.config.calledWith({
41+
adminApiPath: "foo",
42+
})
43+
).toBe(true);
44+
});
45+
46+
it("should call to set baseUrl config if env var is defined", () => {
47+
cypressMock.stubs.env.withArgs("MOCKS_SERVER_BASE_URL").returns("foo");
48+
commands(cypressMock.stubs);
49+
expect(
50+
apiClient.config.calledWith({
51+
baseUrl: "foo",
52+
})
53+
).toBe(true);
54+
});
55+
});
56+
3557
describe("setMock command", () => {
3658
it("should call to update delay", () => {
3759
setMock("foo");

0 commit comments

Comments
 (0)