@jahia/cypress 6.0.0 → 6.1.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.
@@ -0,0 +1,403 @@
1
+ # Cypress Logger Module
2
+
3
+ ## Overview
4
+
5
+ The Logger module is a helper utility designed to enhance Cypress test logging capabilities by providing structured log levels and decorating log messages with appropriate severity indicators. It enables developers to create more organized and filterable test output by categorizing log messages into different levels.
6
+
7
+ This documentation also covers the testStep custom action, which provides structured test organization through foldable log groups.
8
+
9
+ ## Features
10
+
11
+ - **Multiple Log Levels**: Support for DEBUG and INFO logging levels, can easily be extended if required.
12
+ - **Level-based Filtering**: Configure minimum log level to control output verbosity
13
+ - **JSON Object Logging**: Specialized method for logging JSON objects
14
+ - **Cypress Integration**: Seamless integration with Cypress logging system
15
+ - **Chainable Interface**: Returns Cypress chainable objects for fluent test writing
16
+ - **Environment Variable Control**: Persistent log level configuration across test runs
17
+ - **Test Step Organization**: Foldable test steps for better test structure and readability.
18
+
19
+ ## Log Levels and Test Steps
20
+
21
+ The module supports two distinct logging levels with hierarchical filtering:
22
+
23
+ ### Log.debug()
24
+ - **Purpose**: Detailed diagnostic information for debugging and development
25
+ - **Visibility**: Only shown when log level is set to DEBUG
26
+ - **Use Case**: Verbose logging for troubleshooting complex test scenarios
27
+
28
+ ### Log.info()
29
+ - **Purpose**: General informational messages about test execution
30
+ - **Visibility**: Shown when log level is set to INFO or DEBUG
31
+ - **Use Case**: Standard test progress and status information
32
+
33
+ ### cy.step()
34
+ - **Purpose**: Group related test actions under foldable and self-descriptive step names
35
+ - **Visibility**: Shown always
36
+ - **Use Case**: Organize complex test scenarios and have self-documenting code
37
+
38
+ ## Configuration
39
+
40
+ ### Setting Log Level
41
+
42
+ ```typescript
43
+ import { Log } from '@jahia/cypress';
44
+
45
+ // Set visibility to DEBUG level for verbose output
46
+ Log.setLevel(Log.LEVEL.DEBUG);
47
+
48
+ // Set visibility to INFO level for standard output (default configuration)
49
+ Log.setLevel(Log.LEVEL.INFO);
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ ### Basic Logging
55
+
56
+ ```typescript
57
+ import { Log } from '@jahia/cypress';
58
+
59
+ describe('Test Suite', () => {
60
+ it('should demonstrate logging capabilities', () => {
61
+ // Info level logging (always visible)
62
+ Log.info('Starting test execution');
63
+
64
+ // Debug level logging (only visible when DEBUG level is set)
65
+ Log.debug('Detailed diagnostic information');
66
+
67
+ // Chainable usage
68
+ Log.info('Processing user data')
69
+ .then(() => {
70
+ // Continue with test logic
71
+ cy.visit('/login');
72
+ });
73
+ });
74
+ });
75
+ ```
76
+
77
+ ### JSON Object Logging
78
+
79
+ ```typescript
80
+ import { Log } from '@jahia/cypress';
81
+
82
+ describe('API Tests', () => {
83
+ it('should log API responses', () => {
84
+ cy.request('/api/users').then((response) => {
85
+ // Log response data at DEBUG level
86
+ Log.json(Log.LEVEL.DEBUG, response.body);
87
+
88
+ // Log summary at INFO level
89
+ const summary = { status: response.status, count: response.body.length };
90
+ Log.json(Log.LEVEL.INFO, summary);
91
+ });
92
+ });
93
+ });
94
+ ```
95
+
96
+ ### Test Step Organization
97
+
98
+ The test step action creates foldable, hierarchical log groups to organize complex test scenarios:
99
+
100
+ ```typescript
101
+ describe('User Registration Flow', () => {
102
+ it('should register a new user successfully', () => {
103
+ cy.step('Navigate to registration page', () => {
104
+ cy.visit('/register');
105
+ cy.url().should('include', '/register');
106
+ });
107
+
108
+ cy.step('Fill out registration form', () => {
109
+ cy.get('[data-testid="first-name"]').type('John');
110
+ cy.get('[data-testid="last-name"]').type('Doe');
111
+ cy.get('[data-testid="email"]').type('john.doe@example.com');
112
+ cy.get('[data-testid="password"]').type('SecurePassword123!');
113
+ cy.get('[data-testid="confirm-password"]').type('SecurePassword123!');
114
+ });
115
+
116
+ cy.step('Submit registration and verify success', () => {
117
+ cy.get('[data-testid="register-button"]').click();
118
+ cy.get('[data-testid="success-message"]').should('be.visible');
119
+ cy.url().should('include', '/welcome');
120
+ });
121
+ });
122
+ });
123
+ ```
124
+
125
+ #### Test Step Features
126
+
127
+ - **Hierarchical Organization**: Group related test actions under descriptive step names
128
+ - **Foldable Interface**: Steps can be collapsed/expanded in Cypress Test Runner
129
+ - **Clean Log Output**: Reduces clutter by organizing actions into logical groups
130
+ - **Better Debugging**: Easier to identify which step failed during test execution
131
+ - **Documentation**: Steps serve as living documentation of test flow
132
+
133
+ ## Output Format
134
+
135
+ ### Console Display
136
+
137
+ The logger decorates messages with level indicators in the Cypress runner:
138
+
139
+ ```
140
+ [ INFO ] Starting test execution
141
+ [ DEBUG ] Detailed diagnostic information
142
+ [ INFO ] {
143
+ "status": 200,
144
+ "data": {
145
+ "users": 5
146
+ }
147
+ }
148
+ ```
149
+
150
+ ### Level Filtering Behavior
151
+
152
+ | Set Level | INFO Messages | DEBUG Messages |
153
+ |-----------|---------------|----------------|
154
+ | INFO | ✅ Visible | ❌ Hidden |
155
+ | DEBUG | ✅ Visible | ✅ Visible |
156
+
157
+ ## Best Practices
158
+
159
+ ### Development Environment
160
+ - Use `DEBUG` level during active development for maximum visibility
161
+ - Log detailed state information and intermediate values
162
+ - Include context-rich debug messages for complex operations
163
+
164
+ ```typescript
165
+ // Good: Detailed development logging
166
+ Log.debug('User authentication state: authenticated=true, role=admin');
167
+ Log.debug('Form validation results', validationResults);
168
+ ```
169
+
170
+ ### CI/CD Environment
171
+ - Use `INFO` level for cleaner output in automated environments
172
+ - Focus on test milestones and important status updates
173
+ - Avoid excessive logging that could impact performance
174
+
175
+ ```typescript
176
+ // Good: Concise CI/CD logging
177
+ Log.info('Test suite: User Management - Started');
178
+ Log.info('Authentication tests completed successfully');
179
+ ```
180
+
181
+ ### Test Organization with Steps
182
+ - Use meaningful step descriptions that explain the intent
183
+ - Group related actions within logical steps
184
+ - Keep steps focused on a single responsibility
185
+ - Combine with logging for comprehensive test documentation
186
+
187
+ ```typescript
188
+ // Good: Well-organized test with steps and logging
189
+ describe('E-commerce Checkout', () => {
190
+ it('should complete purchase flow', () => {
191
+ cy.step('Add products to cart', () => {
192
+ Log.info('Starting product selection');
193
+ cy.visit('/products');
194
+ cy.get('[data-testid="product-1"]').click();
195
+ cy.get('[data-testid="add-to-cart"]').click();
196
+ Log.debug('Product added to cart successfully');
197
+ });
198
+
199
+ cy.step('Proceed to checkout', () => {
200
+ Log.info('Initiating checkout process');
201
+ cy.get('[data-testid="cart-icon"]').click();
202
+ cy.get('[data-testid="checkout-button"]').click();
203
+ Log.debug('Navigated to checkout page');
204
+ });
205
+
206
+ cy.step('Complete payment', () => {
207
+ Log.info('Processing payment information');
208
+ // Payment form interactions
209
+ Log.info('Payment completed successfully');
210
+ });
211
+ });
212
+ });
213
+ ```
214
+
215
+ ## Integration Examples
216
+
217
+ ### Page Object Pattern
218
+
219
+ ```typescript
220
+ class LoginPage {
221
+ visit() {
222
+ Log.info('Navigating to login page');
223
+ return cy.visit('/login');
224
+ }
225
+
226
+ login(username: string, password: string) {
227
+ Log.debug(`Attempting login for user: ${username}`);
228
+ cy.get('[data-testid="username"]').type(username);
229
+ cy.get('[data-testid="password"]').type(password);
230
+ cy.get('[data-testid="login-button"]').click();
231
+ Log.info('Login form submitted');
232
+ }
233
+ }
234
+ ```
235
+
236
+ ### Complex Workflows with Nested Steps
237
+
238
+ ```typescript
239
+ describe('Multi-step Workflow', () => {
240
+ it('should handle complex user journey', () => {
241
+ cy.step('User Authentication', () => {
242
+ cy.step('Navigate to login', () => {
243
+ cy.visit('/login');
244
+ Log.debug('Login page loaded');
245
+ });
246
+
247
+ cy.step('Enter credentials', () => {
248
+ cy.get('[data-testid="username"]').type('testuser');
249
+ cy.get('[data-testid="password"]').type('password');
250
+ Log.debug('Credentials entered');
251
+ });
252
+
253
+ cy.step('Submit login form', () => {
254
+ cy.get('[data-testid="login-button"]').click();
255
+ Log.info('User logged in successfully');
256
+ });
257
+ });
258
+
259
+ cy.step('Product Selection', () => {
260
+ // Product selection steps
261
+ Log.info('Product selection completed');
262
+ });
263
+
264
+ cy.step('Checkout Process', () => {
265
+ // Checkout steps
266
+ Log.info('Checkout process completed');
267
+ });
268
+ });
269
+ });
270
+ ```
271
+
272
+ ### Test Hooks
273
+
274
+ ```typescript
275
+ describe('Feature Tests', () => {
276
+ beforeEach(() => {
277
+ cy.step('Test Environment Setup', () => {
278
+ Log.debug('Setting up test environment');
279
+ // Setup code
280
+ });
281
+ });
282
+
283
+ afterEach(() => {
284
+ cy.step('Test Environment Cleanup', () => {
285
+ Log.debug('Cleaning up test environment');
286
+ // Cleanup code
287
+ });
288
+ });
289
+ });
290
+ ```
291
+
292
+ ## Performance Considerations
293
+
294
+ ### Log Level Impact
295
+
296
+ - **DEBUG Level**: Higher overhead due to increased log volume
297
+ - **INFO Level**: Minimal overhead with essential information only
298
+ - **JSON Logging**: Additional serialization overhead for large objects
299
+
300
+ ### Optimization Tips
301
+
302
+ 1. Use appropriate log levels for different environments
303
+ 2. Avoid logging large objects in production environments
304
+ 3. Consider conditional logging for performance-critical tests
305
+ 4. Use test steps judiciously - too many nested steps can impact readability
306
+
307
+ ## API Reference
308
+
309
+ ### Logger Methods
310
+
311
+ | Method | Parameters | Return Type | Description |
312
+ |--------|------------|-------------|-------------|
313
+ | `info(message)` | `string` | `Cypress.Chainable` | Logs INFO level message |
314
+ | `debug(message)` | `string` | `Cypress.Chainable` | Logs DEBUG level message |
315
+ | `json(level, object)` | `LEVEL`, `string` | `Cypress.Chainable` | Logs formatted JSON object |
316
+ | `setVerbosity(level)` | `LEVEL` | `void` | Sets minimum visible log level |
317
+
318
+ ### Test Step Methods
319
+
320
+ | Method | Parameters | Return Type | Description |
321
+ |--------|------------|-------------|-------------|
322
+ | `cy.step(message, func)` | `string`, `() => void` | `void` | Creates foldable test step group |
323
+
324
+ ### Enums
325
+
326
+ | Enum | Values | Description |
327
+ |------|--------|-------------|
328
+ | `LEVEL` | `DEBUG (0)`, `INFO (1)` | Available logging levels |
329
+
330
+ ### TypeScript Declarations
331
+
332
+ The testStep module extends the global Cypress interface:
333
+
334
+ ```typescript
335
+ declare global {
336
+ namespace Cypress {
337
+ interface Chainable<Subject> {
338
+ step(message: string, func: () => void): void;
339
+ }
340
+ }
341
+ }
342
+ ```
343
+
344
+ ## Migration Guide
345
+
346
+ ### From Console Logging
347
+
348
+ **Before:**
349
+ ```typescript
350
+ console.log('Test started');
351
+ console.debug('Detailed information');
352
+ ```
353
+
354
+ **After:**
355
+ ```typescript
356
+ Log.info('Test started');
357
+ Log.debug('Detailed information');
358
+ ```
359
+
360
+ ### From Cypress.log()
361
+
362
+ **Before:**
363
+ ```typescript
364
+ Cypress.log({ message: 'Custom message' });
365
+ ```
366
+
367
+ **After:**
368
+ ```typescript
369
+ Log.info('Custom message');
370
+ ```
371
+
372
+ ### From Unstructured Tests to Steps
373
+
374
+ **Before:**
375
+ ```typescript
376
+ it('should complete user flow', () => {
377
+ cy.visit('/login');
378
+ cy.get('[data-testid="username"]').type('user');
379
+ cy.get('[data-testid="password"]').type('pass');
380
+ cy.get('[data-testid="login-button"]').click();
381
+ cy.visit('/products');
382
+ cy.get('[data-testid="product-1"]').click();
383
+ cy.get('[data-testid="add-to-cart"]').click();
384
+ });
385
+ ```
386
+
387
+ **After:**
388
+ ```typescript
389
+ it('should complete user flow', () => {
390
+ cy.step('Login to application', () => {
391
+ cy.visit('/login');
392
+ cy.get('[data-testid="username"]').type('user');
393
+ cy.get('[data-testid="password"]').type('pass');
394
+ cy.get('[data-testid="login-button"]').click();
395
+ });
396
+
397
+ cy.step('Add product to cart', () => {
398
+ cy.visit('/products');
399
+ cy.get('[data-testid="product-1"]').click();
400
+ cy.get('[data-testid="add-to-cart"]').click();
401
+ });
402
+ });
403
+ ```
@@ -0,0 +1,152 @@
1
+ # JavaScript Errors Logger
2
+
3
+ ## Overview
4
+
5
+ The JavaScript Errors Logger is a comprehensive monitoring and reporting module for JavaScript errors and warnings in Cypress tests. It provides automated detection, collection, and reporting of console errors and warnings that occur during test execution, helping maintain code quality and identify issues early in the development process.
6
+
7
+ ## Features
8
+
9
+ - **Multiple Strategy Support**: Choose from three different error handling strategies
10
+ - **Configurable Warning Filtering**: Define allowed warnings that won't trigger test failures
11
+ - **Automatic Hook Integration**: Seamlessly integrates with Cypress test lifecycle
12
+ - **Detailed Error Reporting**: Comprehensive error messages with test context
13
+
14
+ ## Error Handling Strategies
15
+
16
+ The logger supports three distinct strategies for handling JavaScript errors and warnings:
17
+
18
+ ### 1. Fail Fast (Default)
19
+ - **Strategy**: `STRATEGY.failFast`
20
+ - **Behavior**: Fails immediately when an error or warning is detected
21
+ - **Use Case**: Best for development environments where immediate feedback is crucial
22
+ - **Pros**: Quick identification of issues
23
+ - **Cons**: May stop test execution on first error, preventing discovery of additional issues
24
+
25
+ ### 2. Fail After Each Test
26
+ - **Strategy**: `STRATEGY.failAfterEach`
27
+ - **Behavior**: Collects errors/warnings during test execution and fails at the end of each test
28
+ - **Use Case**: Suitable when you want each test to complete but still get immediate feedback
29
+ - **Pros**: Allows full test execution while providing per-test feedback
30
+ - **Cons**: If errors occur in hooks (beforeEach/afterEach), remaining spec tests will be skipped
31
+
32
+ ### 3. Fail After All Tests
33
+ - **Strategy**: `STRATEGY.failAfterAll`
34
+ - **Behavior**: Collects all errors/warnings and reports them after the entire test suite completes
35
+ - **Use Case**: Ideal for CI/CD environments where you want a complete test run overview
36
+ - **Pros**: Complete test suite execution with comprehensive error reporting
37
+ - **Cons**: Error reporting may be confusing as the last test will be marked as failed, since the errors analysis and reporting is done in after() hook
38
+
39
+ ## Configuration
40
+
41
+ ### Environment Variables
42
+
43
+ | Variable | Type | Description |
44
+ |----------|------|-------------|
45
+ | `JS_LOGGER_DISABLED` | boolean | Disables the logger when set to `true` |
46
+
47
+ ### Programmatic Configuration
48
+
49
+ It is **strongly** recommended to add custom configuration in project's common files, e.g. `tests/cypress/support/e2e.js` to have it applied to all test-cases within the project.
50
+
51
+ ```typescript
52
+ import { jsErrorsLogger } from '@jahia/cypress';
53
+
54
+ // Set preferrable error handling strategy
55
+ jsErrorsLogger.setStrategy(jsErrorsLogger.STRATEGY.failAfterEach);
56
+
57
+ // Define allowed warnings that won't trigger failures
58
+ jsErrorsLogger.setAllowedJsWarnings([
59
+ 'Warning: React Hook',
60
+ 'Warning: componentWillReceiveProps'
61
+ ]);
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ### Basic Setup
67
+
68
+ The logger is automatically initialized when jahia-cypress is imported and registered in the Cypress support files. No manual setup is required for basic functionality.
69
+
70
+ ### Disabling the Logger
71
+
72
+ #### Via Environment Variable
73
+
74
+ ```bash
75
+ # Disable in CI/CD or specific environments
76
+ export JS_LOGGER_DISABLED=true
77
+ ```
78
+
79
+ #### Temporarily in Tests
80
+
81
+ ```typescript
82
+ describe('Tests with disabled JS logger', () => {
83
+ before(() => {
84
+ Cypress.env('JS_LOGGER_DISABLED', true);
85
+ });
86
+
87
+ after(() => {
88
+ Cypress.env('JS_LOGGER_DISABLED', false);
89
+ });
90
+
91
+ it('should run without JS error monitoring', () => {
92
+ // Test implementation
93
+ });
94
+ });
95
+ ```
96
+
97
+ ## Error Reporting Format
98
+
99
+ ### Single Test Error (failFast/failAfterEach)
100
+
101
+ ```
102
+ Error: CONSOLE ERRORS and WARNINGS FOUND:
103
+ - TypeError: Cannot read property 'foo' of undefined
104
+ - Warning: React Hook useEffect has missing dependency
105
+ ```
106
+
107
+ ### Multiple Test Errors (failAfterAll)
108
+
109
+ ```
110
+ Error: CONSOLE ERRORS and WARNINGS FOUND:
111
+
112
+ TEST: should load homepage
113
+ ISSUES:
114
+ - TypeError: Cannot read property 'user' of undefined
115
+ - Warning: componentWillMount is deprecated
116
+
117
+ TEST: should handle form submission
118
+ ISSUES:
119
+ - ReferenceError: handleSubmit is not defined
120
+ ```
121
+
122
+ ## Best Practices
123
+
124
+ ### Development Environment
125
+ - Use `STRATEGY.failFast` for immediate feedback during development
126
+ - Configure comprehensive allowed warnings list for known, acceptable warnings
127
+ - Enable detailed logging for debugging purposes
128
+
129
+ ### CI/CD Environment
130
+ - Use `STRATEGY.failAfterAll` to get complete test coverage
131
+ - Keep allowed warnings list minimal to catch regressions
132
+ - Consider disabling in performance testing environments
133
+
134
+ ### Team Collaboration
135
+ - Maintain a shared allowed warnings configuration
136
+ - Document any permanently allowed warnings with justification
137
+ - Regular review and cleanup of allowed warnings list
138
+
139
+ ## API Reference
140
+
141
+ ### Methods
142
+
143
+ | Method | Parameters | Return Type | Description |
144
+ |--------|------------|-------------|-------------|
145
+ | `setStrategy(strategy)` | STRATEGY enum | void | Sets the error handling strategy |
146
+ | `setAllowedJsWarnings(warnings)` | string[] | void | Configures allowed warning messages |
147
+
148
+ ### Enums
149
+
150
+ | Enum | Values | Description |
151
+ |------|--------|-------------|
152
+ | `STRATEGY` | `failFast`, `failAfterAll`, `failAfterEach` | Error handling strategies |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts --max-warnings=0"
@@ -4,3 +4,4 @@ export * from './login';
4
4
  export * from './logout';
5
5
  export * from './repeatUntil';
6
6
  export * from './testStep';
7
+ export * from './jsErrorsLogger';