@bigbinary/neeto-playwright-commons 1.4.6 → 1.5.1

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/index.cjs.js CHANGED
@@ -4,6 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var test = require('@playwright/test');
6
6
  var require$$0 = require('fs');
7
+ var faker = require('@faker-js/faker');
8
+ var ramda = require('ramda');
9
+ var MailosaurClient = require('mailosaur');
7
10
  var dayjs = require('dayjs');
8
11
  var playwrightI18nextFixture = require('playwright-i18next-fixture');
9
12
  var require$$2 = require('os');
@@ -11,7 +14,6 @@ var require$$0$1 = require('path');
11
14
  var require$$0$2 = require('util');
12
15
  var require$$0$3 = require('stream');
13
16
  var require$$0$4 = require('events');
14
- var ramda = require('ramda');
15
17
  var require$$3 = require('crypto');
16
18
 
17
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -34,8 +36,10 @@ function _interopNamespace(e) {
34
36
  return Object.freeze(n);
35
37
  }
36
38
 
39
+ var test__default = /*#__PURE__*/_interopDefaultLegacy(test);
37
40
  var require$$0__namespace = /*#__PURE__*/_interopNamespace(require$$0);
38
41
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0);
42
+ var MailosaurClient__default = /*#__PURE__*/_interopDefaultLegacy(MailosaurClient);
39
43
  var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
40
44
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
41
45
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
@@ -58,7 +62,9 @@ const CREDENTIALS = {
58
62
  email: "oliver@example.com",
59
63
  password: "welcome",
60
64
  };
65
+ const OTP_EMAIL_PATTERN = "is your login code";
61
66
 
67
+ /* eslint-disable playwright/no-skipped-test */
62
68
  const joinString = (string1, string2, string3 = "", separator = " ") => {
63
69
  if (string3 === "") {
64
70
  return string1 + separator + string2;
@@ -108,6 +114,11 @@ const hyphenize = input => {
108
114
  return fallbackString;
109
115
  };
110
116
  const joinHyphenCase = (...args) => args.join(" ").replace(/\s+/g, "-").toLowerCase();
117
+ const skipTest = {
118
+ forDevelopmentEnv: () => test__default["default"].skip(process.env.TEST_ENV === ENVIRONMENT.development),
119
+ forReviewEnv: () => test__default["default"].skip(process.env.TEST_ENV === ENVIRONMENT.review),
120
+ forAllExceptStagingEnv: () => test__default["default"].skip(process.env.TEST_ENV !== ENVIRONMENT.staging),
121
+ };
111
122
 
112
123
  const COMMON_SELECTORS = {
113
124
  spinner: ".neeto-ui-spinner",
@@ -190,7 +201,7 @@ class CustomCommands {
190
201
  const startTime = Date.now();
191
202
  await this.recursiveMethod(callback, condition, timeout, startTime);
192
203
  };
193
- this.verifySuccessToast = async ({ message, closeAfterVerification = true, }) => {
204
+ this.verifySuccessToast = async ({ message = null, closeAfterVerification = true, }) => {
194
205
  if (message) {
195
206
  await test.expect(this.page.getByTestId(COMMON_SELECTORS.toastMessage)).toContainText(message);
196
207
  }
@@ -199,6 +210,7 @@ class CustomCommands {
199
210
  }
200
211
  closeAfterVerification &&
201
212
  (await this.page.getByTestId(COMMON_SELECTORS.toastCloseButton).click());
213
+ await test.expect(this.page.locator(COMMON_SELECTORS.toastIcon)).toBeHidden();
202
214
  };
203
215
  this.reloadAndWait = async (requestCount) => {
204
216
  const reloadRequests = this.interceptMultipleResponses({
@@ -241,16 +253,53 @@ class CustomCommands {
241
253
  }
242
254
  }
243
255
 
256
+ class MailosaurUtils {
257
+ constructor(mailosaur) {
258
+ this.fetchOtpFromEmail = async ({ email, subjectSubstring = OTP_EMAIL_PATTERN, timeout = 2 * 60 * 1000, receivedAfter = new Date(), }) => {
259
+ var _a, _b, _c;
260
+ const receivedEmail = await this.mailosaur.messages.get(this.serverId, { sentTo: email, subject: subjectSubstring }, { timeout, receivedAfter });
261
+ const otp = (_c = (_b = (_a = receivedEmail === null || receivedEmail === void 0 ? void 0 : receivedEmail.text) === null || _a === void 0 ? void 0 : _a.codes) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.value;
262
+ if (ramda.isNil(otp)) {
263
+ throw new Error(`No codes found in the email with subject: ${receivedEmail.subject}. Please re-evaluate the filtering parameters.`);
264
+ }
265
+ return otp;
266
+ };
267
+ this.generateRandomMailosaurEmail = () => faker.faker.internet.email({ provider: `${this.serverId}.mailosaur.net` });
268
+ this.mailosaur = mailosaur;
269
+ if (ramda.isNotNil(process.env.MAILOSAUR_SERVER_ID)) {
270
+ this.serverId = process.env.MAILOSAUR_SERVER_ID;
271
+ }
272
+ else {
273
+ throw new Error("ENV variable MAILOSAUR_SERVER_ID is not defined. Please add the Server ID to use this method. Please visit https://mailosaur.com/app/servers to find the Server ID.");
274
+ }
275
+ }
276
+ }
277
+
244
278
  const commands = {
245
279
  neetoPlaywrightUtilities: async ({ page, request }, use) => {
246
280
  const commands = new CustomCommands(page, request);
247
281
  await use(commands);
248
282
  },
283
+ mailosaur: async ({}, use) => {
284
+ skipTest.forAllExceptStagingEnv();
285
+ if (ramda.isNotNil(process.env.MAILOSAUR_API_KEY)) {
286
+ const mailosaur = new MailosaurClient__default["default"](process.env.MAILOSAUR_API_KEY);
287
+ await use(mailosaur);
288
+ }
289
+ else {
290
+ throw new Error("ENV variable MAILOSAUR_API_KEY is not defined. Please add the API key to use this fixture. Please visit https://mailosaur.com/app/account/keys to find the API key.");
291
+ }
292
+ },
249
293
  page: async ({ page }, use) => {
250
294
  await page.goto("/");
251
295
  await page.waitForLoadState();
252
296
  await use(page);
253
297
  },
298
+ mailosaurUtils: async ({ mailosaur }, use) => {
299
+ skipTest.forAllExceptStagingEnv();
300
+ const mailosaurUtils = new MailosaurUtils(mailosaur);
301
+ await use(mailosaurUtils);
302
+ },
254
303
  };
255
304
 
256
305
  const generateStagingData = (product = "invoice") => {
@@ -1460,7 +1509,7 @@ const append = (queue = '', stash = '', enclose = false) => {
1460
1509
  return utils$g.flatten(result);
1461
1510
  };
1462
1511
 
1463
- const expand$1 = (ast, options = {}) => {
1512
+ const expand$2 = (ast, options = {}) => {
1464
1513
  let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
1465
1514
 
1466
1515
  let walk = (node, parent = {}) => {
@@ -1540,7 +1589,7 @@ const expand$1 = (ast, options = {}) => {
1540
1589
  return utils$g.flatten(walk(ast));
1541
1590
  };
1542
1591
 
1543
- var expand_1 = expand$1;
1592
+ var expand_1 = expand$2;
1544
1593
 
1545
1594
  var constants$4 = {
1546
1595
  MAX_LENGTH: 1024 * 64,
@@ -1929,7 +1978,7 @@ var parse_1$1 = parse$4;
1929
1978
 
1930
1979
  const stringify = stringify$4;
1931
1980
  const compile = compile_1;
1932
- const expand = expand_1;
1981
+ const expand$1 = expand_1;
1933
1982
  const parse$3 = parse_1$1;
1934
1983
 
1935
1984
  /**
@@ -2049,7 +2098,7 @@ braces$1.expand = (input, options = {}) => {
2049
2098
  input = braces$1.parse(input, options);
2050
2099
  }
2051
2100
 
2052
- let result = expand(input, options);
2101
+ let result = expand$1(input, options);
2053
2102
 
2054
2103
  // filter out empty strings if specified
2055
2104
  if (options.noempty === true) {
@@ -7440,12 +7489,12 @@ const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, loginPath = "/"
7440
7489
  const login = async ({ page, neetoPlaywrightUtilities, loginPath, }) => !IS_STAGING_ENV &&
7441
7490
  (await loginWithoutSSO({ page, neetoPlaywrightUtilities, loginPath }));
7442
7491
 
7443
- var main$1 = {exports: {}};
7492
+ var main$2 = {exports: {}};
7444
7493
 
7445
7494
  var name = "dotenv";
7446
7495
  var version$1 = "16.3.1";
7447
7496
  var description = "Loads environment variables from .env file";
7448
- var main = "lib/main.js";
7497
+ var main$1 = "lib/main.js";
7449
7498
  var types = "lib/main.d.ts";
7450
7499
  var exports$1 = {
7451
7500
  ".": {
@@ -7508,7 +7557,7 @@ var require$$4 = {
7508
7557
  name: name,
7509
7558
  version: version$1,
7510
7559
  description: description,
7511
- main: main,
7560
+ main: main$1,
7512
7561
  types: types,
7513
7562
  exports: exports$1,
7514
7563
  scripts: scripts,
@@ -7827,21 +7876,108 @@ const DotenvModule = {
7827
7876
  populate
7828
7877
  };
7829
7878
 
7830
- main$1.exports.configDotenv = DotenvModule.configDotenv;
7831
- main$1.exports._configVault = DotenvModule._configVault;
7832
- main$1.exports._parseVault = DotenvModule._parseVault;
7833
- main$1.exports.config = DotenvModule.config;
7834
- main$1.exports.decrypt = DotenvModule.decrypt;
7835
- main$1.exports.parse = DotenvModule.parse;
7836
- main$1.exports.populate = DotenvModule.populate;
7879
+ main$2.exports.configDotenv = DotenvModule.configDotenv;
7880
+ main$2.exports._configVault = DotenvModule._configVault;
7881
+ main$2.exports._parseVault = DotenvModule._parseVault;
7882
+ main$2.exports.config = DotenvModule.config;
7883
+ main$2.exports.decrypt = DotenvModule.decrypt;
7884
+ main$2.exports.parse = DotenvModule.parse;
7885
+ main$2.exports.populate = DotenvModule.populate;
7886
+
7887
+ main$2.exports = DotenvModule;
7888
+
7889
+ var main = {};
7890
+
7891
+ // like String.prototype.search but returns the last index
7892
+ function _searchLast (str, rgx) {
7893
+ const matches = Array.from(str.matchAll(rgx));
7894
+ return matches.length > 0 ? matches.slice(-1)[0].index : -1
7895
+ }
7896
+
7897
+ function _interpolate (envValue, environment, config) {
7898
+ // find the last unescaped dollar sign in the
7899
+ // value so that we can evaluate it
7900
+ const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
7837
7901
 
7838
- main$1.exports = DotenvModule;
7902
+ // If we couldn't match any unescaped dollar sign
7903
+ // let's return the string as is
7904
+ if (lastUnescapedDollarSignIndex === -1) return envValue
7905
+
7906
+ // This is the right-most group of variables in the string
7907
+ const rightMostGroup = envValue.slice(lastUnescapedDollarSignIndex);
7908
+
7909
+ /**
7910
+ * This finds the inner most variable/group divided
7911
+ * by variable name and default value (if present)
7912
+ * (
7913
+ * (?!(?<=\\))\$ // only match dollar signs that are not escaped
7914
+ * {? // optional opening curly brace
7915
+ * ([\w]+) // match the variable name
7916
+ * (?::-([^}\\]*))? // match an optional default value
7917
+ * }? // optional closing curly brace
7918
+ * )
7919
+ */
7920
+ const matchGroup = /((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;
7921
+ const match = rightMostGroup.match(matchGroup);
7922
+
7923
+ if (match != null) {
7924
+ const [, group, variableName, defaultValue] = match;
7925
+
7926
+ return _interpolate(
7927
+ envValue.replace(
7928
+ group,
7929
+ environment[variableName] ||
7930
+ defaultValue ||
7931
+ config.parsed[variableName] ||
7932
+ ''
7933
+ ),
7934
+ environment,
7935
+ config
7936
+ )
7937
+ }
7938
+
7939
+ return envValue
7940
+ }
7941
+
7942
+ function _resolveEscapeSequences (value) {
7943
+ return value.replace(/\\\$/g, '$')
7944
+ }
7945
+
7946
+ function expand (config) {
7947
+ // if ignoring process.env, use a blank object
7948
+ const environment = config.ignoreProcessEnv ? {} : process.env;
7949
+
7950
+ for (const configKey in config.parsed) {
7951
+ const value = Object.prototype.hasOwnProperty.call(environment, configKey)
7952
+ ? environment[configKey]
7953
+ : config.parsed[configKey];
7954
+
7955
+ config.parsed[configKey] = _resolveEscapeSequences(
7956
+ _interpolate(value, environment, config)
7957
+ );
7958
+ }
7959
+
7960
+ for (const processKey in config.parsed) {
7961
+ environment[processKey] = config.parsed[processKey];
7962
+ }
7963
+
7964
+ return config
7965
+ }
7966
+
7967
+ main.expand = expand;
7839
7968
 
7840
7969
  // @ts-check
7841
7970
  var _a, _b;
7842
- main$1.exports.config({
7971
+ const env = main$2.exports.config({
7843
7972
  path: `./e2e/config/.env.${(_a = process.env.TEST_ENV) !== null && _a !== void 0 ? _a : "development"}`,
7844
7973
  });
7974
+ main.expand(env);
7975
+ if (require$$0__namespace.existsSync("./e2e/config/.env.local")) {
7976
+ const localEnv = main$2.exports.config({
7977
+ path: "./e2e/config/.env.local",
7978
+ });
7979
+ main.expand(localEnv);
7980
+ }
7845
7981
  const currentsConfig = {
7846
7982
  ciBuildId: process.env.NEETO_CI_JOB_ID,
7847
7983
  recordKey: "PVHNwxEOySsdAeTc",
@@ -7855,7 +7991,7 @@ const definePlaywrightConfig = (overrides) => {
7855
7991
  fullyParallel: true,
7856
7992
  forbidOnly: isCI,
7857
7993
  retries: isCI ? 1 : 0,
7858
- timeout: 0,
7994
+ timeout: 5 * 60 * 1000,
7859
7995
  reporter: isCI
7860
7996
  ? [["@currents/playwright", { ...currentsConfig, ...currentsOverrides }]]
7861
7997
  : [["line"]],
@@ -7900,8 +8036,10 @@ exports.LOGIN_SELECTORS = LOGIN_SELECTORS;
7900
8036
  exports.MEMBER_FORM_SELECTORS = MEMBER_FORM_SELECTORS;
7901
8037
  exports.MEMBER_SELECTORS = MEMBER_SELECTORS;
7902
8038
  exports.MERGE_TAGS_SELECTORS = MERGE_TAGS_SELECTORS;
8039
+ exports.MailosaurUtils = MailosaurUtils;
7903
8040
  exports.NEETO_EDITOR_SELECTORS = NEETO_EDITOR_SELECTORS;
7904
8041
  exports.NEETO_FILTERS_SELECTORS = NEETO_FILTERS_SELECTORS;
8042
+ exports.OTP_EMAIL_PATTERN = OTP_EMAIL_PATTERN;
7905
8043
  exports.OrganizationPage = OrganizationPage;
7906
8044
  exports.PROJECT_TRANSLATIONS_PATH = PROJECT_TRANSLATIONS_PATH;
7907
8045
  exports.ROLES_SELECTORS = ROLES_SELECTORS;
@@ -7922,6 +8060,7 @@ exports.joinString = joinString;
7922
8060
  exports.login = login;
7923
8061
  exports.loginWithoutSSO = loginWithoutSSO;
7924
8062
  exports.readFileSyncIfExists = readFileSyncIfExists;
8063
+ exports.skipTest = skipTest;
7925
8064
  exports.updateCredentials = updateCredentials;
7926
8065
  exports.writeDataToFile = writeDataToFile;
7927
8066
  //# sourceMappingURL=index.cjs.js.map