Skip to content

Commit 723b1ef

Browse files
committed
fix(cypress): remove unnecessary logging, fix format in media library and spec utils
1 parent 421a590 commit 723b1ef

File tree

5 files changed

+31
-65
lines changed

5 files changed

+31
-65
lines changed

cypress/e2e/common/media_library.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ function publishPostWithImage(entry) {
8383
}
8484

8585
function closeMediaLibrary() {
86-
console.log('❌ Closing media library');
8786
cy.get('button[class*="CloseButton"]').click();
88-
console.log('❌ Media library closed');
8987
}
9088

9189
function switchToGridView() {

cypress/e2e/common/spec_utils.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
export const before = (taskResult, options, backend) => {
1+
export function before(taskResult, options, backend) {
22
Cypress.config('taskTimeout', 5 * 60 * 1000); // 5 minutes
33
cy.task('setupBackend', { backend, options }).then(data => {
44
taskResult.data = data;
55
Cypress.config('defaultCommandTimeout', data.mockResponses ? 5 * 1000 : 1 * 60 * 1000);
66
});
7-
};
7+
}
88

9-
export const after = (taskResult, backend) => {
9+
export function after(taskResult, backend) {
1010
cy.task('teardownBackend', {
1111
backend,
1212
...taskResult.data,
1313
});
14-
};
14+
}
1515

16-
export const beforeEach = (taskResult, backend) => {
16+
export function beforeEach(taskResult, backend) {
1717
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
1818
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
1919

@@ -36,26 +36,17 @@ export const beforeEach = (taskResult, backend) => {
3636
if (backend !== 'git-gateway') {
3737
return cy.clock(0, ['Date']);
3838
}
39-
};
39+
}
4040

41-
export const afterEach = (taskResult, backend) => {
41+
export function afterEach(taskResult, backend) {
4242
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
4343
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
4444

45-
let startTime;
46-
cy.then(() => {
47-
startTime = Date.now();
48-
console.log(`Starting teardown for: ${spec} - ${testName}`);
49-
});
50-
5145
cy.task('teardownBackendTest', {
5246
backend,
5347
...taskResult.data,
5448
spec,
5549
testName,
56-
}).then(() => {
57-
const duration = Date.now() - startTime;
58-
console.log(`Teardown completed in ${duration}ms for: ${spec} - ${testName}`);
5950
});
6051

6152
if (!process.env.RECORD_FIXTURES) {
@@ -70,11 +61,11 @@ export const afterEach = (taskResult, backend) => {
7061
Cypress.runner.stop();
7162
}
7263
}
73-
};
64+
}
7465

75-
export const seedRepo = (taskResult, backend) => {
66+
export function seedRepo(taskResult, backend) {
7667
cy.task('seedRepo', {
7768
backend,
7869
...taskResult.data,
7970
});
80-
};
71+
}

cypress/plugins/index.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ module.exports = async (on, config) => {
4242
// `on` is used to hook into various events Cypress emits
4343
on('task', {
4444
async setupBackend({ backend, options }) {
45-
console.log(`\n⏱️ [${new Date().toISOString()}] Preparing environment for backend ${backend}`);
46-
const setupStart = Date.now();
45+
console.log('Preparing environment for backend', backend);
4746
await copyBackendFiles(backend);
4847

4948
let result = null;
@@ -52,9 +51,7 @@ module.exports = async (on, config) => {
5251
result = await setupGitHub(options);
5352
break;
5453
case 'git-gateway':
55-
console.log(`⏱️ Starting git-gateway setup: ${new Date().toISOString()}`);
5654
result = await setupGitGateway(options);
57-
console.log(`✅ Git-gateway setup completed in ${Date.now() - setupStart}ms`);
5855
break;
5956
case 'gitlab':
6057
result = await setupGitLab(options);
@@ -70,22 +67,17 @@ module.exports = async (on, config) => {
7067
break;
7168
}
7269

73-
console.log(`✅ Backend setup completed in ${Date.now() - setupStart}ms\n`);
7470
return result;
7571
},
7672
async teardownBackend(taskData) {
7773
const { backend } = taskData;
78-
console.log(`\n⏱️ [${new Date().toISOString()}] Tearing down backend ${backend}`);
79-
const teardownStart = Date.now();
8074

8175
switch (backend) {
8276
case 'github':
8377
await teardownGitHub(taskData);
8478
break;
8579
case 'git-gateway':
86-
console.log(`⏱️ Starting git-gateway backend teardown`);
8780
await teardownGitGateway(taskData);
88-
console.log(`✅ Git-gateway backend teardown completed in ${Date.now() - teardownStart}ms`);
8981
break;
9082
case 'gitlab':
9183
await teardownGitLab(taskData);
@@ -101,21 +93,18 @@ module.exports = async (on, config) => {
10193
console.log('Restoring defaults');
10294
await copyBackendFiles('test');
10395

104-
console.log(`✅ Backend teardown completed in ${Date.now() - teardownStart}ms\n`);
10596
return null;
10697
},
10798
async setupBackendTest(taskData) {
10899
const { backend, testName } = taskData;
109-
console.log(`Setting up test: ${testName} (${backend})`);
100+
console.log(`Setting up single test '${testName}' for backend`, backend);
110101

111102
switch (backend) {
112103
case 'github':
113104
await setupGitHubTest(taskData);
114105
break;
115106
case 'git-gateway':
116-
const setupStart = Date.now();
117107
await setupGitGatewayTest(taskData);
118-
console.log(`git-gateway setup took ${Date.now() - setupStart}ms`);
119108
break;
120109
case 'gitlab':
121110
await setupGitLabTest(taskData);
@@ -131,7 +120,9 @@ module.exports = async (on, config) => {
131120
return null;
132121
},
133122
async teardownBackendTest(taskData) {
134-
const { backend } = taskData;
123+
const { backend, testName } = taskData;
124+
125+
console.log(`Tearing down single test '${testName}' for backend`, backend);
135126

136127
switch (backend) {
137128
case 'github':

cypress/run.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function runCypress() {
6060
await execa('cypress', args, {
6161
stdio: 'inherit',
6262
preferLocal: true,
63-
timeout: 10 * 60 * 1000, // 10 minutes
63+
timeout: 15 * 60 * 1000, // 15 minutes
6464
});
6565
}
6666

cypress/utils/steps.js

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const {
1010

1111
function login(user) {
1212
cy.viewport(1200, 1200);
13-
console.log(`[${new Date().toISOString()}] 🔐 login() called with user: ${user?.email || 'null'}`);
1413
if (user) {
15-
console.log(`[${new Date().toISOString()}] 🔐 cy.visit("/") starting`);
1614
cy.visit('/', {
1715
onBeforeLoad: () => {
1816
// https://github.com/cypress-io/cypress/issues/1208
@@ -23,27 +21,18 @@ function login(user) {
2321
}
2422
},
2523
});
26-
console.log(`[${new Date().toISOString()}] 🔐 cy.visit("/") complete`);
2724
if (user.netlifySiteURL && user.email && user.password) {
28-
console.log(`[${new Date().toISOString()}] 🔐 entering credentials`);
29-
cy.get('input[name="email"]')
30-
.clear()
31-
.type(user.email);
32-
cy.get('input[name="password"]')
33-
.clear()
34-
.type(user.password);
25+
cy.get('input[name="email"]').clear();
26+
cy.get('input[name="email"]').type(user.email);
27+
cy.get('input[name="password"]').clear();
28+
cy.get('input[name="password"]').type(user.password);
3529
cy.contains('button', 'Login').click();
36-
console.log(`[${new Date().toISOString()}] 🔐 credentials submitted`);
3730
}
3831
} else {
39-
console.log(`[${new Date().toISOString()}] 🔐 cy.visit("/") starting (no user)`);
4032
cy.visit('/');
41-
console.log(`[${new Date().toISOString()}] 🔐 cy.visit("/") complete (no user)`);
4233
cy.contains('button', 'Login').click();
4334
}
44-
console.log(`[${new Date().toISOString()}] 🔐 waiting for "New Post" link`);
4535
cy.contains('a', 'New Post');
46-
console.log(`[${new Date().toISOString()}] 🔐 login() complete`);
4736
}
4837

4938
function assertNotification(message) {
@@ -60,12 +49,15 @@ function assertNotification(message) {
6049
}
6150

6251
function assertColorOn(cssProperty, color, opts) {
52+
function assertion($el) {
53+
return expect($el).to.have.css(cssProperty, color);
54+
}
55+
6356
if (opts.type && opts.type === 'label') {
6457
(opts.scope ? opts.scope : cy).contains('label', opts.label).should($el => {
6558
expect($el).to.have.css(cssProperty, color);
6659
});
6760
} else if (opts.type && opts.type === 'field') {
68-
const assertion = $el => expect($el).to.have.css(cssProperty, color);
6961
if (opts.isMarkdown) {
7062
(opts.scope ? opts.scope : cy)
7163
.contains('label', opts.label)
@@ -102,9 +94,7 @@ function goToCollections() {
10294
}
10395

10496
function goToMediaLibrary() {
105-
console.log(`[${new Date().toISOString()}] 📚 goToMediaLibrary() called`);
10697
cy.contains('button', 'Media').click();
107-
console.log(`[${new Date().toISOString()}] 📚 Media button clicked`);
10898
}
10999

110100
function assertUnpublishedEntryInEditor() {
@@ -281,11 +271,9 @@ function populateEntry(entry, onDone = flushClockAndSave) {
281271
for (const key of keys) {
282272
const value = entry[key];
283273
if (key === 'body') {
284-
cy.getMarkdownEditor()
285-
.first()
286-
.click()
287-
.clear({ force: true })
288-
.type(value, { force: true });
274+
cy.getMarkdownEditor().first().click();
275+
cy.getMarkdownEditor().first().clear({ force: true });
276+
cy.getMarkdownEditor().first().type(value, { force: true });
289277
} else {
290278
cy.get(`[id^="${key}-field"]`)
291279
.first()
@@ -481,14 +469,12 @@ function validateNestedObjectFields({ limit, author }) {
481469
cy.get('input[type=number]').type(limit + 1);
482470
cy.contains('button', 'Save').click();
483471
assertFieldValidationError(notifications.validation.range);
484-
cy.get('input[type=number]')
485-
.clear()
486-
.type(-1);
472+
cy.get('input[type=number]').clear();
473+
cy.get('input[type=number]').type(-1);
487474
cy.contains('button', 'Save').click();
488475
assertFieldValidationError(notifications.validation.range);
489-
cy.get('input[type=number]')
490-
.clear()
491-
.type(limit);
476+
cy.get('input[type=number]').clear();
477+
cy.get('input[type=number]').type(limit);
492478
cy.contains('button', 'Save').click();
493479
assertNotification(notifications.saved);
494480
}

0 commit comments

Comments
 (0)