nx/packages/angular/src/generators/convert-to-rspack/lib/get-custom-webpack-config.spec.ts
Colum Ferry 745abdaecf
fix(angular): convert-to-rspack correctly migrating existing custom webpack configs (#30778)
## Current Behavior
The `createConfig` helper from `@nx/angular-rspack` became an async
function.
This meant that the handling of custom webpack configs in the migration
done by `convert-to-rspack` was incorrect.

## Expected Behavior
Ensure the migration is handled correctly.
Ensure that Module Federation migrations work correctly.

## Related Issues
Fixes https://github.com/nrwl/angular-rspack/issues/53
2025-04-22 15:54:51 +01:00

66 lines
2.2 KiB
TypeScript

import { convertWebpackConfigToUseNxModuleFederationPlugin } from './get-custom-webpack-config';
describe('convertconvertWebpackConfigToUseNxModuleFederationPlugin', () => {
it('should convert a basic webpack config to use Nx Module Federation Plugin', () => {
// ARRANGE
const webpackConfigContents = `
import { withModuleFederation } from '@nx/module-federation/angular';
import config from './module-federation.config';
export default withModuleFederation(config, { dts: false });
`;
// ACT
const newWebpackConfigContents =
convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents);
// ASSERT
expect(newWebpackConfigContents).toMatchInlineSnapshot(`
"
import { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } from '@nx/module-federation/rspack';
import config from './module-federation.config';
export default {
plugins: [
new NxModuleFederationPlugin({ config }, {
dts: false,
}),
new NxModuleFederationDevServerPlugin({ config }),
]
}
"
`);
});
it('should convert a basic cjs webpack config to use Nx Module Federation Plugin', () => {
// ARRANGE
const webpackConfigContents = `
const { withModuleFederation } = require('@nx/module-federation/angular');
const config = require('./module-federation.config');
module.exports = withModuleFederation(config, { dts: false });
`;
// ACT
const newWebpackConfigContents =
convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents);
// ASSERT
expect(newWebpackConfigContents).toMatchInlineSnapshot(`
"
const { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } = require('@nx/module-federation/rspack');
const config = require('./module-federation.config');
module.exports = {
plugins: [
new NxModuleFederationPlugin({ config }, {
dts: false,
}),
new NxModuleFederationDevServerPlugin({ config }),
]
}
"
`);
});
});