nx/packages/angular/src/migrations/update-21-2-0/replace-provide-server-routing.spec.ts
Leosvel Pérez Espinosa 601fecdf0c
feat(angular): support angular v20 (#31369)
Add support for Angular v20.

BREAKING CHANGE: Support for Angular v17 was dropped.

### TODO

- [x] Update Angular packages to the stable v20
- [x] Update `jest-preset-angular` when it releases support for Angular
v20
  - [x] PR: https://github.com/thymikee/jest-preset-angular/pull/3119
- [x] Release:
https://github.com/thymikee/jest-preset-angular/releases/tag/v14.6.0
- [ ] Update Angular ESLint packages to the v20 stable version once
released
  - [ ] PR: https://github.com/angular-eslint/angular-eslint/pull/2448
- [x] Update AnalogJS packages when they are released with support for
Angular v20
  - [x] PR: https://github.com/analogjs/analog/pull/1751
- [x] Release: https://github.com/analogjs/analog/releases/tag/v1.17.0
- [x] Fix for `@analogjs/vitest-angular` peer deps:
https://github.com/analogjs/analog/pull/1754
    - [x] Release:
- [x] Beta:
https://github.com/analogjs/analog/releases/tag/v1.17.1-beta.1
- [x] Stable: https://github.com/analogjs/analog/releases/tag/v1.17.1
- [ ] Update Storybook packages
- [x] PRs: https://github.com/storybookjs/storybook/pull/31602 and
https://github.com/storybookjs/storybook/pull/31611
- [x] Storybook 9 Release:
https://github.com/storybookjs/storybook/releases/tag/v9.0.3
  - [ ] Storybook 8 Release??: PENDING
- [ ] Remaining issue:
https://github.com/storybookjs/storybook/issues/31652
2025-06-06 10:55:26 -04:00

195 lines
6.3 KiB
TypeScript

import {
addProjectConfiguration,
type ProjectGraph,
type Tree,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import migration from './replace-provide-server-routing';
let projectGraph: ProjectGraph;
jest.mock('@nx/devkit', () => ({
...jest.requireActual('@nx/devkit'),
createProjectGraphAsync: jest
.fn()
.mockImplementation(() => Promise.resolve(projectGraph)),
}));
describe('replace-provide-server-routing migration', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
addProjectConfiguration(tree, 'app1', { root: 'apps/app1' });
projectGraph = {
dependencies: {
app1: [
{
source: 'app1',
target: 'npm:@angular/ssr',
type: 'static',
},
],
},
nodes: {
app1: {
data: { root: 'apps/app1' },
name: 'app1',
type: 'app',
},
},
};
});
it('should remove "provideServerRouting", add an import for "withRoutes" and update "provideServerRendering" to use "withRoutes"', async () => {
tree.write(
'apps/app1/src/app/app.config.server.ts',
`import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, provideServerRouting } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [provideServerRendering(), provideServerRouting(serverRoutes)],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
`
);
await migration(tree);
expect(tree.read('apps/app1/src/app/app.config.server.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, withRoutes } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [provideServerRendering(withRoutes(serverRoutes))],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
"
`);
});
it('should include extra arguments provided to "provideServerRouting"', async () => {
tree.write(
'apps/app1/src/app/app.config.server.ts',
`import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, provideServerRouting, withAppShell } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering(),
provideServerRouting(serverRoutes, withAppShell(AppShellComponent)),
],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
`
);
await migration(tree);
expect(tree.read('apps/app1/src/app/app.config.server.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, withAppShell, withRoutes } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering(
withRoutes(serverRoutes),
withAppShell(AppShellComponent)
),
],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
"
`);
});
it('should remove "provideServerRoutesConfig", add an import for "withRoutes" and update "provideServerRendering" to use "withRoutes"', async () => {
tree.write(
'apps/app1/src/app/app.config.server.ts',
`import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, provideServerRoutesConfig } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [provideServerRendering(), provideServerRoutesConfig(serverRoutes)],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
`
);
await migration(tree);
expect(tree.read('apps/app1/src/app/app.config.server.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, withRoutes } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [provideServerRendering(withRoutes(serverRoutes))],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
"
`);
});
it('should include extra arguments provided to "provideServerRoutesConfig"', async () => {
tree.write(
'apps/app1/src/app/app.config.server.ts',
`import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, provideServerRoutesConfig, withAppShell } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering(),
provideServerRoutesConfig(serverRoutes, withAppShell(AppShellComponent)),
],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
`
);
await migration(tree);
expect(tree.read('apps/app1/src/app/app.config.server.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, withAppShell, withRoutes } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering(
withRoutes(serverRoutes),
withAppShell(AppShellComponent)
),
],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
"
`);
});
});