Skip to content

Commit b3cfd0d

Browse files
committed
feat(cypress): improve cache optimization logging and reporting
- Add detailed cache statistics when all files are cached - Improve Test Setup Validation messaging for cache scenarios - Provide clearer information about why no validation is needed - Address user concern about lack of helpful debugging information - Enhance visibility into cache hit rates and file processing
1 parent d86f0de commit b3cfd0d

File tree

1 file changed

+88
-71
lines changed

1 file changed

+88
-71
lines changed

cypress/e2e/content/article-links.cy.js

Lines changed: 88 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -32,74 +32,80 @@ describe('Article', () => {
3232
}
3333
}
3434

35-
// Run incremental validation analysis with source file paths
36-
cy.task('runIncrementalValidation', sourceFilePaths)
37-
.then((results) => {
38-
validationStrategy = results.validationStrategy;
39-
40-
// Save cache statistics and validation strategy for reporting
41-
cy.task('saveCacheStatistics', results.cacheStats);
42-
cy.task('saveValidationStrategy', validationStrategy);
43-
44-
// Update subjects to only test files that need validation
45-
if (results.filesToValidate.length > 0) {
46-
// Convert file paths to URLs using shared utility via Cypress task
47-
const urlPromises = results.filesToValidate.map((file) =>
48-
cy.task('filePathToUrl', file.filePath)
49-
);
35+
// Only run incremental validation if we have source file paths
36+
if (sourceFilePaths.length > 0) {
37+
cy.log('🔄 Running incremental validation analysis...');
38+
39+
// Run incremental validation with proper error handling
40+
cy.task('runIncrementalValidation', sourceFilePaths)
41+
.then((results) => {
42+
validationStrategy = results.validationStrategy;
43+
44+
// Save cache statistics and validation strategy for reporting
45+
cy.task('saveCacheStatistics', results.cacheStats);
46+
cy.task('saveValidationStrategy', validationStrategy);
47+
48+
// Update subjects to only test files that need validation
49+
if (results.filesToValidate.length > 0) {
50+
// Convert file paths to URLs using shared utility via Cypress task
51+
const urlPromises = results.filesToValidate.map((file) =>
52+
cy.task('filePathToUrl', file.filePath)
53+
);
5054

51-
cy.wrap(Promise.all(urlPromises)).then((urls) => {
52-
subjects = urls;
55+
cy.wrap(Promise.all(urlPromises)).then((urls) => {
56+
subjects = urls;
5357

58+
cy.log(
59+
`📊 Cache Analysis: ${results.cacheStats.hitRate}% hit rate`
60+
);
61+
cy.log(
62+
`🔄 Testing ${subjects.length} pages (${results.cacheStats.cacheHits} cached)`
63+
);
64+
});
65+
} else {
66+
// All files are cached, no validation needed
67+
subjects = [];
68+
cy.log('✨ All files cached - skipping validation');
5469
cy.log(
55-
`📊 Cache Analysis: ${results.cacheStats.hitRate}% hit rate`
56-
);
57-
cy.log(
58-
`🔄 Testing ${subjects.length} pages (${results.cacheStats.cacheHits} cached)`
70+
`📊 Cache hit rate: ${results.cacheStats.hitRate}% (${results.cacheStats.cacheHits}/${results.cacheStats.totalFiles} files cached)`
5971
);
60-
});
61-
} else {
62-
// All files are cached, no validation needed
63-
subjects = [];
64-
cy.log('✨ All files cached - skipping validation');
65-
}
66-
})
67-
.catch((error) => {
68-
cy.log('❌ Error during incremental validation task: ' + error.message);
69-
70-
// Provide more debugging information for validation failures
71-
cy.log('🔍 Validation Error Details:');
72-
cy.log(` • Error Type: ${error.name || 'Unknown'}`);
73-
cy.log(` • Error Message: ${error.message}`);
74-
if (error.stack) {
75-
const stackLines = error.stack.split('\n').slice(0, 3);
76-
cy.log(` • Stack Trace: ${stackLines.join(' -> ')}`);
77-
}
78-
cy.log(
79-
'💡 This error occurred during cache analysis or file validation setup'
80-
);
81-
cy.log(' Check that all files exist and are readable');
82-
83-
// Instead of failing completely, fall back to testing all provided subjects
84-
cy.log(
85-
'🔄 Falling back to test all provided subjects without cache optimization'
86-
);
72+
}
73+
})
74+
.catch((error) => {
75+
cy.log('❌ Incremental validation failed: ' + error.message);
76+
cy.log(
77+
'🔄 Falling back to test all provided subjects without cache optimization'
78+
);
8779

88-
// Reset validation strategy to indicate fallback mode
89-
validationStrategy = {
90-
fallback: true,
91-
error: error.message,
92-
unchanged: [],
93-
changed: sourceFilePaths.map((filePath) => ({
94-
filePath,
95-
error: 'fallback',
96-
})),
97-
total: sourceFilePaths.length,
98-
};
99-
100-
// Keep original subjects for testing (should come from test_subjects env var)
101-
cy.log(`📋 Testing ${subjects.length} pages in fallback mode`);
102-
});
80+
// Set fallback mode but don't fail the test
81+
validationStrategy = {
82+
fallback: true,
83+
error: error.message,
84+
unchanged: [],
85+
changed: sourceFilePaths.map((filePath) => ({
86+
filePath,
87+
error: 'fallback',
88+
})),
89+
total: sourceFilePaths.length,
90+
};
91+
92+
cy.log(`📋 Testing ${subjects.length} pages in fallback mode`);
93+
});
94+
} else {
95+
cy.log('⚠️ No source file paths available, using all provided subjects');
96+
97+
// Set a simple validation strategy when no source data is available
98+
validationStrategy = {
99+
noSourceData: true,
100+
unchanged: [],
101+
changed: [],
102+
total: subjects.length,
103+
};
104+
105+
cy.log(
106+
`📋 Testing ${subjects.length} pages without incremental validation`
107+
);
108+
}
103109
});
104110

105111
// Helper function to identify download links
@@ -230,23 +236,34 @@ describe('Article', () => {
230236
cy.log(`✅ Testing ${subjects.length} subjects in fallback mode`);
231237
}
232238
} else if (subjects.length === 0) {
233-
cy.log('⚠️ No test subjects found - analyzing cause:');
234-
cy.log(' • All files were cached and skipped');
235-
cy.log(' • No files matched the test criteria');
236-
cy.log(' • File mapping failed during setup');
239+
cy.log('ℹ️ No test subjects to validate - analyzing reason:');
237240

238-
// Don't fail if this is expected (cache hit scenario)
241+
// Check if this is due to cache optimization
239242
const testSubjectsData = Cypress.env('test_subjects_data');
240243
if (
241244
testSubjectsData &&
242245
testSubjectsData !== '[]' &&
243246
testSubjectsData !== ''
244247
) {
245-
cy.log('✅ Cache optimization active - this is expected');
246-
cy.log('ℹ️ Test subjects data is available, all files cached');
248+
cy.log('✅ Cache optimization is active - all files were cached');
249+
try {
250+
const urlToSourceData = JSON.parse(testSubjectsData);
251+
cy.log(`📊 Files processed: ${urlToSourceData.length}`);
252+
cy.log(
253+
'💡 This means all links have been validated recently and are cached'
254+
);
255+
cy.log('🎯 No new validation needed - this is the expected outcome');
256+
} catch (e) {
257+
cy.log(
258+
'✅ Cache optimization active (could not parse detailed data)'
259+
);
260+
}
247261
} else {
248262
cy.log('⚠️ No test subjects data available');
249-
cy.log(' This may indicate no files were provided to test');
263+
cy.log(' Possible reasons:');
264+
cy.log(' • No files were provided to test');
265+
cy.log(' • File mapping failed during setup');
266+
cy.log(' • No files matched the test criteria');
250267
cy.log(
251268
' This is not necessarily an error - may be expected for some runs'
252269
);

0 commit comments

Comments
 (0)