Skip to content

Commit 52a8cc1

Browse files
committed
Change to use env store current backend endpoint
Signed-off-by: Lin Wang <[email protected]>
1 parent 3650221 commit 52a8cc1

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

cypress/utils/commands.js

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,41 @@ export const CURRENT_TENANT = {
2727
};
2828

2929
// Overwrite default backend endpoint to customized one, remember set to original value after tests complete.
30-
export const currentBackendEndpoint = (() => {
31-
let currentEndpoint = BACKEND_BASE_PATH;
32-
const DEFAULT_ENDPOINT = BACKEND_BASE_PATH;
33-
const REMOTE_NO_AUTH_ENDPOINT = Cypress.env('remoteDataSourceNoAuthUrl');
34-
35-
return Object.freeze({
36-
DEFAULT: DEFAULT_ENDPOINT,
37-
REMOTE_NO_AUTH: REMOTE_NO_AUTH_ENDPOINT,
38-
/**
39-
* Change current backend endpoint
40-
* @param {*} changedEndPoint
41-
* @param {*} immediately set immediately false to change tenant after all pending promise be invoked,
42-
* useful for reset backend endpoint after all tests run.
43-
*/
44-
set(changedEndPoint, immediately = true) {
45-
if (
46-
![DEFAULT_ENDPOINT, REMOTE_NO_AUTH_ENDPOINT].includes(changedEndPoint)
47-
) {
48-
throw new Error(`Invalid endpoint:${changedEndPoint}`);
49-
}
50-
const updateEndpoint = () => {
51-
currentEndpoint = changedEndPoint;
52-
cy.log(
53-
`Current backend endpoint has been changed to: ${currentEndpoint}`
54-
);
55-
};
56-
if (immediately) {
57-
updateEndpoint();
58-
} else {
59-
cy.wrap().then(updateEndpoint);
60-
}
61-
},
62-
get() {
63-
return currentEndpoint;
64-
},
65-
});
66-
})();
30+
export const currentBackendEndpoint = Object.freeze({
31+
DEFAULT: BACKEND_BASE_PATH,
32+
REMOTE_NO_AUTH: Cypress.env('remoteDataSourceNoAuthUrl'),
33+
/**
34+
* Change current backend endpoint
35+
* @param {*} changedEndPoint
36+
* @param {*} immediately set immediately false to change tenant after all pending promise be invoked,
37+
* useful for reset backend endpoint after all tests run.
38+
*/
39+
set(changedEndPoint, immediately = true) {
40+
if (
41+
![currentBackendEndpoint.DEFAULT, currentBackendEndpoint.REMOTE_NO_AUTH].includes(
42+
changedEndPoint
43+
)
44+
) {
45+
throw new Error(`Invalid endpoint:${changedEndPoint}`);
46+
}
47+
const updateEndpoint = () => {
48+
Cypress.env('currentBackendEndpoint', changedEndPoint);
49+
cy.log(
50+
`Current backend endpoint has been changed to: ${changedEndPoint}`
51+
);
52+
};
53+
if (immediately) {
54+
updateEndpoint();
55+
} else {
56+
cy.wrap().then(updateEndpoint);
57+
}
58+
},
59+
get() {
60+
return (
61+
Cypress.env('currentBackendEndpoint') || currentBackendEndpoint.DEFAULT
62+
);
63+
},
64+
});
6765

6866
export const supressNoRequestOccurred = () => {
6967
cy.on('fail', (err) => {

0 commit comments

Comments
 (0)