Skip to content

Commit

Permalink
feat(rspack): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Nov 22, 2024
1 parent 33348c0 commit abf9bc7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 85 deletions.
81 changes: 0 additions & 81 deletions packages/react/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,85 +1241,4 @@ describe('app', () => {
}
`);
});

it('should add project to excludes when @nx/rspack/plugin is setup as object and --bundler=rspack', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
let nxJson = readNxJson(tree);
delete nxJson.targetDefaults;
nxJson.plugins ??= [];
nxJson.plugins.push({
plugin: '@nx/rspack/plugin',
options: {
buildTargetName: 'build-base',
},
});
updateNxJson(tree, nxJson);

// ACT
await applicationGenerator(tree, {
directory: 'myapp',
addPlugin: true,
linter: Linter.None,
style: 'none',
bundler: 'rspack',
e2eTestRunner: 'none',
});

// ASSERT
nxJson = readNxJson(tree);
expect(
nxJson.plugins.find((p) =>
typeof p === 'string'
? p === '@nx/rspack/plugin'
: p.plugin === '@nx/rspack/plugin'
)
).toMatchInlineSnapshot(`
{
"exclude": [
"myapp/**",
],
"options": {
"buildTargetName": "build-base",
},
"plugin": "@nx/rspack/plugin",
}
`);
});
it('should add project to excludes when @nx/rspack/plugin is setup as string and --bundler=rspack', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
let nxJson = readNxJson(tree);
delete nxJson.targetDefaults;
nxJson.plugins ??= [];
nxJson.plugins.push('@nx/rspack/plugin');
updateNxJson(tree, nxJson);

// ACT
await applicationGenerator(tree, {
directory: 'myapp',
addPlugin: true,
linter: Linter.None,
style: 'none',
bundler: 'rspack',
e2eTestRunner: 'none',
});

// ASSERT
nxJson = readNxJson(tree);
expect(
nxJson.plugins.find((p) =>
typeof p === 'string'
? p === '@nx/rspack/plugin'
: p.plugin === '@nx/rspack/plugin'
)
).toMatchInlineSnapshot(`
{
"exclude": [
"myapp/**",
],
"plugin": "@nx/rspack/plugin",
}
`);
});
});
12 changes: 8 additions & 4 deletions packages/react/src/rules/update-module-federation-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function updateModuleFederationProject(
if (options.bundler === 'rspack') {
projectConfig.targets.build.executor = '@nx/rspack:rspack';
projectConfig.targets.build.options = {
...projectConfig.targets.build.options,
...(projectConfig.targets.build.options ?? {}),
main: maybeJs(
{ js: options.js, useJsx: true },
`${options.appProjectRoot}/src/main.ts`
Expand All @@ -37,23 +37,27 @@ export function updateModuleFederationProject(
target: 'web',
};

projectConfig.targets.build.configurations ??= {};

projectConfig.targets.build.configurations.production = {
...projectConfig.targets.build.configurations.production,
...(projectConfig.targets.build.configurations?.production ?? {}),
rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${
options.typescriptConfiguration && !options.js ? 'ts' : 'js'
}`,
};
} else {
projectConfig.targets.build.options = {
...projectConfig.targets.build.options,
...(projectConfig.targets.build.options ?? {}),
main: maybeJs(options, `${options.appProjectRoot}/src/main.ts`),
webpackConfig: `${options.appProjectRoot}/webpack.config.${
options.typescriptConfiguration && !options.js ? 'ts' : 'js'
}`,
};

projectConfig.targets.build.configurations ??= {};

projectConfig.targets.build.configurations.production = {
...projectConfig.targets.build.configurations.production,
...(projectConfig.targets.build.configurations?.production ?? {}),
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${
options.typescriptConfiguration && !options.js ? 'ts' : 'js'
}`,
Expand Down

0 comments on commit abf9bc7

Please sign in to comment.