Skip to content

Commit b220729

Browse files
committed
fix(cypress): enhance logging in media library tests and utility functions for better traceability
1 parent 08cde46 commit b220729

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

cypress/e2e/common/media_library.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,22 @@ function assertGridEntryImage(entry) {
102102

103103
export default function({ entries, getUser }) {
104104
beforeEach(() => {
105-
login(getUser && getUser());
105+
console.log('[media_library.beforeEach] START');
106+
const user = getUser && getUser();
107+
console.log('[media_library.beforeEach] user=', user ? JSON.stringify(user) : 'none');
108+
login(user);
109+
console.log('[media_library.beforeEach] login() returned');
106110
});
107111

108112
it('can upload image from global media library', () => {
113+
console.log('[TEST] can upload image from global media library - START');
109114
goToMediaLibrary();
115+
console.log('[TEST] goToMediaLibrary() completed');
110116
uploadMediaFile();
117+
console.log('[TEST] uploadMediaFile() completed');
111118
matchImageSnapshot();
112119
closeMediaLibrary();
120+
console.log('[TEST] can upload image from global media library - END');
113121
});
114122

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

cypress/e2e/common/spec_utils.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,60 @@
11
export function before(taskResult, options, backend) {
2+
console.log(`[spec_utils.before] START backend=${backend}`);
23
Cypress.config('taskTimeout', 5 * 60 * 1000); // 5 minutes
34
cy.task('setupBackend', { backend, options }).then(data => {
5+
console.log('[spec_utils.before] setupBackend completed, data=', data);
46
taskResult.data = data;
57
Cypress.config('defaultCommandTimeout', data.mockResponses ? 5 * 1000 : 1 * 60 * 1000);
8+
console.log(`[spec_utils.before] COMPLETE mockResponses=${data.mockResponses} timeout=${data.mockResponses ? 5000 : 60000}ms`);
69
});
710
}
811

912
export function after(taskResult, backend) {
13+
console.log(`[spec_utils.after] START backend=${backend}`);
1014
cy.task('teardownBackend', {
1115
backend,
1216
...taskResult.data,
17+
}).then(() => {
18+
console.log('[spec_utils.after] COMPLETE');
1319
});
1420
}
1521

1622
export function beforeEach(taskResult, backend) {
1723
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
1824
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
1925

26+
console.log(`[spec_utils.beforeEach] START backend=${backend} spec="${spec}" test="${testName}"`);
27+
console.log(`[spec_utils.beforeEach] mockResponses=${taskResult.data.mockResponses}`);
28+
console.log(`[spec_utils.beforeEach] user=`, JSON.stringify(taskResult.data.user || {}));
29+
2030
cy.task('setupBackendTest', {
2131
backend,
2232
...taskResult.data,
2333
spec,
2434
testName,
35+
}).then(() => {
36+
console.log('[spec_utils.beforeEach] setupBackendTest completed');
2537
});
2638

2739
if (taskResult.data.mockResponses) {
2840
const fixture = `${spec}__${testName}.json`;
29-
console.log('loading fixture:', fixture);
30-
cy.stubFetch({ fixture });
41+
console.log(`[spec_utils.beforeEach] Loading fixture: ${fixture}`);
42+
cy.stubFetch({ fixture }).then(() => {
43+
console.log('[spec_utils.beforeEach] stubFetch completed');
44+
});
45+
} else {
46+
console.log('[spec_utils.beforeEach] WARNING: mockResponses is false/undefined - no fixture loaded');
3147
}
3248

3349
// cy.clock(0, ['Date']) was hanging git-gateway tests after page load
3450
// Hypothesis: freezing time to 0 breaks app initialization during cy.visit()
3551
// Temporary fix: skip cy.clock for git-gateway, use default clock for others
3652
if (backend !== 'git-gateway') {
53+
console.log('[spec_utils.beforeEach] Setting clock to epoch 0');
3754
return cy.clock(0, ['Date']);
3855
}
56+
57+
console.log('[spec_utils.beforeEach] COMPLETE - skipped clock for git-gateway');
3958
}
4059

4160
export function afterEach(taskResult, backend) {

cypress/e2e/media_library_spec_git-gateway_gitlab_backend_large_media.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,33 @@ const backend = 'git-gateway';
66
const provider = 'gitlab';
77

88
describe('Git Gateway (GitLab) Backend Media Library - Large Media', () => {
9-
let taskResult = { data: {} };
9+
const taskResult = { data: {} };
1010

1111
before(() => {
12+
console.log('[SPEC before] START');
1213
specUtils.before(taskResult, { publish_mode: 'editorial_workflow', provider }, backend);
14+
console.log('[SPEC before] COMPLETE, taskResult.data=', taskResult.data);
1315
});
1416

1517
after(() => {
18+
console.log('[SPEC after] START');
1619
specUtils.after(taskResult, backend);
20+
console.log('[SPEC after] COMPLETE');
1721
});
1822

1923
beforeEach(() => {
24+
console.log('[SPEC beforeEach] START, taskResult.data=', taskResult.data);
2025
specUtils.beforeEach(taskResult, backend);
26+
console.log('[SPEC beforeEach] COMPLETE');
2127
});
2228

2329
afterEach(() => {
30+
console.log('[SPEC afterEach] START');
2431
specUtils.afterEach(taskResult, backend);
32+
console.log('[SPEC afterEach] COMPLETE');
2533
});
2634

35+
console.log('[SPEC] About to call fixture()');
2736
fixture({ entries: [entry1], getUser: () => taskResult.data.user });
37+
console.log('[SPEC] fixture() returned');
2838
});

cypress/utils/steps.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ const {
99
} = require('./constants');
1010

1111
function login(user) {
12+
console.log('[login] START user=', user ? 'yes' : 'no', 'netlifySiteURL=', user?.netlifySiteURL || 'none');
1213
cy.viewport(1200, 1200);
1314
if (user) {
15+
console.log('[login] About to cy.visit("/")');
1416
cy.visit('/', {
1517
onBeforeLoad: () => {
1618
// https://github.com/cypress-io/cypress/issues/1208
@@ -19,20 +21,28 @@ function login(user) {
1921
if (user.netlifySiteURL) {
2022
window.localStorage.setItem('netlifySiteURL', user.netlifySiteURL);
2123
}
24+
console.log('[login] onBeforeLoad complete');
2225
},
26+
}).then(() => {
27+
console.log('[login] cy.visit completed');
2328
});
2429
if (user.netlifySiteURL && user.email && user.password) {
30+
console.log('[login] Filling login form');
2531
cy.get('input[name="email"]', { timeout: 10000 }).clear();
2632
cy.get('input[name="email"]').type(user.email);
2733
cy.get('input[name="password"]').clear();
2834
cy.get('input[name="password"]').type(user.password);
2935
cy.contains('button', 'Login').click();
36+
console.log('[login] Login button clicked');
3037
}
3138
} else {
3239
cy.visit('/');
3340
cy.contains('button', 'Login').click();
3441
}
35-
cy.contains('a', 'New Post');
42+
console.log('[login] Waiting for New Post link');
43+
cy.contains('a', 'New Post', { timeout: 60000 }).then(() => {
44+
console.log('[login] New Post link found - COMPLETE');
45+
});
3646
}
3747

3848
function assertNotification(message) {

0 commit comments

Comments
 (0)