@hs-web-team/eslint-config-node 3.2.0-next.4 → 3.2.0-next.5

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.
Files changed (2) hide show
  1. package/cypress.config.ts +120 -0
  2. package/package.json +4 -13
@@ -0,0 +1,120 @@
1
+ import yaml from 'js-yaml';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import createBundler from '@bahmutov/cypress-esbuild-preprocessor';
5
+ import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
6
+ import { createEsbuildPlugin } from '@badeball/cypress-cucumber-preprocessor/esbuild';
7
+
8
+ const DEV = 'DEV';
9
+ const QA = 'qa';
10
+ const PROD = 'prod';
11
+ const currentEnv = QA;
12
+
13
+ export const envs = {
14
+ currentEnv,
15
+ DEV,
16
+ QA,
17
+ PROD,
18
+ };
19
+
20
+ /**
21
+ * @description Recursively climbs up the filepath, until it finds what directory
22
+ * the directory where the hubspot.config.yml file is located.
23
+ *
24
+ * @param {string} currDir - the current working directory path to search from
25
+ * @returns {string} The absolute path of the project's root directory
26
+ */
27
+ const getRootDir = (currDir: string): string => {
28
+ if (fs.existsSync(path.join(currDir, 'hubspot.config.yml'))) return currDir;
29
+ const parentDir = path.dirname(currDir);
30
+ if (parentDir === currDir) {
31
+ throw new Error('Error: Could not find the hubspot.config.yml file within the projects directories.');
32
+ }
33
+ return getRootDir(parentDir);
34
+ };
35
+
36
+ /**
37
+ * @returns {string|null} The `baseUrl` set for the `DEV` portal in `hubspot.config.yml`
38
+ * or `null` if this is not the dev environment or no such property exists.
39
+ */
40
+ export const getDevBaseUrl = (): string | null => {
41
+ try {
42
+ global.console.log(
43
+ 'To test a dev URL, add the `baseUrl` property to your `DEV` portal configuration in `hubspot.config.yml`',
44
+ );
45
+
46
+ const root = getRootDir(__dirname);
47
+ const configPath = path.resolve(root, 'hubspot.config.yml');
48
+ const fileContents = fs.readFileSync(configPath, 'utf8');
49
+ const { portals } = yaml.load(fileContents) as { portals: Array<{ name: string; baseUrl?: string }> };
50
+ const devPortal = portals.find(portal => portal.name === 'DEV');
51
+ return devPortal?.baseUrl || null;
52
+ } catch (error) {
53
+ global.console.error(error);
54
+ return null;
55
+ }
56
+ };
57
+
58
+ /**
59
+ * @description Get the baseUrls for different environments from the ci config file for local test execution.
60
+ * @returns {object} baseUrls - The base urls object
61
+ */
62
+ export const getBaseUrls = (): Record<string, string | null> | null => {
63
+ let fileContents = '';
64
+ let ciConfig: { regression?: { e2eTestEnvironment?: Array<{ name: string; url: string }> } } = {};
65
+ const baseUrls: Record<string, string | null> = {};
66
+ baseUrls[envs.DEV] = getDevBaseUrl();
67
+
68
+ const fileExist = fs.existsSync('.ci/config.yml');
69
+ if (fileExist) {
70
+ fileContents = fs.readFileSync('.ci/config.yml', 'utf8');
71
+ ciConfig = yaml.load(fileContents) as typeof ciConfig;
72
+ if (ciConfig.regression?.e2eTestEnvironment && ciConfig.regression.e2eTestEnvironment.length > 0) {
73
+ try {
74
+ ciConfig.regression.e2eTestEnvironment.forEach(item => {
75
+ baseUrls[item.name] = item.url;
76
+ });
77
+ } catch (error) {
78
+ console.error('Error reading the base urls from the ci config file:', error);
79
+ return null;
80
+ }
81
+ }
82
+ }
83
+ return baseUrls || null;
84
+ };
85
+
86
+ async function setupNodeEvents(
87
+ on: Cypress.PluginEvents,
88
+ config: Cypress.PluginConfigOptions,
89
+ ): Promise<Cypress.PluginConfigOptions> {
90
+ await addCucumberPreprocessorPlugin(on, config);
91
+ on(
92
+ 'file:preprocessor',
93
+ createBundler({ plugins: [createEsbuildPlugin(config)] }),
94
+ );
95
+ return config;
96
+ }
97
+
98
+ const e2e: Cypress.EndToEndConfigOptions = {
99
+ specPattern: 'cypress/e2e/*.cy.js',
100
+ setupNodeEvents,
101
+ };
102
+
103
+ export const config: Cypress.ConfigOptions = {
104
+ chromeWebSecurity: false,
105
+ defaultCommandTimeout: 20000,
106
+ e2e,
107
+ numTestsKeptInMemory: 0,
108
+ pageLoadTimeout: 20000,
109
+ port: 3500,
110
+ responseTimeout: 20000,
111
+ retries: {
112
+ runMode: 1,
113
+ openMode: 0,
114
+ },
115
+ screenshotOnRunFailure: true,
116
+ trashAssetsBeforeRuns: true,
117
+ video: false,
118
+ viewportHeight: 1080,
119
+ viewportWidth: 1920,
120
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hs-web-team/eslint-config-node",
3
- "version": "3.2.0-next.4",
3
+ "version": "3.2.0-next.5",
4
4
  "description": "HubSpot Marketing WebTeam shared configurations for ESLint, Prettier, Stylelint, and Cypress",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -53,13 +53,13 @@
53
53
  "globals": "^17.3.0",
54
54
  "jiti": "^2.6.1",
55
55
  "prettier": "^3.8.1",
56
- "typescript-eslint": "^8.54.0"
56
+ "typescript-eslint": "^8.54.0",
57
+ "esbuild": "^0.27.2",
58
+ "js-yaml": "^4.1.1"
57
59
  },
58
60
  "peerDependencies": {
59
61
  "@badeball/cypress-cucumber-preprocessor": "^24.0.0",
60
62
  "cypress": "^15.0.0",
61
- "esbuild": "^0.27.2",
62
- "js-yaml": "^4.1.1",
63
63
  "stylelint": "^17.1.1",
64
64
  "stylelint-config-standard": "^40.0.0",
65
65
  "stylelint-config-standard-scss": "^17.0.0"
@@ -76,15 +76,6 @@
76
76
  },
77
77
  "cypress": {
78
78
  "optional": true
79
- },
80
- "@badeball/cypress-cucumber-preprocessor": {
81
- "optional": true
82
- },
83
- "esbuild": {
84
- "optional": true
85
- },
86
- "js-yaml": {
87
- "optional": true
88
79
  }
89
80
  }
90
81
  }