@commercetools-frontend/cypress 21.14.3 → 21.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/add-commands/dist/commercetools-frontend-cypress-add-commands.cjs.dev.js +160 -26
- package/add-commands/dist/commercetools-frontend-cypress-add-commands.cjs.prod.js +160 -26
- package/add-commands/dist/commercetools-frontend-cypress-add-commands.esm.js +159 -26
- package/add-commands/index.d.ts +17 -1
- package/dist/commercetools-frontend-cypress.cjs.dev.js +1 -1
- package/dist/commercetools-frontend-cypress.cjs.prod.js +1 -1
- package/dist/commercetools-frontend-cypress.esm.js +1 -1
- package/dist/declarations/src/add-commands/index.d.ts +2 -43
- package/dist/declarations/src/add-commands/login.d.ts +53 -0
- package/package.json +4 -4
|
@@ -11,9 +11,10 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
|
|
|
11
11
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
12
12
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
13
13
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
14
|
+
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
14
15
|
var uuid = require('uuid');
|
|
15
|
-
var constants = require('../../dist/constants-42a0ebf5.cjs.dev.js');
|
|
16
16
|
var ssr = require('@commercetools-frontend/application-shell/ssr');
|
|
17
|
+
var constants = require('../../dist/constants-42a0ebf5.cjs.dev.js');
|
|
17
18
|
|
|
18
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
20
|
|
|
@@ -27,19 +28,98 @@ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$def
|
|
|
27
28
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
28
29
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
29
30
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
31
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
30
32
|
|
|
31
33
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
32
34
|
|
|
33
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
35
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
function loginByForm(commandOptions) {
|
|
36
38
|
var _commandOptions$proje;
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
40
|
+
if (isLocalhost()) {
|
|
41
|
+
throw new Error("At the moment, the \"loginByForm\" command only works when testing a Merchant Center production URL. Using form login in an application running on localhost is not supported due to issues with \"cy.origin\".");
|
|
42
|
+
}
|
|
43
|
+
|
|
41
44
|
var projectKey = (_commandOptions$proje = commandOptions.projectKey) !== null && _commandOptions$proje !== void 0 ? _commandOptions$proje : Cypress.env('PROJECT_KEY');
|
|
45
|
+
cy.task('customApplicationConfig', {
|
|
46
|
+
entryPointUriPath: commandOptions.entryPointUriPath,
|
|
47
|
+
dotfiles: commandOptions.dotfiles
|
|
48
|
+
}, // Do not show log, as it may contain sensible information.
|
|
49
|
+
{
|
|
50
|
+
log: false
|
|
51
|
+
}).then(function (appConfig) {
|
|
52
|
+
var _context, _commandOptions$login;
|
|
53
|
+
|
|
54
|
+
var url = _concatInstanceProperty__default["default"](_context = "/".concat(projectKey, "/")).call(_context, commandOptions.entryPointUriPath);
|
|
55
|
+
|
|
56
|
+
if (commandOptions.entryPointUriPath === 'account') {
|
|
57
|
+
url = "/".concat(commandOptions.entryPointUriPath);
|
|
58
|
+
} // Log loaded application config for debugging purposes.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Cypress.log({
|
|
62
|
+
displayName: 'task',
|
|
63
|
+
name: 'customApplicationConfig',
|
|
64
|
+
message: appConfig
|
|
65
|
+
});
|
|
66
|
+
var userCredentials = (_commandOptions$login = commandOptions.login) !== null && _commandOptions$login !== void 0 ? _commandOptions$login : {
|
|
67
|
+
email: Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER'),
|
|
68
|
+
password: Cypress.env('LOGIN_PASSWORD')
|
|
69
|
+
};
|
|
70
|
+
var sessionKey = ['loginByForm', userCredentials.email, commandOptions.entryPointUriPath]; // const mcUrl = new URL(appConfig.mcApiUrl);
|
|
71
|
+
// const mcFrontendHostname = mcUrl.hostname.replace('mc-api', 'mc');
|
|
72
|
+
|
|
73
|
+
function authCallback() {
|
|
74
|
+
cy.visit(url); // NOTE: using `cy.origin` is currently disabled as it does not seem to properly work.
|
|
75
|
+
// Interestingly, starting an application locally using Vite works, however not when using Webpack.
|
|
76
|
+
// For now we keep it disabled until we find a solution.
|
|
77
|
+
// // https://cypress.io/blog/2022/04/25/cypress-9-6-0-easily-test-multi-domain-workflows-with-cy-origin/
|
|
78
|
+
// cy.origin(
|
|
79
|
+
// mcFrontendHostname,
|
|
80
|
+
// { args: userCredentials },
|
|
81
|
+
// fillLoginForm
|
|
82
|
+
// );
|
|
83
|
+
|
|
84
|
+
fillLoginForm(userCredentials); // Wait for the route to be loaded so that the session can be saved.
|
|
85
|
+
|
|
86
|
+
cy.url().should('include', url);
|
|
87
|
+
} // For backwards compatibility.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (Cypress.config('experimentalSessionAndOrigin')) {
|
|
91
|
+
// https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
|
|
92
|
+
cy.session(sessionKey, authCallback, {
|
|
93
|
+
cacheAcrossSpecs: typeof commandOptions.disableCacheAcrossSpecs === 'boolean' ? !commandOptions.disableCacheAcrossSpecs : true
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
cy.log("We recommend turning on the flag \"experimentalSessionAndOrigin\" to be able to use \"cy.session\" and thus reduce the time to log in between tests.");
|
|
97
|
+
authCallback();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (commandOptions.initialRoute) {
|
|
101
|
+
var _context2;
|
|
102
|
+
|
|
103
|
+
cy.visit(_concatInstanceProperty__default["default"](_context2 = "".concat(Cypress.config('baseUrl'))).call(_context2, commandOptions.initialRoute));
|
|
104
|
+
cy.url().should('include', commandOptions.initialRoute);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function loginByOidc(commandOptions) {
|
|
110
|
+
if (!isLocalhost()) {
|
|
111
|
+
throw new Error("The \"loginByOidc\" command only works when testing a Custom Application running on localhost.");
|
|
112
|
+
}
|
|
113
|
+
|
|
42
114
|
var sessionNonce = uuid.v4();
|
|
115
|
+
var projectKey = undefined;
|
|
116
|
+
|
|
117
|
+
if (commandOptions.entryPointUriPath !== 'account') {
|
|
118
|
+
var _commandOptions$proje2;
|
|
119
|
+
|
|
120
|
+
projectKey = (_commandOptions$proje2 = commandOptions.projectKey) !== null && _commandOptions$proje2 !== void 0 ? _commandOptions$proje2 : Cypress.env('PROJECT_KEY');
|
|
121
|
+
}
|
|
122
|
+
|
|
43
123
|
cy.task('customApplicationConfig', {
|
|
44
124
|
entryPointUriPath: commandOptions.entryPointUriPath,
|
|
45
125
|
dotfiles: commandOptions.dotfiles
|
|
@@ -47,7 +127,7 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
47
127
|
{
|
|
48
128
|
log: false
|
|
49
129
|
}).then(function (appConfig) {
|
|
50
|
-
var _appConfig$__DEVELOPM, _appConfig$__DEVELOPM2, _appConfig$__DEVELOPM3, _appConfig$__DEVELOPM4, _commandOptions$
|
|
130
|
+
var _appConfig$__DEVELOPM, _appConfig$__DEVELOPM2, _appConfig$__DEVELOPM3, _appConfig$__DEVELOPM4, _commandOptions$login2;
|
|
51
131
|
|
|
52
132
|
// Log loaded application config for debugging purposes.
|
|
53
133
|
Cypress.log({
|
|
@@ -61,8 +141,8 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
61
141
|
oAuthScopes: (_appConfig$__DEVELOPM = appConfig.__DEVELOPMENT__) === null || _appConfig$__DEVELOPM === void 0 ? void 0 : (_appConfig$__DEVELOPM2 = _appConfig$__DEVELOPM.oidc) === null || _appConfig$__DEVELOPM2 === void 0 ? void 0 : _appConfig$__DEVELOPM2.oAuthScopes,
|
|
62
142
|
teamId: (_appConfig$__DEVELOPM3 = appConfig.__DEVELOPMENT__) === null || _appConfig$__DEVELOPM3 === void 0 ? void 0 : (_appConfig$__DEVELOPM4 = _appConfig$__DEVELOPM3.oidc) === null || _appConfig$__DEVELOPM4 === void 0 ? void 0 : _appConfig$__DEVELOPM4.teamId
|
|
63
143
|
});
|
|
64
|
-
var userCredentials = (_commandOptions$
|
|
65
|
-
email:
|
|
144
|
+
var userCredentials = (_commandOptions$login2 = commandOptions.login) !== null && _commandOptions$login2 !== void 0 ? _commandOptions$login2 : {
|
|
145
|
+
email: Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER'),
|
|
66
146
|
password: Cypress.env('LOGIN_PASSWORD')
|
|
67
147
|
}; // Perform the login using the API, then store some required values into the browser storage
|
|
68
148
|
// and redirect to the auth callback route.
|
|
@@ -80,29 +160,83 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
80
160
|
followRedirect: false
|
|
81
161
|
};
|
|
82
162
|
cy.request(requestOptions).then(function (res) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
win
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
163
|
+
var sessionKey = ['loginByOidc', userCredentials.email, commandOptions.entryPointUriPath];
|
|
164
|
+
|
|
165
|
+
function authCallback() {
|
|
166
|
+
cy.visit(res.body.redirectTo, {
|
|
167
|
+
onBeforeLoad: function onBeforeLoad(win) {
|
|
168
|
+
var _context3;
|
|
169
|
+
|
|
170
|
+
if (projectKey) {
|
|
171
|
+
win.localStorage.setItem(constants.STORAGE_KEYS.ACTIVE_PROJECT_KEY, projectKey);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
win.sessionStorage.setItem(_concatInstanceProperty__default["default"](_context3 = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context3, sessionNonce), _JSON$stringify__default["default"]({
|
|
175
|
+
applicationId: applicationId,
|
|
176
|
+
query: {}
|
|
177
|
+
}));
|
|
178
|
+
win.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_SCOPE, sessionScope);
|
|
179
|
+
|
|
180
|
+
if (commandOptions.onBeforeLoad) {
|
|
181
|
+
commandOptions.onBeforeLoad(win);
|
|
182
|
+
}
|
|
96
183
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
184
|
+
}); // Wait for the application to be loaded so that the session can be saved.
|
|
185
|
+
|
|
186
|
+
cy.get('#app-loader').should('not.exist');
|
|
187
|
+
} // For backwards compatibility.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if (Cypress.config('experimentalSessionAndOrigin')) {
|
|
191
|
+
// https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
|
|
192
|
+
cy.session(sessionKey, authCallback, {
|
|
193
|
+
cacheAcrossSpecs: typeof commandOptions.disableCacheAcrossSpecs === 'boolean' ? !commandOptions.disableCacheAcrossSpecs : true
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
cy.log("We recommend turning on the flag \"experimentalSessionAndOrigin\" to be able to use \"cy.session\" and thus reduce the time to log in between tests.");
|
|
197
|
+
authCallback();
|
|
198
|
+
}
|
|
99
199
|
|
|
100
200
|
if (commandOptions.initialRoute) {
|
|
101
|
-
var
|
|
201
|
+
var _context4;
|
|
102
202
|
|
|
103
|
-
cy.visit(_concatInstanceProperty__default["default"](
|
|
203
|
+
cy.visit(_concatInstanceProperty__default["default"](_context4 = "".concat(Cypress.config('baseUrl'))).call(_context4, commandOptions.initialRoute));
|
|
104
204
|
cy.url().should('include', commandOptions.initialRoute);
|
|
105
205
|
}
|
|
106
206
|
});
|
|
107
207
|
});
|
|
208
|
+
}
|
|
209
|
+
/* Utilities */
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
function fillLoginForm(userCredentials) {
|
|
213
|
+
cy.get('input[name=email]').type(userCredentials.email);
|
|
214
|
+
cy.get('input[name=password]').type(userCredentials.password, {
|
|
215
|
+
log: false
|
|
216
|
+
});
|
|
217
|
+
cy.get('button').contains('Sign in').click();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function isLocalhost() {
|
|
221
|
+
var baseUrl = new _URL__default["default"](Cypress.config('baseUrl'));
|
|
222
|
+
return baseUrl.hostname === 'localhost';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
Cypress.Commands.add('loginToMerchantCenter', function (commandOptions) {
|
|
226
|
+
Cypress.log({
|
|
227
|
+
name: 'loginToMerchantCenter'
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
if (isLocalhost()) {
|
|
231
|
+
loginByOidc(commandOptions);
|
|
232
|
+
} else {
|
|
233
|
+
loginByForm(commandOptions);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
237
|
+
Cypress.log({
|
|
238
|
+
name: 'loginByOidc'
|
|
239
|
+
});
|
|
240
|
+
cy.log('We recommend not to use the command "cy.loginByOidc" directly. Instead, use the more generic "cy.loginToMerchantCenter" command as it automatically detects which login mechanism to use.');
|
|
241
|
+
loginByOidc(commandOptions);
|
|
108
242
|
});
|
|
@@ -11,9 +11,10 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
|
|
|
11
11
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
12
12
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
13
13
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
14
|
+
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
14
15
|
var uuid = require('uuid');
|
|
15
|
-
var constants = require('../../dist/constants-4d9d4b7b.cjs.prod.js');
|
|
16
16
|
var ssr = require('@commercetools-frontend/application-shell/ssr');
|
|
17
|
+
var constants = require('../../dist/constants-4d9d4b7b.cjs.prod.js');
|
|
17
18
|
|
|
18
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
20
|
|
|
@@ -27,19 +28,98 @@ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$def
|
|
|
27
28
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
28
29
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
29
30
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
31
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
30
32
|
|
|
31
33
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
32
34
|
|
|
33
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
35
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
function loginByForm(commandOptions) {
|
|
36
38
|
var _commandOptions$proje;
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
40
|
+
if (isLocalhost()) {
|
|
41
|
+
throw new Error("At the moment, the \"loginByForm\" command only works when testing a Merchant Center production URL. Using form login in an application running on localhost is not supported due to issues with \"cy.origin\".");
|
|
42
|
+
}
|
|
43
|
+
|
|
41
44
|
var projectKey = (_commandOptions$proje = commandOptions.projectKey) !== null && _commandOptions$proje !== void 0 ? _commandOptions$proje : Cypress.env('PROJECT_KEY');
|
|
45
|
+
cy.task('customApplicationConfig', {
|
|
46
|
+
entryPointUriPath: commandOptions.entryPointUriPath,
|
|
47
|
+
dotfiles: commandOptions.dotfiles
|
|
48
|
+
}, // Do not show log, as it may contain sensible information.
|
|
49
|
+
{
|
|
50
|
+
log: false
|
|
51
|
+
}).then(function (appConfig) {
|
|
52
|
+
var _context, _commandOptions$login;
|
|
53
|
+
|
|
54
|
+
var url = _concatInstanceProperty__default["default"](_context = "/".concat(projectKey, "/")).call(_context, commandOptions.entryPointUriPath);
|
|
55
|
+
|
|
56
|
+
if (commandOptions.entryPointUriPath === 'account') {
|
|
57
|
+
url = "/".concat(commandOptions.entryPointUriPath);
|
|
58
|
+
} // Log loaded application config for debugging purposes.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Cypress.log({
|
|
62
|
+
displayName: 'task',
|
|
63
|
+
name: 'customApplicationConfig',
|
|
64
|
+
message: appConfig
|
|
65
|
+
});
|
|
66
|
+
var userCredentials = (_commandOptions$login = commandOptions.login) !== null && _commandOptions$login !== void 0 ? _commandOptions$login : {
|
|
67
|
+
email: Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER'),
|
|
68
|
+
password: Cypress.env('LOGIN_PASSWORD')
|
|
69
|
+
};
|
|
70
|
+
var sessionKey = ['loginByForm', userCredentials.email, commandOptions.entryPointUriPath]; // const mcUrl = new URL(appConfig.mcApiUrl);
|
|
71
|
+
// const mcFrontendHostname = mcUrl.hostname.replace('mc-api', 'mc');
|
|
72
|
+
|
|
73
|
+
function authCallback() {
|
|
74
|
+
cy.visit(url); // NOTE: using `cy.origin` is currently disabled as it does not seem to properly work.
|
|
75
|
+
// Interestingly, starting an application locally using Vite works, however not when using Webpack.
|
|
76
|
+
// For now we keep it disabled until we find a solution.
|
|
77
|
+
// // https://cypress.io/blog/2022/04/25/cypress-9-6-0-easily-test-multi-domain-workflows-with-cy-origin/
|
|
78
|
+
// cy.origin(
|
|
79
|
+
// mcFrontendHostname,
|
|
80
|
+
// { args: userCredentials },
|
|
81
|
+
// fillLoginForm
|
|
82
|
+
// );
|
|
83
|
+
|
|
84
|
+
fillLoginForm(userCredentials); // Wait for the route to be loaded so that the session can be saved.
|
|
85
|
+
|
|
86
|
+
cy.url().should('include', url);
|
|
87
|
+
} // For backwards compatibility.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (Cypress.config('experimentalSessionAndOrigin')) {
|
|
91
|
+
// https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
|
|
92
|
+
cy.session(sessionKey, authCallback, {
|
|
93
|
+
cacheAcrossSpecs: typeof commandOptions.disableCacheAcrossSpecs === 'boolean' ? !commandOptions.disableCacheAcrossSpecs : true
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
cy.log("We recommend turning on the flag \"experimentalSessionAndOrigin\" to be able to use \"cy.session\" and thus reduce the time to log in between tests.");
|
|
97
|
+
authCallback();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (commandOptions.initialRoute) {
|
|
101
|
+
var _context2;
|
|
102
|
+
|
|
103
|
+
cy.visit(_concatInstanceProperty__default["default"](_context2 = "".concat(Cypress.config('baseUrl'))).call(_context2, commandOptions.initialRoute));
|
|
104
|
+
cy.url().should('include', commandOptions.initialRoute);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function loginByOidc(commandOptions) {
|
|
110
|
+
if (!isLocalhost()) {
|
|
111
|
+
throw new Error("The \"loginByOidc\" command only works when testing a Custom Application running on localhost.");
|
|
112
|
+
}
|
|
113
|
+
|
|
42
114
|
var sessionNonce = uuid.v4();
|
|
115
|
+
var projectKey = undefined;
|
|
116
|
+
|
|
117
|
+
if (commandOptions.entryPointUriPath !== 'account') {
|
|
118
|
+
var _commandOptions$proje2;
|
|
119
|
+
|
|
120
|
+
projectKey = (_commandOptions$proje2 = commandOptions.projectKey) !== null && _commandOptions$proje2 !== void 0 ? _commandOptions$proje2 : Cypress.env('PROJECT_KEY');
|
|
121
|
+
}
|
|
122
|
+
|
|
43
123
|
cy.task('customApplicationConfig', {
|
|
44
124
|
entryPointUriPath: commandOptions.entryPointUriPath,
|
|
45
125
|
dotfiles: commandOptions.dotfiles
|
|
@@ -47,7 +127,7 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
47
127
|
{
|
|
48
128
|
log: false
|
|
49
129
|
}).then(function (appConfig) {
|
|
50
|
-
var _appConfig$__DEVELOPM, _appConfig$__DEVELOPM2, _appConfig$__DEVELOPM3, _appConfig$__DEVELOPM4, _commandOptions$
|
|
130
|
+
var _appConfig$__DEVELOPM, _appConfig$__DEVELOPM2, _appConfig$__DEVELOPM3, _appConfig$__DEVELOPM4, _commandOptions$login2;
|
|
51
131
|
|
|
52
132
|
// Log loaded application config for debugging purposes.
|
|
53
133
|
Cypress.log({
|
|
@@ -61,8 +141,8 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
61
141
|
oAuthScopes: (_appConfig$__DEVELOPM = appConfig.__DEVELOPMENT__) === null || _appConfig$__DEVELOPM === void 0 ? void 0 : (_appConfig$__DEVELOPM2 = _appConfig$__DEVELOPM.oidc) === null || _appConfig$__DEVELOPM2 === void 0 ? void 0 : _appConfig$__DEVELOPM2.oAuthScopes,
|
|
62
142
|
teamId: (_appConfig$__DEVELOPM3 = appConfig.__DEVELOPMENT__) === null || _appConfig$__DEVELOPM3 === void 0 ? void 0 : (_appConfig$__DEVELOPM4 = _appConfig$__DEVELOPM3.oidc) === null || _appConfig$__DEVELOPM4 === void 0 ? void 0 : _appConfig$__DEVELOPM4.teamId
|
|
63
143
|
});
|
|
64
|
-
var userCredentials = (_commandOptions$
|
|
65
|
-
email:
|
|
144
|
+
var userCredentials = (_commandOptions$login2 = commandOptions.login) !== null && _commandOptions$login2 !== void 0 ? _commandOptions$login2 : {
|
|
145
|
+
email: Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER'),
|
|
66
146
|
password: Cypress.env('LOGIN_PASSWORD')
|
|
67
147
|
}; // Perform the login using the API, then store some required values into the browser storage
|
|
68
148
|
// and redirect to the auth callback route.
|
|
@@ -80,29 +160,83 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
80
160
|
followRedirect: false
|
|
81
161
|
};
|
|
82
162
|
cy.request(requestOptions).then(function (res) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
win
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
163
|
+
var sessionKey = ['loginByOidc', userCredentials.email, commandOptions.entryPointUriPath];
|
|
164
|
+
|
|
165
|
+
function authCallback() {
|
|
166
|
+
cy.visit(res.body.redirectTo, {
|
|
167
|
+
onBeforeLoad: function onBeforeLoad(win) {
|
|
168
|
+
var _context3;
|
|
169
|
+
|
|
170
|
+
if (projectKey) {
|
|
171
|
+
win.localStorage.setItem(constants.STORAGE_KEYS.ACTIVE_PROJECT_KEY, projectKey);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
win.sessionStorage.setItem(_concatInstanceProperty__default["default"](_context3 = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context3, sessionNonce), _JSON$stringify__default["default"]({
|
|
175
|
+
applicationId: applicationId,
|
|
176
|
+
query: {}
|
|
177
|
+
}));
|
|
178
|
+
win.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_SCOPE, sessionScope);
|
|
179
|
+
|
|
180
|
+
if (commandOptions.onBeforeLoad) {
|
|
181
|
+
commandOptions.onBeforeLoad(win);
|
|
182
|
+
}
|
|
96
183
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
184
|
+
}); // Wait for the application to be loaded so that the session can be saved.
|
|
185
|
+
|
|
186
|
+
cy.get('#app-loader').should('not.exist');
|
|
187
|
+
} // For backwards compatibility.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if (Cypress.config('experimentalSessionAndOrigin')) {
|
|
191
|
+
// https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
|
|
192
|
+
cy.session(sessionKey, authCallback, {
|
|
193
|
+
cacheAcrossSpecs: typeof commandOptions.disableCacheAcrossSpecs === 'boolean' ? !commandOptions.disableCacheAcrossSpecs : true
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
cy.log("We recommend turning on the flag \"experimentalSessionAndOrigin\" to be able to use \"cy.session\" and thus reduce the time to log in between tests.");
|
|
197
|
+
authCallback();
|
|
198
|
+
}
|
|
99
199
|
|
|
100
200
|
if (commandOptions.initialRoute) {
|
|
101
|
-
var
|
|
201
|
+
var _context4;
|
|
102
202
|
|
|
103
|
-
cy.visit(_concatInstanceProperty__default["default"](
|
|
203
|
+
cy.visit(_concatInstanceProperty__default["default"](_context4 = "".concat(Cypress.config('baseUrl'))).call(_context4, commandOptions.initialRoute));
|
|
104
204
|
cy.url().should('include', commandOptions.initialRoute);
|
|
105
205
|
}
|
|
106
206
|
});
|
|
107
207
|
});
|
|
208
|
+
}
|
|
209
|
+
/* Utilities */
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
function fillLoginForm(userCredentials) {
|
|
213
|
+
cy.get('input[name=email]').type(userCredentials.email);
|
|
214
|
+
cy.get('input[name=password]').type(userCredentials.password, {
|
|
215
|
+
log: false
|
|
216
|
+
});
|
|
217
|
+
cy.get('button').contains('Sign in').click();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function isLocalhost() {
|
|
221
|
+
var baseUrl = new _URL__default["default"](Cypress.config('baseUrl'));
|
|
222
|
+
return baseUrl.hostname === 'localhost';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
Cypress.Commands.add('loginToMerchantCenter', function (commandOptions) {
|
|
226
|
+
Cypress.log({
|
|
227
|
+
name: 'loginToMerchantCenter'
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
if (isLocalhost()) {
|
|
231
|
+
loginByOidc(commandOptions);
|
|
232
|
+
} else {
|
|
233
|
+
loginByForm(commandOptions);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
237
|
+
Cypress.log({
|
|
238
|
+
name: 'loginByOidc'
|
|
239
|
+
});
|
|
240
|
+
cy.log('We recommend not to use the command "cy.loginByOidc" directly. Instead, use the more generic "cy.loginToMerchantCenter" command as it automatically detects which login mechanism to use.');
|
|
241
|
+
loginByOidc(commandOptions);
|
|
108
242
|
});
|
|
@@ -9,22 +9,101 @@ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object
|
|
|
9
9
|
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
10
10
|
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
11
11
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
12
|
+
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
12
13
|
import { v4 } from 'uuid';
|
|
13
|
-
import { S as STORAGE_KEYS, O as OIDC_RESPONSE_TYPES } from '../../dist/constants-0e882d21.esm.js';
|
|
14
14
|
import { buildOidcScope } from '@commercetools-frontend/application-shell/ssr';
|
|
15
|
+
import { O as OIDC_RESPONSE_TYPES, S as STORAGE_KEYS } from '../../dist/constants-0e882d21.esm.js';
|
|
15
16
|
|
|
16
17
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
18
|
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
function loginByForm(commandOptions) {
|
|
21
22
|
var _commandOptions$proje;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
24
|
+
if (isLocalhost()) {
|
|
25
|
+
throw new Error("At the moment, the \"loginByForm\" command only works when testing a Merchant Center production URL. Using form login in an application running on localhost is not supported due to issues with \"cy.origin\".");
|
|
26
|
+
}
|
|
27
|
+
|
|
26
28
|
var projectKey = (_commandOptions$proje = commandOptions.projectKey) !== null && _commandOptions$proje !== void 0 ? _commandOptions$proje : Cypress.env('PROJECT_KEY');
|
|
29
|
+
cy.task('customApplicationConfig', {
|
|
30
|
+
entryPointUriPath: commandOptions.entryPointUriPath,
|
|
31
|
+
dotfiles: commandOptions.dotfiles
|
|
32
|
+
}, // Do not show log, as it may contain sensible information.
|
|
33
|
+
{
|
|
34
|
+
log: false
|
|
35
|
+
}).then(function (appConfig) {
|
|
36
|
+
var _context, _commandOptions$login;
|
|
37
|
+
|
|
38
|
+
var url = _concatInstanceProperty(_context = "/".concat(projectKey, "/")).call(_context, commandOptions.entryPointUriPath);
|
|
39
|
+
|
|
40
|
+
if (commandOptions.entryPointUriPath === 'account') {
|
|
41
|
+
url = "/".concat(commandOptions.entryPointUriPath);
|
|
42
|
+
} // Log loaded application config for debugging purposes.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Cypress.log({
|
|
46
|
+
displayName: 'task',
|
|
47
|
+
name: 'customApplicationConfig',
|
|
48
|
+
message: appConfig
|
|
49
|
+
});
|
|
50
|
+
var userCredentials = (_commandOptions$login = commandOptions.login) !== null && _commandOptions$login !== void 0 ? _commandOptions$login : {
|
|
51
|
+
email: Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER'),
|
|
52
|
+
password: Cypress.env('LOGIN_PASSWORD')
|
|
53
|
+
};
|
|
54
|
+
var sessionKey = ['loginByForm', userCredentials.email, commandOptions.entryPointUriPath]; // const mcUrl = new URL(appConfig.mcApiUrl);
|
|
55
|
+
// const mcFrontendHostname = mcUrl.hostname.replace('mc-api', 'mc');
|
|
56
|
+
|
|
57
|
+
function authCallback() {
|
|
58
|
+
cy.visit(url); // NOTE: using `cy.origin` is currently disabled as it does not seem to properly work.
|
|
59
|
+
// Interestingly, starting an application locally using Vite works, however not when using Webpack.
|
|
60
|
+
// For now we keep it disabled until we find a solution.
|
|
61
|
+
// // https://cypress.io/blog/2022/04/25/cypress-9-6-0-easily-test-multi-domain-workflows-with-cy-origin/
|
|
62
|
+
// cy.origin(
|
|
63
|
+
// mcFrontendHostname,
|
|
64
|
+
// { args: userCredentials },
|
|
65
|
+
// fillLoginForm
|
|
66
|
+
// );
|
|
67
|
+
|
|
68
|
+
fillLoginForm(userCredentials); // Wait for the route to be loaded so that the session can be saved.
|
|
69
|
+
|
|
70
|
+
cy.url().should('include', url);
|
|
71
|
+
} // For backwards compatibility.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
if (Cypress.config('experimentalSessionAndOrigin')) {
|
|
75
|
+
// https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
|
|
76
|
+
cy.session(sessionKey, authCallback, {
|
|
77
|
+
cacheAcrossSpecs: typeof commandOptions.disableCacheAcrossSpecs === 'boolean' ? !commandOptions.disableCacheAcrossSpecs : true
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
cy.log("We recommend turning on the flag \"experimentalSessionAndOrigin\" to be able to use \"cy.session\" and thus reduce the time to log in between tests.");
|
|
81
|
+
authCallback();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (commandOptions.initialRoute) {
|
|
85
|
+
var _context2;
|
|
86
|
+
|
|
87
|
+
cy.visit(_concatInstanceProperty(_context2 = "".concat(Cypress.config('baseUrl'))).call(_context2, commandOptions.initialRoute));
|
|
88
|
+
cy.url().should('include', commandOptions.initialRoute);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function loginByOidc(commandOptions) {
|
|
94
|
+
if (!isLocalhost()) {
|
|
95
|
+
throw new Error("The \"loginByOidc\" command only works when testing a Custom Application running on localhost.");
|
|
96
|
+
}
|
|
97
|
+
|
|
27
98
|
var sessionNonce = v4();
|
|
99
|
+
var projectKey = undefined;
|
|
100
|
+
|
|
101
|
+
if (commandOptions.entryPointUriPath !== 'account') {
|
|
102
|
+
var _commandOptions$proje2;
|
|
103
|
+
|
|
104
|
+
projectKey = (_commandOptions$proje2 = commandOptions.projectKey) !== null && _commandOptions$proje2 !== void 0 ? _commandOptions$proje2 : Cypress.env('PROJECT_KEY');
|
|
105
|
+
}
|
|
106
|
+
|
|
28
107
|
cy.task('customApplicationConfig', {
|
|
29
108
|
entryPointUriPath: commandOptions.entryPointUriPath,
|
|
30
109
|
dotfiles: commandOptions.dotfiles
|
|
@@ -32,7 +111,7 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
32
111
|
{
|
|
33
112
|
log: false
|
|
34
113
|
}).then(function (appConfig) {
|
|
35
|
-
var _appConfig$__DEVELOPM, _appConfig$__DEVELOPM2, _appConfig$__DEVELOPM3, _appConfig$__DEVELOPM4, _commandOptions$
|
|
114
|
+
var _appConfig$__DEVELOPM, _appConfig$__DEVELOPM2, _appConfig$__DEVELOPM3, _appConfig$__DEVELOPM4, _commandOptions$login2;
|
|
36
115
|
|
|
37
116
|
// Log loaded application config for debugging purposes.
|
|
38
117
|
Cypress.log({
|
|
@@ -46,8 +125,8 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
46
125
|
oAuthScopes: (_appConfig$__DEVELOPM = appConfig.__DEVELOPMENT__) === null || _appConfig$__DEVELOPM === void 0 ? void 0 : (_appConfig$__DEVELOPM2 = _appConfig$__DEVELOPM.oidc) === null || _appConfig$__DEVELOPM2 === void 0 ? void 0 : _appConfig$__DEVELOPM2.oAuthScopes,
|
|
47
126
|
teamId: (_appConfig$__DEVELOPM3 = appConfig.__DEVELOPMENT__) === null || _appConfig$__DEVELOPM3 === void 0 ? void 0 : (_appConfig$__DEVELOPM4 = _appConfig$__DEVELOPM3.oidc) === null || _appConfig$__DEVELOPM4 === void 0 ? void 0 : _appConfig$__DEVELOPM4.teamId
|
|
48
127
|
});
|
|
49
|
-
var userCredentials = (_commandOptions$
|
|
50
|
-
email:
|
|
128
|
+
var userCredentials = (_commandOptions$login2 = commandOptions.login) !== null && _commandOptions$login2 !== void 0 ? _commandOptions$login2 : {
|
|
129
|
+
email: Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER'),
|
|
51
130
|
password: Cypress.env('LOGIN_PASSWORD')
|
|
52
131
|
}; // Perform the login using the API, then store some required values into the browser storage
|
|
53
132
|
// and redirect to the auth callback route.
|
|
@@ -65,29 +144,83 @@ Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
|
65
144
|
followRedirect: false
|
|
66
145
|
};
|
|
67
146
|
cy.request(requestOptions).then(function (res) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
win
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
var sessionKey = ['loginByOidc', userCredentials.email, commandOptions.entryPointUriPath];
|
|
148
|
+
|
|
149
|
+
function authCallback() {
|
|
150
|
+
cy.visit(res.body.redirectTo, {
|
|
151
|
+
onBeforeLoad: function onBeforeLoad(win) {
|
|
152
|
+
var _context3;
|
|
153
|
+
|
|
154
|
+
if (projectKey) {
|
|
155
|
+
win.localStorage.setItem(STORAGE_KEYS.ACTIVE_PROJECT_KEY, projectKey);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
win.sessionStorage.setItem(_concatInstanceProperty(_context3 = "".concat(STORAGE_KEYS.NONCE, "_")).call(_context3, sessionNonce), _JSON$stringify({
|
|
159
|
+
applicationId: applicationId,
|
|
160
|
+
query: {}
|
|
161
|
+
}));
|
|
162
|
+
win.sessionStorage.setItem(STORAGE_KEYS.SESSION_SCOPE, sessionScope);
|
|
163
|
+
|
|
164
|
+
if (commandOptions.onBeforeLoad) {
|
|
165
|
+
commandOptions.onBeforeLoad(win);
|
|
166
|
+
}
|
|
81
167
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
168
|
+
}); // Wait for the application to be loaded so that the session can be saved.
|
|
169
|
+
|
|
170
|
+
cy.get('#app-loader').should('not.exist');
|
|
171
|
+
} // For backwards compatibility.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if (Cypress.config('experimentalSessionAndOrigin')) {
|
|
175
|
+
// https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/
|
|
176
|
+
cy.session(sessionKey, authCallback, {
|
|
177
|
+
cacheAcrossSpecs: typeof commandOptions.disableCacheAcrossSpecs === 'boolean' ? !commandOptions.disableCacheAcrossSpecs : true
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
cy.log("We recommend turning on the flag \"experimentalSessionAndOrigin\" to be able to use \"cy.session\" and thus reduce the time to log in between tests.");
|
|
181
|
+
authCallback();
|
|
182
|
+
}
|
|
84
183
|
|
|
85
184
|
if (commandOptions.initialRoute) {
|
|
86
|
-
var
|
|
185
|
+
var _context4;
|
|
87
186
|
|
|
88
|
-
cy.visit(_concatInstanceProperty(
|
|
187
|
+
cy.visit(_concatInstanceProperty(_context4 = "".concat(Cypress.config('baseUrl'))).call(_context4, commandOptions.initialRoute));
|
|
89
188
|
cy.url().should('include', commandOptions.initialRoute);
|
|
90
189
|
}
|
|
91
190
|
});
|
|
92
191
|
});
|
|
192
|
+
}
|
|
193
|
+
/* Utilities */
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
function fillLoginForm(userCredentials) {
|
|
197
|
+
cy.get('input[name=email]').type(userCredentials.email);
|
|
198
|
+
cy.get('input[name=password]').type(userCredentials.password, {
|
|
199
|
+
log: false
|
|
200
|
+
});
|
|
201
|
+
cy.get('button').contains('Sign in').click();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function isLocalhost() {
|
|
205
|
+
var baseUrl = new _URL(Cypress.config('baseUrl'));
|
|
206
|
+
return baseUrl.hostname === 'localhost';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
Cypress.Commands.add('loginToMerchantCenter', function (commandOptions) {
|
|
210
|
+
Cypress.log({
|
|
211
|
+
name: 'loginToMerchantCenter'
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (isLocalhost()) {
|
|
215
|
+
loginByOidc(commandOptions);
|
|
216
|
+
} else {
|
|
217
|
+
loginByForm(commandOptions);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
Cypress.Commands.add('loginByOidc', function (commandOptions) {
|
|
221
|
+
Cypress.log({
|
|
222
|
+
name: 'loginByOidc'
|
|
223
|
+
});
|
|
224
|
+
cy.log('We recommend not to use the command "cy.loginByOidc" directly. Instead, use the more generic "cy.loginToMerchantCenter" command as it automatically detects which login mechanism to use.');
|
|
225
|
+
loginByOidc(commandOptions);
|
|
93
226
|
});
|
package/add-commands/index.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
declare namespace Cypress {
|
|
2
2
|
interface Chainable<Subject> {
|
|
3
|
+
/**
|
|
4
|
+
* Log into the Custom Application.
|
|
5
|
+
* The command detects whether the application is running on localhost or on production
|
|
6
|
+
* and chooses the appropriate login mechanism.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* cy.loginToMerchantCenter({ entryPointUriPath: 'template-starter' })
|
|
10
|
+
*/
|
|
11
|
+
loginToMerchantCenter(
|
|
12
|
+
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
|
|
13
|
+
options?: import('./dist/commercetools-frontend-cypress-add-commands.cjs').CommandLoginOptions
|
|
14
|
+
): Chainable<Subject>;
|
|
3
15
|
/**
|
|
4
16
|
* Log into the Custom Application using the OIDC workflow.
|
|
17
|
+
* The command only works for testing an application running on localhost.
|
|
18
|
+
*
|
|
5
19
|
* @example
|
|
6
20
|
* cy.loginByOidc({ entryPointUriPath: 'template-starter' })
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use the more generic {@link cy.loginToMerchantCenter} command as it automatically detects which login mechanism to use.
|
|
7
23
|
*/
|
|
8
24
|
loginByOidc(
|
|
9
25
|
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
|
|
10
|
-
options?: import('./dist/commercetools-frontend-cypress-add-commands.cjs').
|
|
26
|
+
options?: import('./dist/commercetools-frontend-cypress-add-commands.cjs').CommandLoginOptions
|
|
11
27
|
): Chainable<Subject>;
|
|
12
28
|
}
|
|
13
29
|
}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var constants = require('./constants-42a0ebf5.cjs.dev.js');
|
|
6
6
|
|
|
7
7
|
// NOTE: This string will be replaced on build time with the package version.
|
|
8
|
-
var version = "21.
|
|
8
|
+
var version = "21.16.0";
|
|
9
9
|
|
|
10
10
|
exports.OIDC_RESPONSE_TYPES = constants.OIDC_RESPONSE_TYPES;
|
|
11
11
|
exports.STORAGE_KEYS = constants.STORAGE_KEYS;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var constants = require('./constants-4d9d4b7b.cjs.prod.js');
|
|
6
6
|
|
|
7
7
|
// NOTE: This string will be replaced on build time with the package version.
|
|
8
|
-
var version = "21.
|
|
8
|
+
var version = "21.16.0";
|
|
9
9
|
|
|
10
10
|
exports.OIDC_RESPONSE_TYPES = constants.OIDC_RESPONSE_TYPES;
|
|
11
11
|
exports.STORAGE_KEYS = constants.STORAGE_KEYS;
|
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The application entry point URI path. This value is used to identify
|
|
4
|
-
* the correct application config.
|
|
5
|
-
*/
|
|
6
|
-
entryPointUriPath: string;
|
|
7
|
-
/**
|
|
8
|
-
* Pass a list of dotfiles that must be loaded when the custom-application-config.json
|
|
9
|
-
* is loaded (in case you are using environment placeholder).
|
|
10
|
-
* By default the following dotfiles are loaded: `.env` and `.env.local`.
|
|
11
|
-
* You can also define the values using paths relative to the application folder.
|
|
12
|
-
*/
|
|
13
|
-
dotfiles?: string[];
|
|
14
|
-
/**
|
|
15
|
-
* Called before your page has loaded all of its resources.
|
|
16
|
-
* Use this as a chance to interact for example with the browser storage.
|
|
17
|
-
*/
|
|
18
|
-
onBeforeLoad?: (win: Window) => void;
|
|
19
|
-
/**
|
|
20
|
-
* If defined, visit this route after login.
|
|
21
|
-
*/
|
|
22
|
-
initialRoute?: string;
|
|
23
|
-
/**
|
|
24
|
-
* The project key to access in the user session. The session token is valid for one project key at a time.
|
|
25
|
-
* Defaults to `Cypress.env('PROJECT_KEY')`.
|
|
26
|
-
*/
|
|
27
|
-
projectKey?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The user login credentials.
|
|
30
|
-
*/
|
|
31
|
-
login?: {
|
|
32
|
-
/**
|
|
33
|
-
* The user email.
|
|
34
|
-
* Defaults to `Cypress.env('LOGIN_EMAIL') ?? Cypress.env('LOGIN_USER')`.
|
|
35
|
-
*/
|
|
36
|
-
email: string;
|
|
37
|
-
/**
|
|
38
|
-
* The user password.
|
|
39
|
-
* Defaults to `Cypress.env('LOGIN_PASSWORD')`.
|
|
40
|
-
*/
|
|
41
|
-
password: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
1
|
+
import { type CommandLoginOptions as TCommandLoginOptions } from './login';
|
|
2
|
+
export declare type CommandLoginOptions = TCommandLoginOptions;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare type LoginCredentials = {
|
|
2
|
+
/**
|
|
3
|
+
* The user email.
|
|
4
|
+
* Defaults to `Cypress.env('LOGIN_EMAIL') || Cypress.env('LOGIN_USER')`.
|
|
5
|
+
*/
|
|
6
|
+
email: string;
|
|
7
|
+
/**
|
|
8
|
+
* The user password.
|
|
9
|
+
* Defaults to `Cypress.env('LOGIN_PASSWORD')`.
|
|
10
|
+
*/
|
|
11
|
+
password: string;
|
|
12
|
+
};
|
|
13
|
+
export declare type CommandLoginOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* The application entry point URI path. This value is used to identify
|
|
16
|
+
* the correct application config.
|
|
17
|
+
*/
|
|
18
|
+
entryPointUriPath: string;
|
|
19
|
+
/**
|
|
20
|
+
* Pass a list of dotfiles that must be loaded when the custom-application-config.json
|
|
21
|
+
* is loaded (in case you are using environment placeholder).
|
|
22
|
+
* By default the following dotfiles are loaded: `.env` and `.env.local`.
|
|
23
|
+
* You can also define the values using paths relative to the application folder.
|
|
24
|
+
*/
|
|
25
|
+
dotfiles?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Called before your page has loaded all of its resources.
|
|
28
|
+
* Use this as a chance to interact for example with the browser storage.
|
|
29
|
+
*/
|
|
30
|
+
onBeforeLoad?: (win: Window) => void;
|
|
31
|
+
/**
|
|
32
|
+
* If defined, visit this route after login.
|
|
33
|
+
*/
|
|
34
|
+
initialRoute?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The project key to access in the user session. The session token is valid for one project key at a time.
|
|
37
|
+
* Defaults to `Cypress.env('PROJECT_KEY')`.
|
|
38
|
+
*/
|
|
39
|
+
projectKey?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The user login credentials.
|
|
42
|
+
*/
|
|
43
|
+
login?: LoginCredentials;
|
|
44
|
+
/**
|
|
45
|
+
* Turn off caching the session across specs.
|
|
46
|
+
*/
|
|
47
|
+
disableCacheAcrossSpecs?: boolean;
|
|
48
|
+
};
|
|
49
|
+
export declare type CommandLoginByOidcOptions = CommandLoginOptions;
|
|
50
|
+
declare function loginByForm(commandOptions: CommandLoginOptions): void;
|
|
51
|
+
declare function loginByOidc(commandOptions: CommandLoginOptions): void;
|
|
52
|
+
declare function isLocalhost(): boolean;
|
|
53
|
+
export { loginByForm, loginByOidc, isLocalhost };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/cypress",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.16.0",
|
|
4
4
|
"description": "Cypress commands and utilities for Custom Applications",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@babel/runtime": "^7.19.0",
|
|
39
39
|
"@babel/runtime-corejs3": "^7.19.0",
|
|
40
|
-
"@commercetools-frontend/application-config": "21.
|
|
41
|
-
"@commercetools-frontend/application-shell": "21.
|
|
40
|
+
"@commercetools-frontend/application-config": "21.16.0",
|
|
41
|
+
"@commercetools-frontend/application-shell": "21.16.0",
|
|
42
42
|
"@manypkg/get-packages": "1.1.3",
|
|
43
43
|
"uuid": "8.3.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"cypress": "10.
|
|
46
|
+
"cypress": "10.9.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"cypress": "8.x || 9.x || 10.x"
|