mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
refactor Meteor app assertion function to be more flexible
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user