Skip to content

Commit 17b2a48

Browse files
committed
fix(cypress): improve logging during media file upload and enhance error handling in afterEach
1 parent c804cbb commit 17b2a48

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

cypress/e2e/common/media_library.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ import {
1414
import { workflowStatus } from '../../utils/constants';
1515

1616
function uploadMediaFile() {
17+
cy.task('log', '[media_library] uploadMediaFile: start');
1718
assertNoImagesInLibrary();
19+
cy.task('log', '[media_library] uploadMediaFile: library empty confirmed');
1820

1921
const fixture = 'cypress/fixtures/media/netlify.png';
2022
cy.get('input[type="file"]').selectFile(fixture, { force: true });
23+
cy.task('log', '[media_library] uploadMediaFile: file selected');
2124
cy.contains('span', 'Uploading...').should('not.exist');
25+
cy.task('log', '[media_library] uploadMediaFile: upload finished');
2226

2327
assertImagesInLibrary();
28+
cy.task('log', '[media_library] uploadMediaFile: image present');
2429
}
2530

2631
function assertImagesInLibrary() {
@@ -102,18 +107,19 @@ function assertGridEntryImage(entry) {
102107

103108
export default function({ entries, getUser }) {
104109
beforeEach(() => {
105-
console.log(`[${new Date().toISOString()}] [media_library beforeEach] Starting, about to call login`);
110+
cy.task('log', '[media_library beforeEach] start login');
106111
login(getUser && getUser());
107-
console.log(`[${new Date().toISOString()}] [media_library beforeEach] login completed`);
112+
cy.task('log', '[media_library beforeEach] login completed');
108113
});
109114

110115
it('can upload image from global media library', () => {
111-
console.log(`[${new Date().toISOString()}] [TEST] Starting: can upload image from global media library`);
116+
cy.task('log', '[TEST] can upload image from global media library: start');
112117
goToMediaLibrary();
118+
cy.task('log', '[TEST] can upload image from global media library: media library opened');
113119
uploadMediaFile();
114120
matchImageSnapshot();
115121
closeMediaLibrary();
116-
console.log(`[${new Date().toISOString()}] [TEST] Completed: can upload image from global media library`);
122+
cy.task('log', '[TEST] can upload image from global media library: end');
117123
});
118124

119125
it('can delete image from global media library', () => {

cypress/support/e2e.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ import './commands';
3333

3434
afterEach(function () {
3535
if (this.currentTest.state === 'failed') {
36-
Cypress.runner.stop();
36+
const titlePath = this.currentTest.titlePath ? this.currentTest.titlePath().join(' > ') : '';
37+
// In headless CI, stopping the runner can leave the Cypress process hanging.
38+
if (Cypress.config('isInteractive')) {
39+
Cypress.runner.stop();
40+
} else {
41+
// eslint-disable-next-line no-console
42+
console.error(`[afterEach] Test failed in CI: ${titlePath || this.currentTest.title}`);
43+
if (this.currentTest.err?.message) {
44+
// eslint-disable-next-line no-console
45+
console.error(`[afterEach] Failure: ${this.currentTest.err.message}`);
46+
}
47+
}
3748
}
3849
});

0 commit comments

Comments
 (0)