@jahia/cypress 5.2.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.
- package/dist/support/index.d.ts +2 -0
- package/dist/support/index.js +2 -0
- package/dist/support/jsErrorsLogger.d.ts +45 -0
- package/dist/support/jsErrorsLogger.js +280 -0
- package/dist/support/provisioning/executeGroovy.js +2 -1
- package/dist/support/provisioning/index.d.ts +2 -2
- package/dist/support/provisioning/index.js +2 -2
- package/dist/support/provisioning/installModule.d.ts +11 -0
- package/dist/support/provisioning/installModule.js +25 -0
- package/dist/support/provisioning/runProvisioningScript.js +8 -0
- package/dist/support/provisioning/{uninstallBundle.d.ts → uninstallModule.d.ts} +2 -2
- package/dist/support/provisioning/{uninstallBundle.js → uninstallModule.js} +4 -4
- package/dist/support/registerSupport.js +11 -1
- package/dist/support/testStep.d.ts +27 -0
- package/dist/support/testStep.js +15 -0
- package/dist/utils/Logger.d.ts +54 -0
- package/dist/utils/Logger.js +105 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/docs/extended-logger.md +403 -0
- package/docs/js-errors-logger.md +152 -0
- package/package.json +1 -1
- package/src/support/index.ts +2 -0
- package/src/support/jsErrorsLogger.ts +281 -0
- package/src/support/provisioning/executeGroovy.ts +2 -1
- package/src/support/provisioning/index.ts +2 -2
- package/src/support/provisioning/installModule.ts +34 -0
- package/src/support/provisioning/runProvisioningScript.ts +9 -0
- package/src/support/provisioning/{uninstallBundle.ts → uninstallModule.ts} +3 -3
- package/src/support/registerSupport.ts +14 -2
- package/src/support/testStep.ts +41 -0
- package/src/utils/Logger.ts +108 -0
- package/src/utils/index.ts +1 -0
- package/dist/support/provisioning/installBundle.d.ts +0 -9
- package/dist/support/provisioning/installBundle.js +0 -15
- package/src/support/provisioning/installBundle.ts +0 -23
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Helper module to decorate Cypress log messages with different log levels (INFO and DEBUG at the moment).
|
|
4
|
+
* @example
|
|
5
|
+
* // Switch default logging verbosity to DEBUG
|
|
6
|
+
* Log.setVerbosity(Log.LEVELS.DEBUG);
|
|
7
|
+
*
|
|
8
|
+
* Log.info('This is an info message');
|
|
9
|
+
* Log.debug('This is a debug message');
|
|
10
|
+
* Log.json(Log.LEVELS.DEBUG, myJSON);
|
|
11
|
+
* Log.info('My info message').then(() => { ... });
|
|
12
|
+
*
|
|
13
|
+
* @note The log verbosity can be set by calling `Log.setVerbosity(Log.LEVELS.DEBUG)` in the code (default is `INFO`).
|
|
14
|
+
* It tells the logger to log only messages with the given level and above.
|
|
15
|
+
*/
|
|
16
|
+
exports.__esModule = true;
|
|
17
|
+
exports.Log = void 0;
|
|
18
|
+
// ENV variable to store the logging verbosity level
|
|
19
|
+
var envVarLoggingVerbosity = '__LOG_VERBOSITY__';
|
|
20
|
+
/**
|
|
21
|
+
* Logging levels enumerator.
|
|
22
|
+
*/
|
|
23
|
+
var LEVEL;
|
|
24
|
+
(function (LEVEL) {
|
|
25
|
+
LEVEL[LEVEL["DEBUG"] = 0] = "DEBUG";
|
|
26
|
+
LEVEL[LEVEL["INFO"] = 1] = "INFO";
|
|
27
|
+
})(LEVEL || (LEVEL = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Return the current logging verbosity level.
|
|
30
|
+
* @returns {LEVEL} - current logging level set in Cypress environment variable `__LOG_VERBOSITY__`
|
|
31
|
+
* @note be careful with Cypress.env(envVarLoggingVerbosity), since it might return `0` for `DEBUG` level,
|
|
32
|
+
* which is falsy in JavaScript, so we need to check if the variable is undefined.
|
|
33
|
+
*/
|
|
34
|
+
function getVerbosity() {
|
|
35
|
+
return typeof Cypress.env(envVarLoggingVerbosity) === 'undefined' ? LEVEL.INFO : Cypress.env(envVarLoggingVerbosity);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets the logging verbosity level for the logger. Messages with a level lower than the set level will not be logged.
|
|
39
|
+
* @param {LEVEL} level - log level to be set (e.g. 'DEBUG', 'INFO')
|
|
40
|
+
* @return {void}
|
|
41
|
+
*/
|
|
42
|
+
function setVerbosity(level) {
|
|
43
|
+
Cypress.env(envVarLoggingVerbosity, level);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Logs INFO message
|
|
47
|
+
* @param {string} message - log message
|
|
48
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
49
|
+
*/
|
|
50
|
+
function info(message) {
|
|
51
|
+
return _send_(exports.Log.LEVEL.INFO, message);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Logs DEBUG message
|
|
55
|
+
* @param {string} message - log message
|
|
56
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
57
|
+
*/
|
|
58
|
+
function debug(message) {
|
|
59
|
+
return _send_(exports.Log.LEVEL.DEBUG, message);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Logs JSON object with logging level given
|
|
63
|
+
* @param {LEVEL} level - log level (e.g. 'INFO', 'DEBUG')
|
|
64
|
+
* @param {string} text - json object to be logged
|
|
65
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
66
|
+
*/
|
|
67
|
+
function json(level, text) {
|
|
68
|
+
return _send_(level, JSON.stringify(text, null, 2));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Private method to send the log message to Cypress log
|
|
72
|
+
* @param {LEVEL} level - log level (e.g. 'INFO', 'DEBUG')
|
|
73
|
+
* @param {string} message - log message
|
|
74
|
+
* @note The method checks if the log level is enabled before sending the message to Cypress log
|
|
75
|
+
* and uses the Cypress.log method to display the message in the Cypress log
|
|
76
|
+
* @note The method is private and should not be called directly
|
|
77
|
+
* Use the public methods (info, debug, error, warning) to send log messages
|
|
78
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
function _send_(level, message) {
|
|
82
|
+
// Check if the log level is valid
|
|
83
|
+
if (!Object.values(exports.Log.LEVEL).includes(level)) {
|
|
84
|
+
throw new Error("Log level \"" + level + "\" is not supported. Supported levels are: " + exports.Log.LEVEL);
|
|
85
|
+
}
|
|
86
|
+
// Check if the log level is enabled,
|
|
87
|
+
// take into account the log level set in Cypress.env('LOG_LEVEL') and the log level set in the Log.LEVEL variable.
|
|
88
|
+
// If the log level is enabled, send the message to Cypress log.
|
|
89
|
+
if (level >= getVerbosity()) {
|
|
90
|
+
// Send the message to Cypress log
|
|
91
|
+
// use cy.then() to ensure that the log message is sent in the correct order
|
|
92
|
+
// and use cy.wrap() to return the Cypress chainable object
|
|
93
|
+
return cy.then(function () {
|
|
94
|
+
Cypress.log({ displayName: "[ " + exports.Log.LEVEL[level].toUpperCase() + " ]", message: "" + message });
|
|
95
|
+
}).then(cy.wrap);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Export the Log module with methods to log messages and set the logging level
|
|
99
|
+
exports.Log = {
|
|
100
|
+
info: info,
|
|
101
|
+
debug: debug,
|
|
102
|
+
json: json,
|
|
103
|
+
setVerbosity: setVerbosity,
|
|
104
|
+
LEVEL: LEVEL
|
|
105
|
+
};
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -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