From a3d4bc4e34e3e4c1734fa3c1d8cb19c59778b190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Thu, 7 Aug 2025 11:07:54 +0200 Subject: [PATCH] test meteor run on production --- tools/modern-tests/assertions.js | 4 ++-- tools/modern-tests/helpers.js | 9 ++++++++- tools/modern-tests/react.test.js | 27 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tools/modern-tests/assertions.js b/tools/modern-tests/assertions.js index ffa74e6d5f..6080888a98 100644 --- a/tools/modern-tests/assertions.js +++ b/tools/modern-tests/assertions.js @@ -25,7 +25,7 @@ export async function assertMeteorReactApp(port) { * @param {number} port - Port where the app is running * @returns {Promise} */ -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); } diff --git a/tools/modern-tests/helpers.js b/tools/modern-tests/helpers.js index 9b27176410..41d42d05e5 100644 --- a/tools/modern-tests/helpers.js +++ b/tools/modern-tests/helpers.js @@ -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 diff --git a/tools/modern-tests/react.test.js b/tools/modern-tests/react.test.js index 70e4c9475e..df16bde0f0 100644 --- a/tools/modern-tests/react.test.js +++ b/tools/modern-tests/react.test.js @@ -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);