refactor Meteor app assertion function to be more flexible

This commit is contained in:
Nacho Codoñer
2025-08-12 13:47:51 +02:00
parent 1adaf7133c
commit a79f09809e

View File

@@ -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<void>}
*/
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<void>}
*/
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);
}
/**