@bigbinary/neeto-playwright-commons 1.1.1 → 1.1.3

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
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var test = require('@playwright/test');
6
- var fs$9 = require('fs');
6
+ var require$$0$3 = require('fs');
7
7
  var require$$2 = require('os');
8
8
  var require$$0 = require('path');
9
9
  var require$$0$1 = require('util');
10
10
  var require$$0$2 = require('stream');
11
- var require$$0$3 = require('events');
11
+ var require$$0$4 = require('events');
12
12
  var ramda = require('ramda');
13
13
  var dayjs = require('dayjs');
14
14
  var require$$3 = require('crypto');
@@ -33,17 +33,17 @@ function _interopNamespace(e) {
33
33
  return Object.freeze(n);
34
34
  }
35
35
 
36
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$9);
37
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs$9);
36
+ var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
37
+ var require$$0__namespace = /*#__PURE__*/_interopNamespace(require$$0$3);
38
38
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
39
39
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
40
40
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
41
41
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
42
- var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
42
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
43
43
  var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
44
44
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
45
45
 
46
- const COMMON_SELECTORS$1 = {
46
+ const COMMON_SELECTORS = {
47
47
  toastMessage: "toastr-message-container",
48
48
  toastIcon: ".Toastify__toast-icon",
49
49
  toastCloseButton: "toastr-close-button",
@@ -4938,7 +4938,7 @@ var fs$6 = {};
4938
4938
  (function (exports) {
4939
4939
  Object.defineProperty(exports, "__esModule", { value: true });
4940
4940
  exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
4941
- const fs = fs__default["default"];
4941
+ const fs = require$$0__default$3["default"];
4942
4942
  exports.FILE_SYSTEM_ADAPTER = {
4943
4943
  lstat: fs.lstat,
4944
4944
  stat: fs.stat,
@@ -5289,7 +5289,7 @@ var fs$2 = {};
5289
5289
  (function (exports) {
5290
5290
  Object.defineProperty(exports, "__esModule", { value: true });
5291
5291
  exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
5292
- const fs = fs__default["default"];
5292
+ const fs = require$$0__default$3["default"];
5293
5293
  exports.FILE_SYSTEM_ADAPTER = {
5294
5294
  lstat: fs.lstat,
5295
5295
  stat: fs.stat,
@@ -5726,7 +5726,7 @@ class Reader$1 {
5726
5726
  reader$1.default = Reader$1;
5727
5727
 
5728
5728
  Object.defineProperty(async$4, "__esModule", { value: true });
5729
- const events_1 = require$$0__default$3["default"];
5729
+ const events_1 = require$$0__default$4["default"];
5730
5730
  const fsScandir$2 = out$2;
5731
5731
  const fastq = queue.exports;
5732
5732
  const common$1 = common$3;
@@ -6596,7 +6596,7 @@ var settings = {};
6596
6596
  (function (exports) {
6597
6597
  Object.defineProperty(exports, "__esModule", { value: true });
6598
6598
  exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
6599
- const fs = fs__default["default"];
6599
+ const fs = require$$0__default$3["default"];
6600
6600
  const os = require$$2__default["default"];
6601
6601
  /**
6602
6602
  * The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
@@ -6754,17 +6754,61 @@ function assertPatternsInput(input) {
6754
6754
  }
6755
6755
  var out = FastGlob;
6756
6756
 
6757
- process.env.TEST_ENV === "staging";
6758
- const STORAGE_STATE$1 = "./e2e/auth/user.json";
6757
+ const ENVIRONMENT = {
6758
+ development: "development",
6759
+ staging: "staging",
6760
+ review: "review",
6761
+ };
6762
+ const IS_STAGING_ENV = process.env.TEST_ENV === "staging";
6763
+ const STORAGE_STATE = "./e2e/auth/user.json";
6764
+ const GLOBAL_TRANSLATIONS_PATTERN = "../node_modules/@bigbinary/**/translations/en.json";
6765
+ const PROJECT_TRANSLATIONS_PATH = "../app/javascript/src/translations/en.json";
6766
+ const CREDENTIALS = { email: "oliver@example.com", password: "welcome" };
6759
6767
 
6760
- const readFileSyncIfExists$1 = (path = STORAGE_STATE$1) => {
6768
+ const joinString = (string1, string2, string3 = "", separator = " ") => {
6769
+ if (string3 === "") {
6770
+ return string1 + separator + string2;
6771
+ }
6772
+ return string1 + separator + string2 + separator + string3;
6773
+ };
6774
+ const readFileSyncIfExists = (path = STORAGE_STATE) => {
6761
6775
  try {
6762
- return JSON.parse(fs__namespace.readFileSync(path, "utf8"));
6776
+ return JSON.parse(require$$0__namespace.readFileSync(path, "utf8"));
6763
6777
  }
6764
6778
  catch (error) {
6765
6779
  return {};
6766
6780
  }
6767
6781
  };
6782
+ const writeDataToFile = data => {
6783
+ try {
6784
+ require$$0__namespace.writeFileSync(STORAGE_STATE, data, "utf8");
6785
+ }
6786
+ catch (error) {
6787
+ console.log(error); // eslint-disable-line
6788
+ }
6789
+ return true;
6790
+ };
6791
+ const updateCredentials = ({ key, value }) => {
6792
+ const data = readFileSyncIfExists();
6793
+ data["user"][key] = value;
6794
+ return writeDataToFile(JSON.stringify(data));
6795
+ };
6796
+ const clearCredentials = () => {
6797
+ require$$0__namespace.unlink(STORAGE_STATE, error => {
6798
+ if (!error)
6799
+ return;
6800
+ console.log(error); // eslint-disable-line
6801
+ });
6802
+ };
6803
+ const readTranslations = () => {
6804
+ let translations = readFileSyncIfExists(PROJECT_TRANSLATIONS_PATH);
6805
+ const paths = out.sync(GLOBAL_TRANSLATIONS_PATTERN);
6806
+ paths.forEach(path => {
6807
+ const packageTranslation = readFileSyncIfExists(path);
6808
+ translations = ramda.mergeDeepLeft(translations, packageTranslation);
6809
+ });
6810
+ return translations;
6811
+ };
6768
6812
 
6769
6813
  class CustomCommands {
6770
6814
  constructor(page, request) {
@@ -6797,13 +6841,13 @@ class CustomCommands {
6797
6841
  };
6798
6842
  this.verifySuccessToast = async ({ message, closeAfterVerification = true, }) => {
6799
6843
  if (message) {
6800
- await test.expect(this.page.getByTestId(COMMON_SELECTORS$1.toastMessage)).toHaveValue(message);
6844
+ await test.expect(this.page.getByTestId(COMMON_SELECTORS.toastMessage)).toHaveValue(message);
6801
6845
  }
6802
6846
  else {
6803
- await test.expect(this.page.locator(COMMON_SELECTORS$1.toastIcon)).toHaveValue("👍");
6847
+ await test.expect(this.page.locator(COMMON_SELECTORS.toastIcon)).toHaveValue("👍");
6804
6848
  closeAfterVerification &&
6805
6849
  (await this.page
6806
- .getByTestId(COMMON_SELECTORS$1.toastCloseButton)
6850
+ .getByTestId(COMMON_SELECTORS.toastCloseButton)
6807
6851
  .click());
6808
6852
  }
6809
6853
  };
@@ -6815,19 +6859,20 @@ class CustomCommands {
6815
6859
  await reloadRequests;
6816
6860
  };
6817
6861
  this.apiRequest = async ({ url, headers: additionalHeaders, body: data, method = "get", params = {}, ...otherOptions }) => {
6818
- const { headers } = readFileSyncIfExists$1();
6862
+ const { headers } = readFileSyncIfExists();
6819
6863
  const requestOptions = {
6820
6864
  headers: { ...headers, ...additionalHeaders, "accept-encoding": "gzip" },
6821
6865
  data,
6822
6866
  params,
6823
6867
  ...otherOptions,
6824
6868
  };
6825
- return await {
6826
- get: this.request.get(url, requestOptions),
6827
- post: this.request.post(url, requestOptions),
6828
- put: this.request.put(url, requestOptions),
6829
- delete: this.request.delete(url, requestOptions),
6830
- }[method.toLowerCase()];
6869
+ const httpMethodsHandlers = {
6870
+ get: () => this.request.get(url, requestOptions),
6871
+ post: () => this.request.post(url, requestOptions),
6872
+ put: () => this.request.put(url, requestOptions),
6873
+ delete: () => this.request.delete(url, requestOptions),
6874
+ };
6875
+ return await httpMethodsHandlers[method.toLowerCase()]();
6831
6876
  };
6832
6877
  this.verifyFieldValue = values => {
6833
6878
  const verifyEachFieldValue = ({ field, value, }) => test.expect(this.page.getByTestId(field)).toHaveValue(value);
@@ -6848,67 +6893,11 @@ const commands = {
6848
6893
  },
6849
6894
  page: async ({ page }, use) => {
6850
6895
  await page.goto("/");
6851
- await page.waitForLoadState("load");
6896
+ await page.waitForLoadState();
6852
6897
  await use(page);
6853
6898
  },
6854
6899
  };
6855
6900
 
6856
- const ENVIRONMENT = {
6857
- development: "development",
6858
- staging: "staging",
6859
- review: "review",
6860
- };
6861
- const IS_STAGING_ENV = process.env.TEST_ENV === "staging";
6862
- const STORAGE_STATE = "./e2e/auth/user.json";
6863
- const GLOBAL_TRANSLATIONS_PATTERN = "../node_modules/@bigbinary/**/translations/en.json";
6864
- const PROJECT_TRANSLATIONS_PATH = "../app/javascript/src/translations/en.json";
6865
- const CREDENTIALS = { email: "oliver@example.com", password: "welcome" };
6866
-
6867
- const joinString = (string1, string2, string3 = "", separator = " ") => {
6868
- if (string3 === "") {
6869
- return string1 + separator + string2;
6870
- }
6871
- return string1 + separator + string2 + separator + string3;
6872
- };
6873
- const readFileSyncIfExists = (path = STORAGE_STATE) => {
6874
- try {
6875
- return JSON.parse(fs__namespace.readFileSync(path, "utf8"));
6876
- }
6877
- catch (error) {
6878
- return {};
6879
- }
6880
- };
6881
- const writeDataToFile = data => {
6882
- try {
6883
- fs__namespace.writeFileSync(STORAGE_STATE, data, "utf8");
6884
- }
6885
- catch (error) {
6886
- console.log(error); // eslint-disable-line
6887
- }
6888
- return true;
6889
- };
6890
- const updateCredentials = ({ key, value }) => {
6891
- const data = readFileSyncIfExists();
6892
- data["user"][key] = value;
6893
- return writeDataToFile(JSON.stringify(data));
6894
- };
6895
- const clearCredentials = () => {
6896
- fs__namespace.unlink(STORAGE_STATE, error => {
6897
- if (!error)
6898
- return;
6899
- console.log(error); // eslint-disable-line
6900
- });
6901
- };
6902
- const readTranslations = () => {
6903
- let translations = readFileSyncIfExists(PROJECT_TRANSLATIONS_PATH);
6904
- const paths = out.sync(GLOBAL_TRANSLATIONS_PATTERN);
6905
- paths.forEach(path => {
6906
- const packageTranslation = readFileSyncIfExists(path);
6907
- translations = ramda.mergeDeepLeft(translations, packageTranslation);
6908
- });
6909
- return translations;
6910
- };
6911
-
6912
6901
  const timestamp = dayjs__default["default"]().format("YYYYMMDDHH");
6913
6902
  const firstName = "André";
6914
6903
  const lastName = "O'Reilly";
@@ -6925,7 +6914,7 @@ const stagingData = {
6925
6914
  businessName: stagingOrganization,
6926
6915
  subdomainName: IS_STAGING_ENV ? stagingOrganization : "spinkart",
6927
6916
  email: IS_STAGING_ENV
6928
- ? `cypresstest${otpBypassKey}+invoice+${timestamp}@bigbinary.com`
6917
+ ? `cypresstest${otpBypassKey}+invoice+${timestamp}-playwright@bigbinary.com`
6929
6918
  : "oliver@example.com",
6930
6919
  };
6931
6920
 
@@ -6945,25 +6934,14 @@ const i18n = {
6945
6934
  };
6946
6935
 
6947
6936
  const BASE_URL = "/api/v1";
6948
- const PROFILE_PATH = "/profile";
6949
- const NEETO_AUTH_URL = "https://app.neetoauth.net";
6950
- const LOGIN_PATH = `${BASE_URL}/login`;
6951
- const SIGNUP_PATH = `${BASE_URL}/signups`;
6952
- const SUBDOMAIN_AVAILABILITY_PATH = `${BASE_URL}/subdomain_availability`;
6953
- const COUNTRIES_PATH = `${BASE_URL}/countries`;
6954
- const NEETO_APPS_PATH = `${BASE_URL}/neeto_apps`;
6955
-
6956
- const COMMON_SELECTORS = {
6957
- toastMessage: "toastr-message-container",
6958
- toastIcon: ".Toastify__toast-icon",
6959
- toastCloseButton: "toastr-close-button",
6960
- dropdownIcon: "nui-dropdown-icon",
6961
- checkbox: "nui-checkbox-input",
6962
- spinner: ".neeto-ui-spinner",
6963
- input: "nui-input-field",
6964
- alertModalSubmitButton: "alert-submit-button",
6965
- selectContainer: "nui-select-container",
6966
- subheaderText: "subheader-left",
6937
+ const ROUTES = {
6938
+ neetoAuth: "https://app.neetoauth.net",
6939
+ profile: "/profile",
6940
+ login: `${BASE_URL}/login`,
6941
+ signup: `${BASE_URL}/signups`,
6942
+ subdomainAvailability: `${BASE_URL}/subdomain_availability`,
6943
+ countries: `${BASE_URL}/countries`,
6944
+ neetoApps: `${BASE_URL}/neeto_apps`,
6967
6945
  };
6968
6946
 
6969
6947
  const SIGNUP_SELECTORS = {
@@ -7001,8 +6979,8 @@ class OrganizationPage {
7001
6979
  : await this.page.goto(`${authUrl}?redirect_uri=${appNameInLowerCase}.net`);
7002
6980
  await this.page.getByTestId(SIGNUP_SELECTORS.emailTextField).fill(email);
7003
6981
  const signup = this.neetoPlaywrightUtilities.interceptMultipleResponses({
7004
- responseUrl: SIGNUP_PATH,
7005
- baseUrl: NEETO_AUTH_URL,
6982
+ responseUrl: ROUTES.signup,
6983
+ baseUrl: ROUTES.neetoAuth,
7006
6984
  });
7007
6985
  await this.page.getByTestId(SIGNUP_SELECTORS.submitButton).click();
7008
6986
  await signup;
@@ -7010,7 +6988,7 @@ class OrganizationPage {
7010
6988
  await this.page
7011
6989
  .getByTestId(SIGNUP_SELECTORS.organizationNameTextField)
7012
6990
  .fill(businessName);
7013
- const fetchSubdomainAvailability = this.page.waitForResponse(response => response.url().includes(SUBDOMAIN_AVAILABILITY_PATH));
6991
+ const fetchSubdomainAvailability = this.page.waitForResponse(response => response.url().includes(ROUTES.subdomainAvailability));
7014
6992
  await this.page
7015
6993
  .getByTestId(SIGNUP_SELECTORS.subdomainNameTextField)
7016
6994
  .fill(subdomainName);
@@ -7024,10 +7002,10 @@ class OrganizationPage {
7024
7002
  .getByTestId(SIGNUP_SELECTORS.organizationSubmitButton)
7025
7003
  .click();
7026
7004
  await Promise.all([
7027
- this.page.waitForResponse(response => response.url().includes(SIGNUP_PATH)),
7028
- this.page.waitForResponse(response => response.url().includes(COUNTRIES_PATH)),
7005
+ this.page.waitForResponse(response => response.url().includes(ROUTES.signup)),
7006
+ this.page.waitForResponse(response => response.url().includes(ROUTES.countries)),
7029
7007
  ]);
7030
- await this.page.waitForURL(`**${PROFILE_PATH}`, { timeout: 15000 });
7008
+ await this.page.waitForURL(`**${ROUTES.profile}`, { timeout: 15000 });
7031
7009
  await this.page
7032
7010
  .getByTestId(SIGNUP_SELECTORS.firstNameTextField)
7033
7011
  .fill(firstName);
@@ -7036,8 +7014,8 @@ class OrganizationPage {
7036
7014
  .fill(lastName);
7037
7015
  await this.page.getByTestId(COMMON_SELECTORS.checkbox).click();
7038
7016
  const submitProfile = this.neetoPlaywrightUtilities.interceptMultipleResponses({
7039
- responseUrl: SIGNUP_PATH,
7040
- baseUrl: NEETO_AUTH_URL,
7017
+ responseUrl: ROUTES.signup,
7018
+ baseUrl: ROUTES.neetoAuth,
7041
7019
  });
7042
7020
  await this.page.getByTestId(SIGNUP_SELECTORS.profileSubmitButton).click();
7043
7021
  await submitProfile;
@@ -7055,7 +7033,7 @@ class OrganizationPage {
7055
7033
  subdomainName: user.subdomainName,
7056
7034
  appName: "neetoInvoice",
7057
7035
  });
7058
- await this.page.route(`**${NEETO_APPS_PATH}`, async (route) => {
7036
+ await this.page.route(`**${ROUTES.neetoApps}`, async (route) => {
7059
7037
  headers = await route.request().allHeaders();
7060
7038
  await route.continue();
7061
7039
  });
@@ -7078,7 +7056,7 @@ class OrganizationPage {
7078
7056
  await this.page
7079
7057
  .getByTestId(SIGNUP_SELECTORS.subdomainNameTextField)
7080
7058
  .fill(newOrganizationName);
7081
- await this.page.waitForResponse(response => response.url().includes(SUBDOMAIN_AVAILABILITY_PATH));
7059
+ await this.page.waitForResponse(response => response.url().includes(ROUTES.subdomainAvailability));
7082
7060
  subdomainErrorCount = await subdomainError.count();
7083
7061
  if (subdomainErrorCount === 0) {
7084
7062
  updateCredentials({
@@ -7143,21 +7121,23 @@ const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, }) => {
7143
7121
  var _a;
7144
7122
  await page.goto((_a = process.env.BASE_URL) !== null && _a !== void 0 ? _a : "");
7145
7123
  let headers = {};
7146
- await page.route(`**${LOGIN_PATH}`, async (route) => {
7147
- headers = await route.request().allHeaders();
7148
- await route.continue();
7149
- });
7150
7124
  await page.getByTestId("login-email-text-field").fill(CREDENTIALS.email);
7151
7125
  await page
7152
7126
  .getByTestId("login-password-text-field")
7153
7127
  .fill(CREDENTIALS.password);
7154
7128
  const login = neetoPlaywrightUtilities.interceptMultipleResponses({
7155
- times: 2,
7129
+ times: 1,
7156
7130
  });
7157
7131
  await page.getByTestId(LOGIN_SELECTORS.submitButton).click();
7158
7132
  await login;
7133
+ await page.route(`**${BASE_URL}/**`, async (route) => {
7134
+ headers = await route.request().allHeaders();
7135
+ await route.continue();
7136
+ });
7159
7137
  const userCredentials = readFileSyncIfExists();
7160
7138
  await page.context().storageState({ path: STORAGE_STATE });
7139
+ //eslint-disable-next-line
7140
+ await page.waitForTimeout(5000); // There is a delay in headers being set from the route.
7161
7141
  const mergedCredentials = {
7162
7142
  ...readFileSyncIfExists(),
7163
7143
  ...userCredentials,
@@ -7250,7 +7230,7 @@ var require$$4 = {
7250
7230
  browser: browser
7251
7231
  };
7252
7232
 
7253
- const fs = fs__default["default"];
7233
+ const fs = require$$0__default$3["default"];
7254
7234
  const path = require$$0__default["default"];
7255
7235
  const os = require$$2__default["default"];
7256
7236
  const crypto = require$$3__default["default"];
@@ -7582,7 +7562,7 @@ const definePlaywrightConfig = (overrides) => {
7582
7562
  const { globalOverrides = {}, useOverrides = {}, projectOverrides = [], currentsOverrides = {}, } = overrides;
7583
7563
  return test.defineConfig({
7584
7564
  testDir: "./e2e/tests",
7585
- fullyParallel: false,
7565
+ fullyParallel: true,
7586
7566
  forbidOnly: isCI,
7587
7567
  retries: isCI ? 1 : 0,
7588
7568
  timeout: 0,
@@ -7619,23 +7599,17 @@ const definePlaywrightConfig = (overrides) => {
7619
7599
  exports.BASE_URL = BASE_URL;
7620
7600
  exports.COMMON_SELECTORS = COMMON_SELECTORS;
7621
7601
  exports.COMMON_TEXTS = COMMON_TEXTS;
7622
- exports.COUNTRIES_PATH = COUNTRIES_PATH;
7623
7602
  exports.CREDENTIALS = CREDENTIALS;
7624
7603
  exports.CustomCommands = CustomCommands;
7625
7604
  exports.ENVIRONMENT = ENVIRONMENT;
7626
7605
  exports.GLOBAL_TRANSLATIONS_PATTERN = GLOBAL_TRANSLATIONS_PATTERN;
7627
7606
  exports.IS_STAGING_ENV = IS_STAGING_ENV;
7628
- exports.LOGIN_PATH = LOGIN_PATH;
7629
7607
  exports.LOGIN_SELECTORS = LOGIN_SELECTORS;
7630
- exports.NEETO_APPS_PATH = NEETO_APPS_PATH;
7631
- exports.NEETO_AUTH_URL = NEETO_AUTH_URL;
7632
7608
  exports.OrganizationPage = OrganizationPage;
7633
- exports.PROFILE_PATH = PROFILE_PATH;
7634
7609
  exports.PROJECT_TRANSLATIONS_PATH = PROJECT_TRANSLATIONS_PATH;
7635
- exports.SIGNUP_PATH = SIGNUP_PATH;
7610
+ exports.ROUTES = ROUTES;
7636
7611
  exports.SIGNUP_SELECTORS = SIGNUP_SELECTORS;
7637
7612
  exports.STORAGE_STATE = STORAGE_STATE;
7638
- exports.SUBDOMAIN_AVAILABILITY_PATH = SUBDOMAIN_AVAILABILITY_PATH;
7639
7613
  exports.clearCredentials = clearCredentials;
7640
7614
  exports.commands = commands;
7641
7615
  exports.definePlaywrightConfig = definePlaywrightConfig;