test meteor run on production

This commit is contained in:
Nacho Codoñer
2025-08-07 11:07:54 +02:00
parent a0cecb9e91
commit a3d4bc4e34
3 changed files with 36 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ export async function assertMeteorReactApp(port) {
* @param {number} port - Port where the app is running
* @returns {Promise<void>}
*/
export async function assertRspackScriptTag(port) {
export async function assertRspackScriptTag(port, shoudlExist = true) {
// Navigate to the app
await page.goto(`http://localhost:${port}`);
@@ -36,5 +36,5 @@ export async function assertRspackScriptTag(port) {
// Check if any script tag has __rspack__ in its path
const hasRspackScript = scriptTags.some(src => src && src.includes('__rspack__'));
expect(hasRspackScript).toBe(true);
expect(hasRspackScript).toBe(shoudlExist);
}

View File

@@ -60,6 +60,7 @@ export async function setupMeteorApp(appName) {
* @param {Object} options - Additional options
* @param {string|RegExp} options.waitForOutput - Output pattern to wait for
* @param {Object} options.waitOptions - Options for waitForMeteorOutput
* @param {string[]} options.commandOptions - Additional command line options for the run command (e.g. ['--production'])
* @returns {Object} - The meteor process and output lines
*/
export async function runMeteorApp(tempDir, port, options = {}) {
@@ -69,10 +70,16 @@ export async function runMeteorApp(tempDir, port, options = {}) {
// Determine if we need to capture output
const captureOutput = !!options.waitForOutput;
// Combine port option with any additional command options
const args = ['--port', port.toString()];
if (options.commandOptions && Array.isArray(options.commandOptions)) {
args.push(...options.commandOptions);
}
// Run the meteor command
const { meteorProcess, outputLines } = await runMeteorCommand(
'run',
['--port', port.toString()],
args,
tempDir,
{},
captureOutput

View File

@@ -142,7 +142,32 @@ describe('React App Bundling', () => {
await assertMeteorReactApp(PORT);
// Assert that the app is using Rspack
await assertRspackScriptTag(PORT);
await assertRspackScriptTag(PORT, true);
// Kill the meteor process
await killMeteorProcess(meteorProcess);
// Ensure any process on the port is killed
await killProcessByPort(PORT);
await killProcessByPort('8080');
});
test(`"meteor run --production" should run the app with Rspack in production`, async () => {
// Run the Meteor app and wait for "restarted at" output
const result = await runMeteorApp(tempDir, PORT, {
waitForOutput: "=> App running at:",
commandOptions: ['--production'],
});
meteorProcess = result.meteorProcess;
// Wait for a margin
await wait(500);
// Assert that the Meteor React app is running correctly
await assertMeteorReactApp(PORT);
// Assert that the app is using Rspack
await assertRspackScriptTag(PORT, false);
// Kill the meteor process
await killMeteorProcess(meteorProcess);