thymikee / jest-preset-angular

Jest configuration preset for Angular projects.
https://thymikee.github.io/jest-preset-angular/
MIT License
883 stars 304 forks source link

[Feature]: Support AOT compilation #2582

Open waterplea opened 1 month ago

waterplea commented 1 month ago

🚀 Feature Proposal

It looks like currently JIT compiler is hardcoded: https://github.com/thymikee/jest-preset-angular/blob/main/src/compiler/ng-jest-compiler.ts#L63

I would be nice if we could use Jest with Angular AOT.

Motivation

JIT is barely ever used for years and is a very obscure mode that can cause issues that do not occur in real apps. AOT has been the default for nearly 10 major versions. Using AOT in Jest would improve testing environment by bringing it closer to the real life.

Example

No response

ahnpnl commented 1 month ago

We are following Angular CLI regarding to unit test. With Angular CLI, it also uses JIT compilation.

In general, to support AOT, we need a different flow comparing to current way. It will be kind of like

According to what I've known, using JIT compilation for test is faster than AOT.

@alan-agius4 would you please give us some more insights why Angular CLI uses JIT compilation for test? Thank you

alan-agius4 commented 1 month ago

AOT compilation speed has improved significantly over the years, so the speed improvements over JIT aren't that substantial. In the Angular CLI, JIT is currently used for unit tests but we are considering providing an option to use AOT. However, we first need to address a few questions, mainly concerning the correct semantics for writing tests and certain testing APIs that are JIT specific.

//cc @clydin and @dgp1130