From a79f09809e41f8e6592fc2d79a42e92be3d2c084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Tue, 12 Aug 2025 13:47:51 +0200 Subject: [PATCH] refactor Meteor app assertion function to be more flexible --- tools/modern-tests/assertions.js | 47 +++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/tools/modern-tests/assertions.js b/tools/modern-tests/assertions.js index f14ff6d731..a8441ccb9e 100644 --- a/tools/modern-tests/assertions.js +++ b/tools/modern-tests/assertions.js @@ -5,6 +5,34 @@ import fs from 'fs-extra'; import path from 'path'; +/** + * Helper function to assert that a Meteor app is running correctly + * @param {number} port - Port where the app is running + * @param {Object} options - Options for the assertion + * @param {string} options.title - Expected content in the title + * @param {string} options.h1 - Expected content in the h1 element + * @returns {Promise} + */ +export async function assertMeteorApp(port, options = {}) { + // Extract options with default values + const { title: inTitle, h1: inH1 } = options; + + // Navigate to the app + await page.goto(`http://localhost:${port}`); + + // Check the title if specified + if (inTitle) { + const title = await page.title(); + expect(title).toMatch(new RegExp(inTitle)); + } + + // Check for static content if specified + if (inH1) { + const h1Text = await page.$eval('h1', el => el.textContent); + expect(h1Text).toMatch(new RegExp(inH1)); + } +} + /** * Helper function to assert that a Meteor React app is running correctly * @param {number} port - Port where the app is running @@ -14,19 +42,12 @@ import path from 'path'; * @returns {Promise} */ export async function assertMeteorReactApp(port, options = {}) { - // Extract options with default values - const { title: inTitle = "react", h1: inH1 = "Welcome to Meteor!" } = options; - - // Navigate to the app - await page.goto(`http://localhost:${port}`); - - // Check the title - const title = await page.title(); - expect(title).toMatch(new RegExp(inTitle)); - - // Check for static content - const h1Text = await page.$eval('h1', el => el.textContent); - expect(h1Text).toMatch(new RegExp(inH1)); + const reactOptions = { + title: "react", + h1: "Welcome to Meteor!", + ...options + }; + await assertMeteorApp(port, reactOptions); } /**