ng-mocks icon indicating copy to clipboard operation
ng-mocks copied to clipboard

feat: support signal input from angular 17.1

Open andreandersson opened this issue 10 months ago • 8 comments

Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment.

Solves #7976

andreandersson avatar Apr 24 '24 07:04 andreandersson

@satanTime the CI will probably not work "as is", and I'm not sure how to solve this nicely. We need to run a "pre-build-step" to downgrade angularJitApplicationTransform to cjs instead of esm. I'm guessing we need to update all test / build-steps in the scripts of package.json?

andreandersson avatar Apr 24 '24 07:04 andreandersson

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (940dc1a) to head (e519230).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #8818   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          227       227           
  Lines         4935      4925   -10     
  Branches      1147      1142    -5     
=========================================
- Hits          4935      4925   -10     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 14 '24 07:05 codecov[bot]

This is finally ready for review

andreandersson avatar May 21 '24 04:05 andreandersson

Thank you, I'll take a look during the next days.

satanTime avatar May 21 '24 05:05 satanTime

Could you explain the changes when you have time?

satanTime avatar May 21 '24 05:05 satanTime

Sure, though I'm not really sure I understand the changes myself to a full extend I'll do my best.

The most important part is running angularJitApplicationTransform when transpiling ng-mocks. angularJitApplicationTransform is part of @angular/core and downlevels code by, for example, changing from a signal input to @Input.

Since @angular/core is an esm-module we need to convert it to CommonJS to be able to build it for ng-mocks, hence why we're not simply importing it from @angular/core directly but rather use esbuild to convert it in a post-install step. I'm very open to other suggestions here, since this is probably the thing I dislike most about the current solution.

Since the transforming does other things I was able to remove some more code. Mainly parseParameters which handles @Attribute. These are some changes I'm not to confident about, but the tests seem to think the solution is fine.

The usage of angularJitApplicationTransform is needed twice, one for the tests (karma.conf.ts) and one for "real world" (webpack.config.js). In other words; we don't really have any tests for the actual implementation. Only that the test-configuration is correct. The test is located in e2e a18, though it should run in all 17.1+ versions of angular. The only reason for this was problems with import { input } from '@angular/core' in different versions of angular while still having the angularJitApplicationTransform handling the typings in a good way.

The solution is quite inspired from jest-preset-angular: https://github.com/thymikee/jest-preset-angular/pull/2303

Let me know if you want to talk to me somewhere else regarding these changes. I'll try to update the commit messages with this information as well.

andreandersson avatar May 21 '24 06:05 andreandersson

@satanTime Are there any updates about this pull request? The amount of NG0303 errors generated in specs by signal inputs can cause a lot of headache :( Related issue: https://github.com/help-me-mom/ng-mocks/issues/7976#issuecomment-2061085756

SiimTa avatar Aug 05 '24 14:08 SiimTa

How tf this PR isn't merged yet ? We kinda need this to use your package with angular 17-18

Jessy-BH avatar Oct 11 '24 13:10 Jessy-BH

Hello, seems we need this in my team projects. Any news ?

thiboot avatar Oct 30 '24 14:10 thiboot