From 41f3b22679300652a4fa0e2c818a6387f553479e Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 19 May 2026 23:46:17 -0300 Subject: [PATCH] Fix flaky E2E tests (Cypress + Playwright) (#36637) * Fix flaky email sort test by ignoring punctuation in localeCompare PostgreSQL's en_US.UTF-8 collation ignores hyphens at the primary sort level, but JS localeCompare() on a C-locale CI runner uses byte order, causing the expected and actual sort orders to diverge for emails containing hyphens. Passing ignorePunctuation:true aligns JS collation with Postgres behavior. * E2E/Cypress: re-enable CYPRESS_* env var overrides allowCypressEnv: false was introduced in the v15.13 upgrade (PR #36091) but broke the existing CYPRESS_adminUsername / CYPRESS_adminPassword override mechanism that local and CI runners depend on. * E2E/Cypress: fix MM-T1508 accessibility image test flakiness The test was failing because the admin user could have a stale compact display mode preference from a previous spec, causing post avatars to render with pointer-events: none and blocking the .status-wrapper click. Two fixes: - resetUserPreference() now resets message_display to 'clean' so compact mode doesn't leak across spec files - accessibility_image_spec before() now runs as a fresh user with default preferences rather than the shared admin account --- e2e-tests/cypress/cypress.config.ts | 6 +++--- .../accessibility/accessibility_image_spec.js | 13 +++++++++---- e2e-tests/cypress/tests/support/index.js | 1 + .../system_console/system_users/column_sort.spec.ts | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/e2e-tests/cypress/cypress.config.ts b/e2e-tests/cypress/cypress.config.ts index b499d4a98c3..cca14200584 100644 --- a/e2e-tests/cypress/cypress.config.ts +++ b/e2e-tests/cypress/cypress.config.ts @@ -27,9 +27,9 @@ export default defineConfig({ viewportWidth: 1300, allowCypressEnv: false, expose: { - adminEmail: 'sysadmin@sample.mattermost.com', - adminUsername: 'sysadmin', - adminPassword: 'Sys@dmin-sample1', + adminEmail: process.env.CYPRESS_adminEmail || 'sysadmin@sample.mattermost.com', + adminUsername: process.env.CYPRESS_adminUsername || 'sysadmin', + adminPassword: process.env.CYPRESS_adminPassword || 'Sys@dmin-sample1', allowedUntrustedInternalConnections: 'localhost', cwsURL: 'http://localhost:8076', cwsAPIURL: 'http://localhost:8076', diff --git a/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_image_spec.js b/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_image_spec.js index 5703f9c38a0..031c82da940 100644 --- a/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_image_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_image_spec.js @@ -16,11 +16,16 @@ describe('Verify Accessibility Support in Different Images', () => { let otherUser; before(() => { - cy.apiInitSetup().then(({offTopicUrl, user}) => { - otherUser = user; + cy.apiInitSetup().then(({team, offTopicUrl, user}) => { + cy.apiCreateUser({prefix: 'other'}).then(({user: user1}) => { + otherUser = user1; + return cy.apiAddUserToTeam(team.id, otherUser.id); + }).then(() => { + cy.apiLogin(user); - // Visit the Off Topic channel - cy.visit(offTopicUrl); + // Visit the Off Topic channel + cy.visit(offTopicUrl); + }); }); }); diff --git a/e2e-tests/cypress/tests/support/index.js b/e2e-tests/cypress/tests/support/index.js index 279c291e647..743703b0761 100644 --- a/e2e-tests/cypress/tests/support/index.js +++ b/e2e-tests/cypress/tests/support/index.js @@ -254,6 +254,7 @@ function sysadminSetup(user) { function resetUserPreference(userId) { cy.apiSaveTeammateNameDisplayPreference('username'); + cy.apiSaveMessageDisplayPreference('clean'); cy.apiSaveLinkPreviewsPreference('true'); cy.apiSaveCollapsePreviewsPreference('false'); cy.apiSaveClockDisplayModeTo24HourPreference(false); diff --git a/e2e-tests/playwright/specs/functional/system_console/system_users/column_sort.spec.ts b/e2e-tests/playwright/specs/functional/system_console/system_users/column_sort.spec.ts index cf05f7f87f3..f451a500f55 100644 --- a/e2e-tests/playwright/specs/functional/system_console/system_users/column_sort.spec.ts +++ b/e2e-tests/playwright/specs/functional/system_console/system_users/column_sort.spec.ts @@ -53,7 +53,7 @@ test.describe('System Console - Users table sorting', () => { } expect(emails.length).toBeGreaterThan(3); - const sorted = [...emails].sort((a, b) => a.localeCompare(b)); + const sorted = [...emails].sort((a, b) => a.localeCompare(b, undefined, {ignorePunctuation: true})); if (sortDirection === 'descending') { sorted.reverse(); } @@ -81,7 +81,7 @@ test.describe('System Console - Users table sorting', () => { } expect(emails.length).toBeGreaterThan(3); - const sorted = [...emails].sort((a, b) => a.localeCompare(b)); + const sorted = [...emails].sort((a, b) => a.localeCompare(b, undefined, {ignorePunctuation: true})); if (reversedDirection === 'descending') { sorted.reverse(); }