High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Add ability to wait and healthcheck for backend app in Cypress settings tests.
Kailash Nadhe6d3aad0a1ef
diff --git a/frontend/cypress/e2e/bounces.cy.js b/frontend/cypress/e2e/bounces.cy.jsindex aadf552c..603f5a6f 100644--- a/frontend/cypress/e2e/bounces.cy.js+++ b/frontend/cypress/e2e/bounces.cy.js@@ -11,11 +11,18 @@ describe('Bounces', () => {cy.get('[data-cy=btn-enable-bounce] .switch').click();cy.get('[data-cy=btn-enable-bounce-webhook] .switch').click();+ // The last <select> box, pick 'delete' option.+ cy.get('select[name="bounce.action"]').last().select('delete');+cy.get('[data-cy=btn-save]').click();- cy.wait(2000);++ cy.waitForBackend();+ cy.wait(1000);});it('Post bounces', () => {+ cy.loginAndVisit('/admin/subscribers/bounces');+// Get campaign.let camp = {};cy.request(`${apiUrl}/api/campaigns`).then((resp) => {@@ -42,6 +49,7 @@ describe('Bounces', () => {// Hard bounces blocklist.cy.request('POST', `${apiUrl}/webhooks/bounce`, { source: 'api', type: 'hard', email: subs[0].email });cy.request('POST', `${apiUrl}/webhooks/bounce`, { source: 'api', type: 'hard', email: subs[0].email });+cy.request(`${apiUrl}/api/subscribers/${subs[0].id}`).then((resp) => {sub = resp.body.data;}).then(() => {diff --git a/frontend/cypress/e2e/settings.cy.js b/frontend/cypress/e2e/settings.cy.jsindex 82a8a7ad..4b243e80 100644--- a/frontend/cypress/e2e/settings.cy.js+++ b/frontend/cypress/e2e/settings.cy.js@@ -1,12 +1,14 @@const apiUrl = Cypress.env('apiUrl');-describe('Templates', () => {+describe('Settings', () => {it('Opens settings page', () => {cy.resetDB();cy.loginAndVisit('/admin/settings');});it('Changes some settings', () => {+ cy.get('.b-tabs nav a').eq(0).click();+const rootURL = 'http://127.0.0.1:9000';const faveURL = 'http://127.0.0.1:9000/public/static/logo.png';@@ -26,8 +28,11 @@ describe('Templates', () => {cy.get('[data-cy=btn-save]').click();- cy.wait(1000);+ cy.waitForBackend();+ cy.wait(2000);+ });+ it('Verify settings change', () => {// Verify the changes.cy.request(`${apiUrl}/api/settings`).should((response) => {const { data } = response.body;diff --git a/frontend/cypress/support/commands.js b/frontend/cypress/support/commands.jsindex d3b2bca6..2d17d9a4 100644--- a/frontend/cypress/support/commands.js+++ b/frontend/cypress/support/commands.js@@ -1,4 +1,5 @@import 'cypress-file-upload';+import 'cypress-wait-until';Cypress.Commands.add('resetDB', () => {// Although cypress clearly states that a webserver should not be run@@ -51,6 +52,27 @@ Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe, callback =.then((iframe) => cy.wrap(iframe.contents().find('body'))).within({}, callback));+Cypress.Commands.add('waitForBackend', () => {+ // Intercept frontend's health checks to prevent test failures+ cy.intercept({+ method: 'GET',+ url: '/*', // Update with actual polling endpoint+ }, {+ continueOnNetworkError: true, // Prevents Cypress from failing on network errors+ });++ cy.waitUntil(+ () => cy.request({+ url: '/api/profile', // Same endpoint as frontend polls+ failOnStatusCode: false,+ }).then((response) => response.status === 200),+ {+ timeout: 10000, // Max wait time (10 seconds)+ interval: 1000, // Check every 0.5 seconds+ },+ );+});+Cypress.on('uncaught:exception', (err, runnable) => {if (err.hasOwnProperty('request')) {const u = err.request.url;diff --git a/frontend/package.json b/frontend/package.jsonindex 3ef71aab..d190f374 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -34,6 +34,7 @@"@vue/eslint-config-airbnb": "^7.0.1","cypress": "13.15.0","cypress-file-upload": "^5.0.2",+ "cypress-wait-until": "^3.0.2","eslint": "^8.56.0","eslint-define-config": "^2.0.0","eslint-plugin-import": "^2.23.3",diff --git a/frontend/yarn.lock b/frontend/yarn.lockindex b0e0b023..ea413c3d 100644--- a/frontend/yarn.lock+++ b/frontend/yarn.lock@@ -1056,6 +1056,11 @@ cypress-file-upload@^5.0.2:resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz#d8824cbeaab798e44be8009769f9a6c9daa1b4a1"integrity sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g==+cypress-wait-until@^3.0.2:+ version "3.0.2"+ resolved "https://registry.yarnpkg.com/cypress-wait-until/-/cypress-wait-until-3.0.2.tgz#c90dddfa4c46a2c422f5b91d486531c560bae46e"+ integrity sha512-iemies796dD5CgjG5kV0MnpEmKSH+s7O83ZoJLVzuVbZmm4lheMsZqAVT73hlMx4QlkwhxbyUzhOBUOZwoOe0w==+version "13.15.0"resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.15.0.tgz#5eca5387ef34b2e611cfa291967c69c2cd39381d"