nx/packages/angular/src/migrations/update-20-2-0/update-angular-ssr-imports-to-use-node-entry-point.spec.ts
Leosvel Pérez Espinosa 3ec539065d
feat(angular): add support for angular v19 (#28847)
## Third-party deps support for Angular v19

- [x] `jest-preset-angular`
  - [x] PRs:
    - [x] https://github.com/thymikee/jest-preset-angular/pull/2835
  - [x] Released:
- [x] RC:
https://github.com/thymikee/jest-preset-angular/releases/tag/v14.4.0-rc.0
- [x] Stable:
https://github.com/thymikee/jest-preset-angular/releases/tag/v14.4.0
- [x] Angular ESLint
  - [x] PRs:
    - [x] https://github.com/angular-eslint/angular-eslint/pull/2109
  - [x] Released:
- [x]
https://github.com/angular-eslint/angular-eslint/releases/tag/v19.0.0
- [x] Storybook
  - [x] PRs:
    - [x] https://github.com/storybookjs/storybook/pull/29659
    - [x] https://github.com/storybookjs/storybook/pull/29677
  - [x] Released:
    - [x] https://github.com/storybookjs/storybook/pull/29679
- [ ] NgRx
  - [x] PRs:
    - [x] https://github.com/ngrx/platform/pull/4602
  - [ ] Released:
- [x] Beta:
https://github.com/ngrx/platform/blob/main/CHANGELOG.md#1900-beta0-2024-11-20
    - [ ] Stable:
- [ ] Analog
  - [x] PRs:
    - [x] https://github.com/analogjs/analog/pull/1447
    - [x] https://github.com/analogjs/analog/pull/1451
  - [ ] Released:
- [x] Beta:
https://github.com/analogjs/analog/releases/tag/v1.10.0-beta.6
    - [ ] Stable:

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

Angular v19 is not supported.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

Angular v19 should be supported.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
 
Fixes #29028
2024-12-02 11:43:24 -05:00

92 lines
2.7 KiB
TypeScript

import {
addProjectConfiguration,
type ProjectConfiguration,
type ProjectGraph,
type Tree,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import migration from './update-angular-ssr-imports-to-use-node-entry-point';
let projectGraph: ProjectGraph;
jest.mock('@nx/devkit', () => ({
...jest.requireActual('@nx/devkit'),
createProjectGraphAsync: () => Promise.resolve(projectGraph),
formatFiles: jest.fn(),
}));
describe('update-angular-ssr-imports-to-use-node-entry-point migration', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});
it('should replace "CommonEngine*" imports from "@angular/ssr" to "@angular/ssr/node"', async () => {
addProject('app1', { name: 'app1', root: 'apps/app1' }, [
'npm:@angular/ssr',
]);
tree.write(
'apps/app1/server.ts',
`import { CommonEngine } from '@angular/ssr';
import type { CommonEngineOptions, CommonEngineRenderOptions } from '@angular/ssr';
`
);
await migration(tree);
expect(tree.read('apps/app1/server.ts', 'utf-8')).toMatchInlineSnapshot(`
"import { CommonEngine } from '@angular/ssr/node';
import type { CommonEngineOptions, CommonEngineRenderOptions } from '@angular/ssr/node';
"
`);
});
it('should not re-append "/node" in "CommonEngine*" imports from "@angular/ssr/node"', async () => {
addProject('app1', { name: 'app1', root: 'apps/app1' }, [
'npm:@angular/ssr',
]);
const input = `import { CommonEngine } from '@angular/ssr/node';
import type { CommonEngineOptions, CommonEngineRenderOptions } from '@angular/ssr/node';
`;
tree.write('apps/app1/server.ts', input);
await migration(tree);
expect(tree.read('apps/app1/server.ts', 'utf-8')).toBe(input);
});
it('should not replace "CommonEngine*" imports from other packages', async () => {
addProject('app1', { name: 'app1', root: 'apps/app1' }, [
'npm:@angular/ssr',
]);
const input = `import { CommonEngine } from 'some-other-package';
import type { CommonEngineOptions, CommonEngineRenderOptions } from '../some-relative-path';
`;
tree.write('apps/app1/server.ts', input);
await migration(tree);
expect(tree.read('apps/app1/server.ts', 'utf-8')).toBe(input);
});
function addProject(
projectName: string,
config: ProjectConfiguration,
dependencies: string[]
): void {
projectGraph = {
dependencies: {
[projectName]: dependencies.map((d) => ({
source: projectName,
target: d,
type: 'static',
})),
},
nodes: {
[projectName]: { data: config, name: projectName, type: 'app' },
},
};
addProjectConfiguration(tree, projectName, config);
}
});