haven-cypress-integration 1.6.2 → 2.0.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/README.md CHANGED
@@ -1,164 +1,268 @@
1
- # Haven-Cypress Integration
2
-
3
- Seamless integration between Cypress test frameworks and HAVEN test case management system.
4
-
5
- ## Quick Start
6
-
7
- ### 1. Install
1
+ # haven-cypress-integration
2
+
3
+ Seamless Cypress integration with HAVEN test case management. Advanced test execution with real-time monitoring and flexible configuration options.
4
+
5
+ ## Key Features
6
+ - **Automatic report generation** (Mochawesome HTML + JSON)
7
+ - **Tag-based filtering** using `@TC-AUTO-XXXX` and custom tags via `@cypress/grep`
8
+ - **Environment support** - Test against QA/DEV/CTE/PROD environments
9
+ - **Custom tags support** - Filter by `@smoke`, `@regression`, `@p1`, etc.
10
+ - **Real-time log streaming** to S3 during test execution
11
+ - **Flexible test execution** via custom `E2E_COMMAND` environment variable
12
+ - **Enhanced automation ID detection** (supports dots, dashes)
13
+ - **S3 artifact upload** to `artifacts/{PRODUCT}/{PLAN_ID}/automation/{RUN_ID}`
14
+ - **HAVEN API integration** with environment information
15
+ - **ECR push** with product+version tagging (version from consumer `package.json`)
16
+ - **Podman compatible** - Works with both Docker and Podman
17
+
18
+ ## Install
8
19
  ```bash
9
- npm install haven-cypress-integration
10
- ```
11
-
12
- ### 2. Add Tags to Tests
13
- Add `@TC-AUTO-XXXX` tags to your test descriptions:
14
-
15
- ```javascript
16
- it("Login test @TC-AUTO-123, @p2", () => {
17
- cy.visit('/login');
18
- cy.get('[data-cy=username]').type('user');
19
- cy.get('[data-cy=password]').type('pass');
20
- cy.get('[data-cy=submit]').click();
21
- });
22
-
23
- it("User registration @TC-AUTO-124, @p1", () => {
24
- cy.visit('/register');
25
- // your test code
26
- });
20
+ npm install haven-cypress-integration cypress
27
21
  ```
28
22
 
29
- ### 3. Cypress Configuration (Optional Simplification)
30
- The library automatically configures mochawesome reporting. You can use a simplified `cypress.config.js`:
23
+ ## Usage
31
24
 
32
- ```javascript
33
- const { defineConfig } = require("cypress");
25
+ ### Build Types
34
26
 
35
- module.exports = defineConfig({
36
- video: false,
37
- e2e: {
38
- supportFile: "cypress/support/e2e.js",
39
- setupNodeEvents(on, config) {
40
- // Haven-cypress automatically handles:
41
- // - mochawesome reporter configuration
42
- // - grep functionality for tag filtering
43
- // - proper environment variables
44
- return config;
45
- },
46
- },
47
- });
48
- ```
27
+ #### Thin Image (Default)
28
+ Lightweight image that clones your code at runtime from Azure DevOps. Best for CI/CD pipelines:
29
+ ```bash
30
+ # Build thin image (default)
31
+ npx haven-cypress build --product=BE --push
49
32
 
50
- **Note**: If you prefer to keep your existing cypress.config.js with manual mochawesome configuration, that's fine too! The library will respect your settings.
33
+ # Explicit thin image build
34
+ npx haven-cypress build --product=BE --type=thin --push
51
35
 
52
- ### 4. Build Docker Image
53
- ```bash
54
- npx haven-cypress build --product=BE
36
+ # With custom tag
37
+ npx haven-cypress build --product=BE --type=thin --tag=thin-1.0.0 --push
55
38
  ```
56
39
 
57
- ### 5. Push to ECR and Deploy to Haven
40
+ #### Full Image
41
+ Includes your app code baked into the image. Best for simple deployments:
58
42
  ```bash
59
- npx haven-cypress build --product=BE --push
43
+ # Build full image
44
+ npx haven-cypress build --product=BE --type=full --push
60
45
  ```
61
- Your Docker image is now pushed to ECR and ready to be deployed and run by HAVEN!
62
46
 
63
- ## Commands
47
+ **Thin Image Runtime Requirements:**
48
+ - `ADO_REPO` - Full ADO repo path (e.g., `dev.azure.com/org/project/_git/repo`)
49
+ - `ADO_PAT` - Personal Access Token for authentication
50
+ - `ADO_BRANCH` - Branch to clone (optional, default: `main`)
64
51
 
65
- ### Build Image
52
+ ### Build and Deploy Examples
66
53
  ```bash
67
- # Basic build with product organization
54
+ # Build locally (thin image - default)
68
55
  npx haven-cypress build --product=BE
69
56
 
70
- # Custom tag with product
71
- npx haven-cypress build --product=BE --tag=v1.0
72
-
73
- # Build and push to ECR haven-test-images repository
57
+ # Build and push thin image to ECR (default)
74
58
  npx haven-cypress build --product=BE --push
75
59
 
76
- # Build and push with custom tag
77
- npx haven-cypress build --product=BE --tag=v1.0 --push
60
+ # Build and push full image to ECR
61
+ npx haven-cypress build --product=BE --type=full --push
62
+
63
+ # Build with custom version (thin by default)
64
+ npx haven-cypress build --product=BE --tag=v2.1.0 --push
78
65
  ```
79
66
 
80
- ### Run Tests
67
+ ### Running Tests
81
68
  ```bash
82
- # Run all tests
83
- npx haven-cypress run
84
-
85
- # Run specific test cases
69
+ # Run specific automation IDs
86
70
  npx haven-cypress run --automationIds=TC-AUTO-123,TC-AUTO-124
87
- ```
88
71
 
89
- ### ECR Image Organization
90
- Images are organized in the `haven-test-images` ECR repository with product-based versioning:
72
+ # Run tests with custom tags
73
+ npx haven-cypress run --customTags=smoke,p1
74
+
75
+ # Combine automation IDs and custom tags
76
+ npx haven-cypress run --automationIds=TC-AUTO-123 --customTags=smoke
91
77
  ```
92
- Repository: haven-test-images
93
- ├── BE-1.0.123456 (latest with build number)
94
- ├── BE-2.1.0 (semantic version)
95
- ├── payments-1.0.789012
96
- └── auth-3.0.0
78
+
79
+ ### HAVEN Deployment
80
+ HAVEN will run your containerized tests with environment variables:
81
+ ```bash
82
+ docker run \
83
+ -e TEST_ENVIRONMENT=PROD \
84
+ -e PLAN_ID=123 \
85
+ -e RUN_ID=456 \
86
+ -e E2E_COMMAND="npm run test:e2e" \
87
+ 066726995253.dkr.ecr.us-east-1.amazonaws.com/haven-test-images:BE-1.1.0 \
88
+ --customTags=smoke,p1
97
89
  ```
98
90
 
99
- **Tag Format**: `{PRODUCT}-{VERSION}`
100
- - **Product**: Organizes images by product/team
101
- - **Version**: Semantic versioning (e.g., `2.1.0`) or build numbers (e.g., `1.0.123456`)
91
+ ## Test Tagging Examples
102
92
 
103
- ### Versioning Examples
93
+ ### Basic Test Tagging
94
+ ```javascript
95
+ describe('Login Tests', () => {
96
+ it('should login successfully @TC-AUTO-123 @smoke @p0', () => {
97
+ const env = Cypress.env('TEST_ENVIRONMENT'); // QA, DEV, CTE, PROD
98
+ cy.visit(`https://${env.toLowerCase()}.myapp.com/login`);
99
+ // your test code
100
+ });
101
+
102
+ it('should register new user @TC-AUTO-456 @regression @p1', () => {
103
+ // your test code
104
+ });
105
+ });
106
+ ```
104
107
 
105
- **Using package.json version (Recommended):**
106
- ```json
107
- // package.json
108
- {
109
- "version": "2.1.0"
110
- }
108
+ ### Environment-Specific Testing
109
+ ```javascript
110
+ it('environment-specific test @TC-AUTO-789', () => {
111
+ const env = Cypress.env('TEST_ENVIRONMENT');
112
+
113
+ switch(env) {
114
+ case 'PROD':
115
+ cy.visit('https://app.mycompany.com');
116
+ break;
117
+ case 'CTE':
118
+ cy.visit('https://cte.mycompany.com');
119
+ break;
120
+ default:
121
+ cy.visit(`https://${env.toLowerCase()}.mycompany.com`);
122
+ }
123
+ });
111
124
  ```
125
+
126
+ ### Using Custom E2E Commands
127
+ For projects with custom test runners, set the `E2E_COMMAND` environment variable:
112
128
  ```bash
113
- # Automatically uses package.json version
114
- npx haven-cypress build --product=BE --push
115
- → ECR tag: BE-2.1.0
129
+ # In your Dockerfile or container environment
130
+ ENV E2E_COMMAND="npm run test:e2e:prod"
116
131
  ```
117
132
 
118
- **Manual version override:**
119
- ```bash
120
- # Override with custom semantic version
121
- npx haven-cypress build --product=BE --tag=v3.0.0 --push
122
- → ECR tag: BE-3.0.0
133
+ The integration will export `HAVEN_GREP_INCLUDE` and `HAVEN_GREP_EXCLUDE` for use in your `cypress.config.js`:
134
+ ```javascript
135
+ // cypress.config.js
136
+ const { defineConfig } = require('cypress');
123
137
 
124
- npx haven-cypress build --product=BE --tag=3.0.0 --push
125
- → ECR tag: BE-3.0.0
138
+ module.exports = defineConfig({
139
+ e2e: {
140
+ setupNodeEvents(on, config) {
141
+ // Use HAVEN's grep patterns if available
142
+ if (process.env.HAVEN_GREP_INCLUDE) {
143
+ config.env.grepTags = process.env.HAVEN_GREP_INCLUDE;
144
+ }
145
+ if (process.env.HAVEN_GREP_EXCLUDE) {
146
+ config.env.grepInvert = process.env.HAVEN_GREP_EXCLUDE;
147
+ }
148
+ return config;
149
+ },
150
+ },
151
+ });
126
152
  ```
127
153
 
128
- **Fallback for missing package.json:**
129
- ```bash
130
- # Falls back to build number if no package.json version found
131
- BUILD_NUMBER=456 npx haven-cypress build --product=BE --push
132
- ECR tag: BE-1.0.456
154
+ ## Artifacts and Monitoring
155
+
156
+ ### S3 Artifacts
157
+ - **Live Output**: `s3://{BUCKET}/artifacts/{PRODUCT}/{PLAN_ID}/automation/{RUN_ID}/live-output.log` (updated every 30s)
158
+ - **Final Output**: `s3://{BUCKET}/artifacts/{PRODUCT}/{PLAN_ID}/automation/{RUN_ID}/test-output.log`
159
+ - **Report ZIP**: `s3://{BUCKET}/artifacts/{PRODUCT}/{PLAN_ID}/automation/{RUN_ID}/{PRODUCT}_{TIMESTAMP}.zip`
160
+
161
+ ### Shared Volume (for HAVEN)
162
+ - ZIP: `/shared/test-logs/{PRODUCT}_{TIMESTAMP}.zip`
163
+ - HTML: `/shared/test-logs/report.html`
164
+
165
+ ## Environment Variables
166
+
167
+ ### Required (provided by HAVEN)
168
+ - `PLAN_ID` - Test plan identifier
169
+ - `RUN_ID` - Test run identifier
170
+ - `PRODUCT_NAME` - Product name for artifact organization
171
+ - `BUCKET_NAME` - S3 bucket for artifact uploads
172
+
173
+ ### Optional
174
+ - `TEST_ENVIRONMENT` - Target environment (QA/DEV/CTE/PROD, default: QA)
175
+ - `E2E_COMMAND` - Custom test execution command (default: `npx cypress run ...`)
176
+ - `HAVEN_GREP_PATTERN` - Grep pattern from Haven (parsed into include/exclude)
177
+
178
+ ### Available to Tests
179
+ - `TEST_ENVIRONMENT` - Accessible in your test code via `Cypress.env('TEST_ENVIRONMENT')`
180
+ - `HAVEN_GREP_INCLUDE` - Exported grep pattern for custom configs
181
+ - `HAVEN_GREP_EXCLUDE` - Exported grep pattern for excluding tests (NOT: prefix)
182
+
183
+ ## ECR Image Management
184
+
185
+ Images are automatically tagged and organized by product and build type:
186
+
187
+ ### Tag Format
188
+ - **Full Image**: `{PRODUCT}-{VERSION}` (e.g., `BE-1.1.0`)
189
+ - **Thin Image**: `{PRODUCT}-thin-{VERSION}` (e.g., `BE-thin-1.1.0`)
190
+
191
+ ### Repository
192
+ - **Repository**: `haven-test-images`
193
+ - **Examples**:
194
+ - `BE-1.1.0` (full image from package.json version)
195
+ - `BE-thin-1.1.0` (thin image for ADO cloning)
196
+ - `payments-2.1.0` (custom full image)
197
+ - `payments-thin-2.1.0` (custom thin image)
198
+
199
+ ### Usage in HAVEN
200
+ ```yaml
201
+ # Use full image (app code included)
202
+ image: haven-test-images:BE-1.1.0
203
+
204
+ # Use thin image (requires ADO_REPO, ADO_PAT env vars)
205
+ image: haven-test-images:BE-thin-1.1.0
206
+ environment:
207
+ ADO_REPO: "dev.azure.com/myorg/myproject/_git/myrepo"
208
+ ADO_PAT: "${ADO_PAT_SECRET}"
209
+ ADO_BRANCH: "main"
133
210
  ```
134
211
 
135
- ## What's Included
212
+ ## Requirements
136
213
 
137
- - **Tag-based test filtering** (`@TC-AUTO-XXXX`)
138
- - **Product-based organization** (ECR repository management)
139
- - **Automatic mochawesome configuration** (no manual setup required)
140
- - **Mochawesome reporting** with screenshots
141
- - **S3 artifact upload** (reports, logs, screenshots)
142
- - ✅ **HAVEN API integration** (result synchronization)
143
- - ✅ **ECR integration** (automatic push to haven-test-images repository)
144
- - ✅ **Docker containerization** ready for HAVEN deployment
214
+ - Node.js 16+
215
+ - Podman or Docker
216
+ - AWS CLI configured (for ECR push)
217
+ - HAVEN access credentials (provided when container runs)
218
+ - `@cypress/grep` plugin configured in your Cypress project
145
219
 
146
- ## How It Works
220
+ ## Cypress Project Setup
147
221
 
148
- 1. **Haven runs your container** with mounted configuration and environment variables
149
- 2. **Your tests run** with tag filtering based on automation IDs
150
- 3. **Results are generated** using Mochawesome reporting
151
- 4. **Artifacts are uploaded** to S3 for review
152
- 5. **Results sync back** to HAVEN via API integration
222
+ Ensure your Cypress project has the `@cypress/grep` plugin configured:
153
223
 
154
- ## Requirements
224
+ ```bash
225
+ npm install @cypress/grep --save-dev
226
+ ```
155
227
 
156
- - Node.js 14+
157
- - Docker or Podman
158
- - Existing Cypress project
159
- - AWS credentials configured (for ECR push)
160
- - HAVEN access credentials (provided by Haven when container runs)
228
+ ```javascript
229
+ // cypress/support/e2e.js
230
+ import registerCypressGrep from '@cypress/grep';
231
+ registerCypressGrep();
232
+ ```
233
+
234
+ ```javascript
235
+ // cypress.config.js
236
+ const { defineConfig } = require('cypress');
161
237
 
162
- ## Support
238
+ module.exports = defineConfig({
239
+ e2e: {
240
+ setupNodeEvents(on, config) {
241
+ require('@cypress/grep/src/plugin')(config);
242
+ return config;
243
+ },
244
+ },
245
+ });
246
+ ```
163
247
 
164
- For issues or questions, contact your HAVEN administrator.
248
+ ## Latest Updates
249
+
250
+ ### v2.0.0
251
+ - Added thin/full image support (matching Playwright integration)
252
+ - Added ADO clone mode for thin images
253
+ - Added `HAVEN_GREP_PATTERN` support with include/exclude patterns
254
+ - Added `NOT:` prefix support for excluding tests
255
+ - Added real-time log streaming to S3
256
+ - Added custom E2E command support via `E2E_COMMAND`
257
+ - Added `--platform linux/amd64` for ARM/M1 compatibility
258
+ - Added `--force-compression` for ECR push reliability
259
+ - Added stale ECR credential clearing
260
+ - Removed all emojis from console output
261
+ - Removed axios/glob dependencies (using native Node.js modules)
262
+ - Haven scripts now in `/haven/` directory (isolated from app code)
263
+
264
+ ## Notes
265
+ - Works with existing HAVEN runner; no changes required
266
+ - Container base image: `cypress/included:14.3.1`
267
+ - Supports both default Cypress execution and custom E2E commands
268
+ - Real-time monitoring via S3 log streaming during test execution
@@ -1,77 +1,64 @@
1
1
  #!/usr/bin/env node
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const { spawnSync } = require('child_process');
5
+ const lib = require('..');
2
6
 
3
- const HavenCypressIntegration = require('../index.js');
4
-
5
- const args = process.argv.slice(2);
6
- const command = args[0];
7
+ function parseArgs() {
8
+ const args = process.argv.slice(2);
9
+ const cmd = args[0] || 'build';
10
+ const opts = { tag: 'haven-cypress-tests:latest', push: false, product: null, automationIds: '', customTags: '', type: 'thin' };
11
+ for (const a of args.slice(1)) {
12
+ if (a.startsWith('--tag=')) opts.tag = a.split('=')[1];
13
+ if (a === '--push') opts.push = true;
14
+ if (a.startsWith('--product=')) opts.product = a.split('=')[1];
15
+ if (a.startsWith('--automationIds=')) opts.automationIds = a.split('=')[1];
16
+ if (a.startsWith('--customTags=')) opts.customTags = a.split('=')[1];
17
+ if (a.startsWith('--type=')) opts.type = a.split('=')[1];
18
+ }
19
+ return { cmd, opts };
20
+ }
7
21
 
8
- if (!command) {
9
- console.log(`
10
- Haven-Cypress Integration
22
+ function printHelp() {
23
+ console.log(`HAVEN Cypress Integration
11
24
 
12
- Usage: npx haven-cypress <command> [options]
25
+ Usage:
26
+ npx haven-cypress build [--product=BE] [--tag=1.2.3] [--type=full|thin] [--push]
27
+ npx haven-cypress run --automationIds=TC-AUTO-1,TC-AUTO-2
28
+ npx haven-cypress run --customTags=smoke,p1
13
29
 
14
- Commands:
15
- build [options] Build Docker image with Haven integration
16
- run [options] Run tests with Haven integration
30
+ Build Types:
31
+ --type=thin Thin image for runtime ADO cloning (default)
32
+ --type=full Full image with app code baked in
17
33
 
18
34
  Options:
19
- --tag=name:version Docker image tag (default: haven-cypress-tests:latest)
20
- --product=name Product name for ECR organization (required for --push)
21
- --push Push image to ECR haven-test-images repository
35
+ --tag=name:version or just version Docker image tag (default: haven-cypress-tests:latest)
36
+ --product=name Product name for ECR tagging (recommended)
37
+ --push Push image to ECR after building
22
38
  --automationIds=ID1,ID2 Run specific test cases by automation ID
23
39
  --customTags=tag1,tag2 Run tests with custom tags (smoke, regression, p1, etc.)
24
40
 
25
41
  Examples:
26
- npx haven-cypress build --product=BE
42
+ # Build thin image (default - for ADO runtime cloning)
27
43
  npx haven-cypress build --product=BE --push
28
- npx haven-cypress build --product=BE --tag=v2.1.0 --push
29
- npx haven-cypress run --automationIds=TC-AUTO-123,TC-AUTO-124
30
- npx haven-cypress run --customTags=smoke,p1
31
- npx haven-cypress run --automationIds=TC-AUTO-123 --customTags=smoke
32
44
 
33
- Versioning:
34
- --tag=latest → ECR tag: BE-{package.json.version} or BE-1.0.{BUILD_NUMBER}
35
- --tag=v2.1.0 → ECR tag: BE-2.1.0
36
- --tag=2.1.0 → ECR tag: BE-2.1.0
37
-
38
- Version Priority:
39
- 1. Custom --tag (if provided)
40
- 2. package.json version (for --tag=latest)
41
- 3. BUILD_NUMBER fallback (if package.json not found)
45
+ # Build full image (app code included)
46
+ npx haven-cypress build --product=BE --type=full --push
42
47
  `);
43
- process.exit(1);
44
48
  }
45
49
 
46
- const integration = new HavenCypressIntegration();
50
+ (async () => {
51
+ const { cmd, opts } = parseArgs();
52
+ if (!['build', 'run', 'help', '-h', '--help'].includes(cmd)) return printHelp();
53
+ if (cmd === 'help' || cmd === '-h' || cmd === '--help') return printHelp();
47
54
 
48
- // Parse options
49
- const options = {};
50
- args.slice(1).forEach(arg => {
51
- if (arg.startsWith('--')) {
52
- const [key, value] = arg.substring(2).split('=');
53
- options[key] = value || true;
54
- }
55
- });
55
+ if (cmd === 'build') {
56
+ await lib.buildImage(opts.tag, { product: opts.product, push: opts.push, type: opts.type });
57
+ return;
58
+ }
56
59
 
57
- try {
58
- switch (command) {
59
- case 'build':
60
- const tag = options.tag || 'haven-cypress-tests:latest';
61
- integration.buildImage(tag, options);
62
- break;
63
-
64
- case 'run':
65
- const automationIds = options.automationIds || '';
66
- const customTags = options.customTags || '';
67
- integration.runTests(automationIds, customTags);
68
- break;
69
-
70
- default:
71
- console.error(`❌ Unknown command: ${command}`);
72
- process.exit(1);
73
- }
74
- } catch (error) {
75
- console.error(`❌ Error: ${error.message}`);
76
- process.exit(1);
77
- }
60
+ if (cmd === 'run') {
61
+ await lib.runTests(opts.automationIds, opts.customTags);
62
+ return;
63
+ }
64
+ })();