Skip to content

Commit 312cb8d

Browse files
Improve Cypress teardown (#7745)
* fix(cypress): adjust task timeout and enhance logging for teardown process * Apply suggestion from @yanthomasdev Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com> * fix(cypress): enhance logging and improve API request timeouts in gitGateway and setup tasks * fix(cypress): enhance logging for media upload and test setup processes * fix(cypress): adjust timeout settings and refine clock handling in tests * fix(cypress): remove unnecessary logging from uploadMediaFile and beforeEach hooks * fix(cypress): remove unnecessary logging, fix format in media library and spec utils * fix(cypress): refactor API request handling and enhance logging in teardown processes * fix(cypress): streamline API calls by combining fetch functions * fix(cypress): increase retry delay in waitForDeploys function and improve error message * fix(cypress): optimize element selection by using aliases * fix(cypress): enhance logging for better traceability during tests and setup * fix(cypress): enhance logging in test lifecycle hooks and improve error handling * fix(cypress): improve logging during media file upload and enhance error handling in afterEach * fix(cypress): streamline logging in media library and login functions for improved clarity * fix(cypress): reduce logging in beforeEach and remove unnecessary log tasks * fix(gitGateway): make fetchWithTimeout handle full URLs, remove wrapper functions * fix(cypress): enhance logging in media library tests and utility functions for better traceability --------- Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
1 parent d2a5726 commit 312cb8d

File tree

9 files changed

+179
-134
lines changed

9 files changed

+179
-134
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
env:
9595
CI_BUILD_ID: ${{ github.run_id }}-${{ github.run_attempt }}
9696
IS_FORK: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true || github.repository_owner != 'decaporg' }}
97+
# Only used for fork PRs (can't access CYPRESS_RECORD_KEY)
9798
MACHINE_INDEX: ${{ matrix.machine }}
9899
MACHINE_COUNT: 4
99100
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}

cypress.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { defineConfig } from 'cypress';
33
export default defineConfig({
44
projectId: '1c35bs',
55
retries: {
6-
runMode: 2, // Reduced from 4 - Cypress Cloud helps identify flaky tests
6+
runMode: 2,
77
openMode: 0,
88
},
99
e2e: {
1010
video: false,
11-
// We've imported your old cypress plugins here.
12-
// You may want to clean this up later by importing these.
1311
setupNodeEvents(on, config) {
1412
// eslint-disable-next-line @typescript-eslint/no-var-requires
1513
return require('./cypress/plugins/index.js')(on, config);

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: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
1-
export const before = (taskResult, options, backend) => {
2-
Cypress.config('taskTimeout', 7 * 60 * 1000);
1+
export function before(taskResult, options, backend) {
2+
console.log(`[spec_utils.before] START backend=${backend}`);
3+
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
});
7-
};
10+
}
811

9-
export const after = (taskResult, backend) => {
12+
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
});
14-
};
20+
}
1521

16-
export const beforeEach = (taskResult, backend) => {
22+
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;
25+
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+
1930
cy.task('setupBackendTest', {
2031
backend,
2132
...taskResult.data,
2233
spec,
2334
testName,
35+
}).then(() => {
36+
console.log('[spec_utils.beforeEach] setupBackendTest completed');
2437
});
2538

2639
if (taskResult.data.mockResponses) {
2740
const fixture = `${spec}__${testName}.json`;
28-
console.log('loading fixture:', fixture);
29-
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');
3047
}
3148

32-
return cy.clock(0, ['Date']);
33-
};
49+
// cy.clock(0, ['Date']) was hanging git-gateway tests after page load
50+
// Hypothesis: freezing time to 0 breaks app initialization during cy.visit()
51+
// Temporary fix: skip cy.clock for git-gateway, use default clock for others
52+
if (backend !== 'git-gateway') {
53+
console.log('[spec_utils.beforeEach] Setting clock to epoch 0');
54+
return cy.clock(0, ['Date']);
55+
}
3456

35-
export const afterEach = (taskResult, backend) => {
57+
console.log('[spec_utils.beforeEach] COMPLETE - skipped clock for git-gateway');
58+
}
59+
60+
export function afterEach(taskResult, backend) {
3661
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
3762
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
3863

@@ -51,15 +76,16 @@ export const afterEach = (taskResult, backend) => {
5176
},
5277
},
5378
} = Cypress.mocha.getRunner();
79+
5480
if (state === 'failed' && retries === currentRetry) {
5581
Cypress.runner.stop();
5682
}
5783
}
58-
};
84+
}
5985

60-
export const seedRepo = (taskResult, backend) => {
86+
export function seedRepo(taskResult, backend) {
6187
cy.task('seedRepo', {
6288
backend,
6389
...taskResult.data,
6490
});
65-
};
91+
}

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
});

0 commit comments

Comments
 (0)