@hs-web-team/eslint-config-node 3.2.0-next.6 → 3.2.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/.github/workflows/main.yml +2 -2
- package/.github/workflows/pr.yml +2 -2
- package/.nvmrc +1 -1
- package/CLAUDE.md +4 -3
- package/README.md +3 -33
- package/examples/cypress-usage.md +119 -244
- package/package.json +2 -2
- package/cypress.config.ts +0 -120
|
@@ -11,11 +11,11 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
strategy:
|
|
13
13
|
matrix:
|
|
14
|
-
node: [
|
|
14
|
+
node: [24]
|
|
15
15
|
|
|
16
16
|
name: Node ${{ matrix.node }} lint
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
19
|
- name: Run unit tests
|
|
20
20
|
uses: actions/setup-node@v6
|
|
21
21
|
with:
|
package/.github/workflows/pr.yml
CHANGED
|
@@ -11,11 +11,11 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
strategy:
|
|
13
13
|
matrix:
|
|
14
|
-
node: [
|
|
14
|
+
node: [24]
|
|
15
15
|
|
|
16
16
|
name: Node ${{ matrix.node }} sample
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
19
|
- name: Run unit tests
|
|
20
20
|
uses: actions/setup-node@v6
|
|
21
21
|
with:
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
v24
|
package/CLAUDE.md
CHANGED
|
@@ -94,6 +94,7 @@ When testing changes to this package in downstream projects, you'll typically:
|
|
|
94
94
|
- Uses **esbuild** preprocessor for fast bundling (much faster than webpack)
|
|
95
95
|
- Includes Cucumber preprocessor setup with native esbuild support
|
|
96
96
|
- Native TypeScript support via esbuild (no additional loader needed)
|
|
97
|
+
- `@badeball/cypress-cucumber-preprocessor`, `@bahmutov/cypress-esbuild-preprocessor`, `esbuild`, and `js-yaml` are all bundled — consumers only need to install `cypress`
|
|
97
98
|
- Spec pattern: `cypress/e2e/*.cy.js`
|
|
98
99
|
- Exported utilities:
|
|
99
100
|
- `config`: Main Cypress configuration object
|
|
@@ -105,7 +106,7 @@ When testing changes to this package in downstream projects, you'll typically:
|
|
|
105
106
|
|
|
106
107
|
### Package Details
|
|
107
108
|
- **Type**: ESM module (`"type": "module"`)
|
|
108
|
-
- **Node requirement**: >=
|
|
109
|
+
- **Node requirement**: >= 24
|
|
109
110
|
- **Exports**:
|
|
110
111
|
- Main export (`.`): `index.js` - Node.js ESLint configuration
|
|
111
112
|
- Browser export (`./browser`): `browser.js` - Browser/React ESLint configuration
|
|
@@ -117,7 +118,7 @@ When testing changes to this package in downstream projects, you'll typically:
|
|
|
117
118
|
### Migration Context
|
|
118
119
|
This package is currently on v3, which uses ESLint 9's flat config format. The project has migrated from:
|
|
119
120
|
- v1 → v2: See `docs/MIGRATION-V2.md`
|
|
120
|
-
- v2 → v3: See `docs/MIGRATION-V3.md` (ESLint 9 flat config migration requiring Node.js
|
|
121
|
+
- v2 → v3: See `docs/MIGRATION-V3.md` (ESLint 9 flat config migration requiring Node.js 24+)
|
|
121
122
|
|
|
122
123
|
## Important Notes
|
|
123
124
|
|
|
@@ -136,7 +137,7 @@ This package is currently on v3, which uses ESLint 9's flat config format. The p
|
|
|
136
137
|
- Mixed module systems:
|
|
137
138
|
- Main package is ESM (`index.js`, `browser.js`)
|
|
138
139
|
- Utility scripts use CommonJS (`bin/add-prettier-scripts.js`, `cypress.config.cjs`)
|
|
139
|
-
- CI runs on Node
|
|
140
|
+
- CI runs on Node 24 (see `.github/workflows/pr.yml`)
|
|
140
141
|
- No automated tests currently (`npm test` will fail with "Error: no test specified")
|
|
141
142
|
- Detailed documentation available in `examples/`:
|
|
142
143
|
- `browser-usage.md` - Browser/React ESLint configuration
|
package/README.md
CHANGED
|
@@ -115,43 +115,13 @@ For detailed Stylelint configuration documentation, see [examples/stylelint-usag
|
|
|
115
115
|
|
|
116
116
|
This package provides shared Cypress configuration for E2E testing.
|
|
117
117
|
|
|
118
|
-
1. Install
|
|
118
|
+
1. Install Cypress
|
|
119
119
|
|
|
120
120
|
```sh
|
|
121
|
-
npm i -D cypress
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
2. Create `cypress.config.js` in project root
|
|
125
|
-
|
|
126
|
-
```javascript
|
|
127
|
-
const { defineConfig } = require('cypress');
|
|
128
|
-
const { config, envs, getBaseUrls } = require('@hs-web-team/eslint-config-node/cypress.config');
|
|
129
|
-
|
|
130
|
-
module.exports = defineConfig({
|
|
131
|
-
...config,
|
|
132
|
-
e2e: {
|
|
133
|
-
...config.e2e,
|
|
134
|
-
baseUrl: 'http://localhost:3000',
|
|
135
|
-
},
|
|
136
|
-
env: {
|
|
137
|
-
...envs,
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
3. Add scripts to package.json
|
|
143
|
-
|
|
144
|
-
```json
|
|
145
|
-
{
|
|
146
|
-
"scripts": {
|
|
147
|
-
"cypress:open": "cypress open",
|
|
148
|
-
"cypress:run": "cypress run",
|
|
149
|
-
"test:e2e": "cypress run"
|
|
150
|
-
}
|
|
151
|
-
}
|
|
121
|
+
npm i -D cypress@15
|
|
152
122
|
```
|
|
153
123
|
|
|
154
|
-
For detailed Cypress configuration
|
|
124
|
+
For detailed Cypress configuration and migration documentation, see [examples/cypress-usage.md](./examples/cypress-usage.md).
|
|
155
125
|
|
|
156
126
|
## Where to use it
|
|
157
127
|
|
|
@@ -4,16 +4,10 @@ This package provides a shared Cypress configuration for E2E testing in HubSpot
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
For full setup instructions, see the [Cypress Framework Setup](https://git.hubteam.com/pages/MarketingWebTeam/webteam-docs/docs/developers/coding-on-the-web-team/software-testing/cypress-framework-setup/) guide.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
2. If using TypeScript:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install --save-dev typescript @types/node
|
|
10
|
+
npm i -D cypress@15
|
|
17
11
|
```
|
|
18
12
|
|
|
19
13
|
## Usage
|
|
@@ -24,18 +18,13 @@ Create a `cypress.config.js` file in your project root:
|
|
|
24
18
|
|
|
25
19
|
```javascript
|
|
26
20
|
const { defineConfig } = require('cypress');
|
|
27
|
-
const { config
|
|
21
|
+
const { config } = require('@hs-web-team/eslint-config-node/cypress.config');
|
|
28
22
|
|
|
29
23
|
module.exports = defineConfig({
|
|
30
24
|
...config,
|
|
31
25
|
e2e: {
|
|
32
26
|
...config.e2e,
|
|
33
|
-
baseUrl: 'http://localhost:3000',
|
|
34
|
-
// Add custom e2e options here
|
|
35
|
-
},
|
|
36
|
-
env: {
|
|
37
|
-
...envs,
|
|
38
|
-
// Add custom environment variables
|
|
27
|
+
baseUrl: 'http://localhost:3000',
|
|
39
28
|
},
|
|
40
29
|
});
|
|
41
30
|
```
|
|
@@ -54,7 +43,7 @@ module.exports = defineConfig({
|
|
|
54
43
|
...config,
|
|
55
44
|
e2e: {
|
|
56
45
|
...config.e2e,
|
|
57
|
-
baseUrl: baseUrls.qa
|
|
46
|
+
baseUrl: baseUrls.qa,
|
|
58
47
|
},
|
|
59
48
|
env: {
|
|
60
49
|
...envs,
|
|
@@ -67,163 +56,72 @@ module.exports = defineConfig({
|
|
|
67
56
|
|
|
68
57
|
### Core Configuration
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- **
|
|
73
|
-
- **
|
|
74
|
-
- Default command timeout: 20 seconds
|
|
75
|
-
- Page load timeout: 20 seconds
|
|
76
|
-
- Response timeout: 20 seconds
|
|
77
|
-
- **Test Settings**:
|
|
78
|
-
- Port: 3500
|
|
79
|
-
- Viewport: 1920x1080
|
|
80
|
-
- Tests kept in memory: 0 (prevents memory issues)
|
|
81
|
-
- **Retries**:
|
|
82
|
-
- Run mode: 1 retry
|
|
83
|
-
- Open mode: 0 retries
|
|
84
|
-
- **Screenshots**: Enabled on failure
|
|
59
|
+
- **Chrome Web Security**: Disabled for cross-origin testing
|
|
60
|
+
- **Timeouts**: 20s for default command, page load, and response (Cypress default is 4s)
|
|
61
|
+
- **Viewport**: 1920x1080
|
|
62
|
+
- **Retries**: 1 in run mode, 0 in open mode
|
|
85
63
|
- **Video**: Disabled by default
|
|
86
|
-
- **
|
|
64
|
+
- **Tests kept in memory**: 0 (prevents memory issues)
|
|
87
65
|
|
|
88
66
|
### E2E Configuration
|
|
89
67
|
|
|
90
|
-
- **Spec
|
|
91
|
-
- **Cucumber
|
|
92
|
-
- **TypeScript
|
|
93
|
-
- **esbuild Preprocessor**: Fast bundling for `.feature` files, TypeScript, and JavaScript
|
|
68
|
+
- **Spec pattern**: `cypress/e2e/*.cy.js`
|
|
69
|
+
- **Cucumber support**: Includes Cucumber preprocessor setup with esbuild
|
|
70
|
+
- **TypeScript support**: Native via esbuild, no additional loader needed
|
|
94
71
|
|
|
95
|
-
###
|
|
72
|
+
### Exports
|
|
96
73
|
|
|
97
|
-
|
|
74
|
+
| Export | Description |
|
|
75
|
+
|--------|-------------|
|
|
76
|
+
| `config` | Main Cypress configuration object |
|
|
77
|
+
| `envs` | Environment constants (`DEV`, `QA`, `PROD`, `currentEnv`) |
|
|
78
|
+
| `setupNodeEvents` | The `setupNodeEvents` function (for custom extension) |
|
|
79
|
+
| `getDevBaseUrl()` | Reads `baseUrl` from the DEV portal in `hubspot.config.yml` |
|
|
80
|
+
| `getBaseUrls()` | Reads URLs for all environments from `.ci/config.yml` |
|
|
98
81
|
|
|
99
82
|
#### `envs`
|
|
100
|
-
|
|
83
|
+
|
|
101
84
|
```javascript
|
|
102
|
-
|
|
103
|
-
currentEnv: 'qa',
|
|
85
|
+
{
|
|
86
|
+
currentEnv: 'qa',
|
|
104
87
|
DEV: 'DEV',
|
|
105
88
|
QA: 'qa',
|
|
106
89
|
PROD: 'prod',
|
|
107
|
-
}
|
|
90
|
+
}
|
|
108
91
|
```
|
|
109
92
|
|
|
110
93
|
#### `getDevBaseUrl()`
|
|
111
|
-
Retrieves the `baseUrl` from the `DEV` portal in `hubspot.config.yml`:
|
|
112
94
|
|
|
113
|
-
|
|
114
|
-
const devUrl = getDevBaseUrl(); // Returns baseUrl or null
|
|
115
|
-
```
|
|
95
|
+
Returns the `baseUrl` from the `DEV` portal in `hubspot.config.yml`, or `null` if not found.
|
|
116
96
|
|
|
117
|
-
**Requirements**:
|
|
118
|
-
- Project must have a `hubspot.config.yml` file
|
|
119
|
-
- DEV portal must have a `baseUrl` property configured
|
|
97
|
+
**Requirements**: `hubspot.config.yml` must exist and the DEV portal must have a `baseUrl` property.
|
|
120
98
|
|
|
121
99
|
#### `getBaseUrls()`
|
|
122
|
-
|
|
100
|
+
|
|
101
|
+
Returns base URLs for all environments:
|
|
123
102
|
|
|
124
103
|
```javascript
|
|
125
|
-
const urls = getBaseUrls();
|
|
126
104
|
// Returns: { DEV: '...', qa: '...', prod: '...' }
|
|
127
105
|
```
|
|
128
106
|
|
|
129
|
-
|
|
130
|
-
- `.ci/config.yml` file with `regression.e2eTestEnvironment` configuration
|
|
131
|
-
- Format:
|
|
132
|
-
```yaml
|
|
133
|
-
regression:
|
|
134
|
-
e2eTestEnvironment:
|
|
135
|
-
- name: qa
|
|
136
|
-
url: https://qa.example.com
|
|
137
|
-
- name: prod
|
|
138
|
-
url: https://prod.example.com
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## Project Structure
|
|
142
|
-
|
|
143
|
-
### Recommended Folder Structure
|
|
144
|
-
|
|
145
|
-
```
|
|
146
|
-
project-root/
|
|
147
|
-
├── cypress/
|
|
148
|
-
│ ├── e2e/
|
|
149
|
-
│ │ ├── login.cy.js
|
|
150
|
-
│ │ └── homepage.cy.js
|
|
151
|
-
│ ├── fixtures/
|
|
152
|
-
│ │ └── users.json
|
|
153
|
-
│ ├── support/
|
|
154
|
-
│ │ ├── commands.js
|
|
155
|
-
│ │ └── e2e.js
|
|
156
|
-
│ └── downloads/
|
|
157
|
-
├── cypress.config.js
|
|
158
|
-
└── package.json
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### For Cucumber/BDD Testing
|
|
162
|
-
|
|
163
|
-
```
|
|
164
|
-
project-root/
|
|
165
|
-
├── cypress/
|
|
166
|
-
│ ├── e2e/
|
|
167
|
-
│ │ └── features/
|
|
168
|
-
│ │ ├── login.feature
|
|
169
|
-
│ │ └── homepage.feature
|
|
170
|
-
│ ├── support/
|
|
171
|
-
│ │ ├── step_definitions/
|
|
172
|
-
│ │ │ ├── login.ts
|
|
173
|
-
│ │ │ └── homepage.ts
|
|
174
|
-
│ │ └── e2e.ts
|
|
175
|
-
└── cypress.config.js
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Add Scripts to package.json
|
|
179
|
-
|
|
180
|
-
Add Cypress scripts to your `package.json`:
|
|
107
|
+
The `DEV` key comes from `getDevBaseUrl()`. The `qa` and `prod` keys come from `.ci/config.yml`:
|
|
181
108
|
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"test:e2e": "cypress run"
|
|
190
|
-
}
|
|
191
|
-
}
|
|
109
|
+
```yaml
|
|
110
|
+
regression:
|
|
111
|
+
e2eTestEnvironment:
|
|
112
|
+
- name: qa
|
|
113
|
+
url: https://qa.example.com
|
|
114
|
+
- name: prod
|
|
115
|
+
url: https://prod.example.com
|
|
192
116
|
```
|
|
193
117
|
|
|
194
|
-
Then run:
|
|
195
|
-
- `npm run cypress:open` - Open Cypress Test Runner (interactive)
|
|
196
|
-
- `npm run cypress:run` - Run all tests headlessly
|
|
197
|
-
- `npm run test:e2e` - Run E2E tests (alias for cypress:run)
|
|
198
|
-
|
|
199
118
|
## Customizing Configuration
|
|
200
119
|
|
|
201
|
-
### Override Default Values
|
|
202
|
-
|
|
203
|
-
```javascript
|
|
204
|
-
const { defineConfig } = require('cypress');
|
|
205
|
-
const { config } = require('@hs-web-team/eslint-config-node/cypress.config');
|
|
206
|
-
|
|
207
|
-
module.exports = defineConfig({
|
|
208
|
-
...config,
|
|
209
|
-
// Override specific values
|
|
210
|
-
defaultCommandTimeout: 30000,
|
|
211
|
-
viewportWidth: 1280,
|
|
212
|
-
viewportHeight: 720,
|
|
213
|
-
video: true, // Enable video recording
|
|
214
|
-
e2e: {
|
|
215
|
-
...config.e2e,
|
|
216
|
-
baseUrl: 'http://localhost:8080',
|
|
217
|
-
specPattern: 'cypress/integration/**/*.spec.js',
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
120
|
### Add Custom setupNodeEvents
|
|
223
121
|
|
|
224
|
-
`setupNodeEvents` is
|
|
122
|
+
`setupNodeEvents` is embedded in `config.e2e`. If you override it without calling the package's version, you'll lose the Cucumber preprocessor and esbuild setup.
|
|
225
123
|
|
|
226
|
-
Import `setupNodeEvents` directly and call it
|
|
124
|
+
Import `setupNodeEvents` directly and call it first:
|
|
227
125
|
|
|
228
126
|
```javascript
|
|
229
127
|
const { defineConfig } = require('cypress');
|
|
@@ -234,7 +132,6 @@ module.exports = defineConfig({
|
|
|
234
132
|
e2e: {
|
|
235
133
|
...config.e2e,
|
|
236
134
|
async setupNodeEvents(on, cfg) {
|
|
237
|
-
// sets up esbuild preprocessor and Cucumber
|
|
238
135
|
await wtSetupNodeEvents(on, cfg);
|
|
239
136
|
|
|
240
137
|
on('task', {
|
|
@@ -250,133 +147,111 @@ module.exports = defineConfig({
|
|
|
250
147
|
});
|
|
251
148
|
```
|
|
252
149
|
|
|
253
|
-
If you don't need custom node events, omit `setupNodeEvents` entirely and just spread `...config.e2e
|
|
150
|
+
If you don't need custom node events, omit `setupNodeEvents` entirely and just spread `...config.e2e`.
|
|
254
151
|
|
|
255
|
-
##
|
|
152
|
+
## Migrating from `@hs-web-team/eslint-config-browser`
|
|
256
153
|
|
|
257
|
-
###
|
|
154
|
+
### 1. Update the import
|
|
258
155
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
jobs:
|
|
264
|
-
cypress-run:
|
|
265
|
-
runs-on: ubuntu-latest
|
|
266
|
-
steps:
|
|
267
|
-
- name: Checkout
|
|
268
|
-
uses: actions/checkout@v4
|
|
269
|
-
|
|
270
|
-
- name: Setup Node
|
|
271
|
-
uses: actions/setup-node@v4
|
|
272
|
-
with:
|
|
273
|
-
node-version: 22
|
|
274
|
-
|
|
275
|
-
- name: Install dependencies
|
|
276
|
-
run: npm ci
|
|
277
|
-
|
|
278
|
-
- name: Run Cypress tests
|
|
279
|
-
uses: cypress-io/github-action@v6
|
|
280
|
-
with:
|
|
281
|
-
start: npm start
|
|
282
|
-
wait-on: 'http://localhost:3000'
|
|
283
|
-
```
|
|
156
|
+
**JavaScript:**
|
|
157
|
+
```javascript
|
|
158
|
+
// Before
|
|
159
|
+
const { getDevBaseUrl, getBaseUrls, config, envs } = require('@hs-web-team/eslint-config-browser/cypress.config.js');
|
|
284
160
|
|
|
285
|
-
|
|
161
|
+
// After
|
|
162
|
+
const { getDevBaseUrl, getBaseUrls, config, envs } = require('@hs-web-team/eslint-config-node/cypress.config');
|
|
163
|
+
```
|
|
286
164
|
|
|
287
|
-
|
|
165
|
+
**TypeScript (module format stays the same — ESM `import`/`export default` still works):**
|
|
166
|
+
```typescript
|
|
167
|
+
// Before
|
|
168
|
+
import { getDevBaseUrl, getBaseUrls, config, envs } from '@hs-web-team/eslint-config-browser/cypress.config.js';
|
|
288
169
|
|
|
289
|
-
|
|
290
|
-
{
|
|
291
|
-
"compilerOptions": {
|
|
292
|
-
"target": "ES2021",
|
|
293
|
-
"lib": ["ES2021", "DOM"],
|
|
294
|
-
"types": ["cypress", "node"],
|
|
295
|
-
"moduleResolution": "node",
|
|
296
|
-
"esModuleInterop": true,
|
|
297
|
-
"skipLibCheck": true,
|
|
298
|
-
"strict": true
|
|
299
|
-
},
|
|
300
|
-
"include": ["cypress/**/*.ts"],
|
|
301
|
-
"exclude": ["node_modules"]
|
|
302
|
-
}
|
|
170
|
+
// After
|
|
171
|
+
import { getDevBaseUrl, getBaseUrls, envs, config as wtConfig } from '@hs-web-team/eslint-config-node/cypress.config';
|
|
303
172
|
```
|
|
304
173
|
|
|
305
|
-
|
|
174
|
+
### 2. Remove manual `setupNodeEvents`
|
|
306
175
|
|
|
307
|
-
|
|
176
|
+
Cucumber and esbuild are bundled into `config.e2e.setupNodeEvents`. Remove your manual `setupNodeEvents` function entirely and spread `...config.e2e` to inherit it automatically.
|
|
308
177
|
|
|
309
|
-
|
|
310
|
-
```bash
|
|
311
|
-
npm install --save-dev @badeball/cypress-cucumber-preprocessor
|
|
312
|
-
```
|
|
178
|
+
If you need to add custom tasks on top, see [Add Custom setupNodeEvents](#add-custom-setupnodeevents).
|
|
313
179
|
|
|
314
|
-
|
|
315
|
-
```json
|
|
316
|
-
{
|
|
317
|
-
"stepDefinitions": "cypress/support/step_definitions/**/*.{js,ts}",
|
|
318
|
-
"json": {
|
|
319
|
-
"enabled": true,
|
|
320
|
-
"output": "cypress/results/cucumber-report.json"
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
```
|
|
180
|
+
### 3. Update the config structure
|
|
324
181
|
|
|
325
|
-
|
|
326
|
-
```gherkin
|
|
327
|
-
Feature: Login
|
|
182
|
+
The old pattern built the full `e2e` object from scratch — repeating settings already in the bundle — then assigned it:
|
|
328
183
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
184
|
+
```javascript
|
|
185
|
+
const customConfig = { ...config };
|
|
186
|
+
const e2e = {
|
|
187
|
+
specPattern: 'cypress/e2e/**/*.feature',
|
|
188
|
+
baseUrl,
|
|
189
|
+
setupNodeEvents, // manual webpack + cucumber setup
|
|
190
|
+
defaultCommandTimeout: 20000, // already in bundle
|
|
191
|
+
retries: { runMode: 1, openMode: 0 }, // already in bundle
|
|
192
|
+
// ...
|
|
193
|
+
};
|
|
194
|
+
customConfig.e2e = e2e;
|
|
195
|
+
module.exports = defineConfig(customConfig);
|
|
333
196
|
```
|
|
334
197
|
|
|
335
|
-
|
|
198
|
+
The new pattern spreads `...config.e2e` to inherit bundled settings (including `setupNodeEvents`) and only adds project-specific overrides:
|
|
336
199
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
200
|
+
**JavaScript:**
|
|
201
|
+
```javascript
|
|
202
|
+
module.exports = defineConfig({
|
|
203
|
+
...config,
|
|
204
|
+
e2e: {
|
|
205
|
+
...config.e2e,
|
|
206
|
+
specPattern: 'cypress/e2e/**/*.feature',
|
|
207
|
+
baseUrl,
|
|
208
|
+
supportFile: 'cypress/support/e2e.js',
|
|
209
|
+
reporter: 'mochawesome',
|
|
210
|
+
reporterOptions: {
|
|
211
|
+
reportDir: 'cypress/results',
|
|
212
|
+
overwrite: false,
|
|
213
|
+
html: true,
|
|
214
|
+
json: true,
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
```
|
|
344
219
|
|
|
345
|
-
|
|
220
|
+
**TypeScript:**
|
|
221
|
+
```typescript
|
|
222
|
+
export default defineConfig({
|
|
223
|
+
e2e: {
|
|
224
|
+
...wtConfig.e2e,
|
|
225
|
+
specPattern: 'cypress/e2e/**/*.feature',
|
|
226
|
+
baseUrl,
|
|
227
|
+
supportFile: 'cypress/support/e2e.ts',
|
|
228
|
+
reporter: 'mochawesome',
|
|
229
|
+
reporterOptions: {
|
|
230
|
+
reportDir: 'cypress/results',
|
|
231
|
+
overwrite: false,
|
|
232
|
+
html: true,
|
|
233
|
+
json: true,
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
blockHosts: '*.google-analytics.com',
|
|
237
|
+
});
|
|
238
|
+
```
|
|
346
239
|
|
|
347
|
-
|
|
240
|
+
### 4. Keep project-specific settings not in the bundle
|
|
348
241
|
|
|
349
|
-
|
|
242
|
+
These are not included in the bundle and must be carried over manually if your project uses them:
|
|
350
243
|
|
|
351
|
-
-
|
|
352
|
-
-
|
|
353
|
-
-
|
|
354
|
-
-
|
|
244
|
+
- `reporter` and `reporterOptions` (e.g. mochawesome)
|
|
245
|
+
- `supportFile`
|
|
246
|
+
- `blockHosts`
|
|
247
|
+
- `fixturesFolder`, `screenshotsFolder`, `videosFolder`
|
|
248
|
+
- `testIsolation`
|
|
249
|
+
- `specPattern` (if using `.feature` files — bundle default is `cypress/e2e/*.cy.js`)
|
|
355
250
|
|
|
356
251
|
## Troubleshooting
|
|
357
252
|
|
|
358
|
-
### Module Not Found Errors
|
|
359
|
-
|
|
360
|
-
Ensure all required dependencies are installed:
|
|
361
|
-
```bash
|
|
362
|
-
npm install --save-dev cypress @badeball/cypress-cucumber-preprocessor esbuild js-yaml
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### Compilation Errors
|
|
366
|
-
|
|
367
|
-
If you see compilation errors with TypeScript files, ensure esbuild is installed:
|
|
368
|
-
```bash
|
|
369
|
-
npm install --save-dev esbuild
|
|
370
|
-
```
|
|
371
|
-
|
|
372
253
|
### Environment Configuration Not Loading
|
|
373
254
|
|
|
374
255
|
Ensure your project has the required configuration files:
|
|
375
256
|
- `hubspot.config.yml` for HubSpot projects
|
|
376
257
|
- `.ci/config.yml` for multi-environment setups
|
|
377
|
-
|
|
378
|
-
### Memory Issues
|
|
379
|
-
|
|
380
|
-
The configuration sets `numTestsKeptInMemory: 0` to prevent memory issues. If you still experience problems, consider:
|
|
381
|
-
- Running tests in smaller batches
|
|
382
|
-
- Increasing Node.js memory: `NODE_OPTIONS=--max_old_space_size=4096 cypress run`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hs-web-team/eslint-config-node",
|
|
3
|
-
"version": "3.2.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "HubSpot Marketing WebTeam shared configurations for ESLint, Prettier, Stylelint, and Cypress",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=24"
|
|
30
30
|
},
|
|
31
31
|
"bin": {
|
|
32
32
|
"add-prettier": "bin/add-prettier-scripts.js"
|
package/cypress.config.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
};
|