add test coverage CustomConsoleLogPlugin with support for plugin disabling

This commit is contained in:
Nacho Codoñer
2025-12-15 19:39:18 +01:00
parent 8e8364dca6
commit ab703e3140
4 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
// CustomConsoleLogPlugin.js
class CustomConsoleLogPlugin {
apply(compiler) {
compiler.hooks.beforeRun.tap('CustomConsoleLogPlugin', (compilation) => {
console.log('👉 [CustomConsoleLogPlugin] Build is starting...');
});
compiler.hooks.done.tap('CustomConsoleLogPlugin', (stats) => {
console.log('✅ [CustomConsoleLogPlugin] Build finished successfully!');
});
}
}
module.exports = CustomConsoleLogPlugin;

View File

@@ -1,5 +1,6 @@
const { defineConfig } = require('@meteorjs/rspack');
const path = require('path');
const CustomConsoleLogPlugin = require("./plugins/CustomConsoleLogPlugin");
/**
* Rspack configuration for Meteor projects.
@@ -12,7 +13,13 @@ const path = require('path');
* Use these flags to adjust your build settings based on environment.
*/
module.exports = defineConfig(Meteor => {
const disabledPluginMatches = Meteor.isRun
? ['CustomConsoleLogPlugin']
: Meteor.isTest
? /CustomConsoleLogPlugin/i
: p => p?.constructor?.name === 'CustomConsoleLogPlugin';
return {
...Meteor.disablePlugins(disabledPluginMatches),
resolve: {
alias: {
"@public": path.resolve(__dirname, "public"),
@@ -32,5 +39,6 @@ module.exports = defineConfig(Meteor => {
},
],
},
plugins: [new CustomConsoleLogPlugin()],
};
});

View File

@@ -79,6 +79,9 @@ describe('React App Bundling /', () => {
// Check if images exist and return 200 status code
await assertImagesExistAndLoad();
// Check custom plugin is disabled with Meteor.disablePlugins
await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true });
},
afterRunRebuildClient: async ({ allConsoleLogs }) => {
// Check for HMR output as enabled by default
@@ -89,6 +92,9 @@ describe('React App Bundling /', () => {
// Check if images exist and return 200 status code
await assertImagesExistAndLoad();
// Check custom plugin is disabled with Meteor.disablePlugins
await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true });
},
afterRunProductionRebuildClient: async ({ allConsoleLogs }) => {
// Check for HMR to not be enabled in production-like mode
@@ -96,12 +102,21 @@ describe('React App Bundling /', () => {
},
afterTest: async ({ result }) => {
await waitForReactEnvs(result.outputLines);
// Check custom plugin is disabled with Meteor.disablePlugins
await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true });
},
afterTestOnce: async ({ result }) => {
await waitForReactEnvs(result.outputLines);
// Check custom plugin is disabled with Meteor.disablePlugins
await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true });
},
afterBuild: async ({ result }) => {
await waitForReactEnvs(result.outputLines, { isJsxEnabled: true });
// Check custom plugin is disabled with Meteor.disablePlugins
await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true });
},
}
}));

View File

@@ -761,6 +761,25 @@ RSPACK_DEVSERVER_PORT=3232 meteor run
The reason is that the Rspack dev server is handled by the Meteor so it can make both dev server works together, and the info of the port needs to be properly shared via the env.
### Disable Plugins
Meteor allows disabling Rspack plugins that are added by default or through presets. This is useful when troubleshooting build issues or replacing a plugin with a custom implementation.
Plugins are matched by name (constructor name) and can be specified as a string, RegExp, a predicate function, or an array of all.
``` js
const { defineConfig } = require('@meteorjs/rspack');
module.exports = defineConfig(Meteor => ({
// Disable one or more Rspack plugins
...Meteor.disablePlugins([
'DefinePlugin',
/Html/i,
p => p?.constructor?.name === 'CustomConsoleLogPlugin',
]),
}));
```
## Benefits
MeteorRspack integration sends your app code to Rspack to use modern bundler features. Meteor then uses Rspacks output to handle Meteor-specific tasks (like Atmosphere package compilation) and create the final bundle.