-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ivy compatibility #409
Comments
Hi @JiaLiPassion, I know that you work on |
Angular compiler design documentation can also be a helpful source https://github.com/angular/angular/blob/master/packages/compiler/design/architecture.md |
@ahnpnl , sure, I would like to help, and I will try to understand this issue and find out who to contact in the Angular team. |
The best scenario is somehow we can invoke a function which is exposed by Angular compiler. The function will create Angular TypeScript If this scenario is possible, we can reduce lots of maintenance work and everything will be handled by angular source. I suspect https://github.com/angular/angular/blob/d1ea1f4c7f3358b730b0d94e65b00bc28cae279c/packages/compiler-cli/src/perform_compile.ts#L237 is something might be useful for this approach. |
Yeah, I think using the Angular compiler API is the optimal approach, no fiddling with transformers and such! But we should take a good look at what Angular is doing different from the general compilation for testing with Karma as a reference. |
I have tried out
and discover a few nice things:
Notes
|
@ahnpnl Awesome! This breakthrough is great! Ultimately I see it like this: We can either go in the performance optimization by avoiding The direction taken here is the latter. To evaluate if this works as we imagine, we have to take some more steps. A roadmap for these next steps would be awesome. Please correct me, if I forgot something here, but it looks like this to me:
|
Yes that is my idea as well. I did a bit investigation into how Angular CLI invokes Angular compiler. Here is the flow:
Flow explanation
Unknown thingNo idea how this constant value is correctly set for Ivy/VE. This is one of the key things to make |
jest-preset-angular
So I found how the flag
In this picture is a part of
So I think our task should first look into A new question comes up is: what does
So it seems like the component compilation is done separately in Ivy while TestBed only set up testing environment (like jest |
we got an answer from one Angular team member, he suggested that we can open an issue which they can give some insights about how things work internally |
Wow, this is great! Thanks so much for all the effort you do in this direction. |
Today I asked Angular CLI team about reusing their transformers. They said those are private APIs so we are on our own to get it working. Lucky part is most of necessary apis in Started a bit today with replace-resources. The conclusion is: we can’t use it because it requires webpack. So our 2 transformers: |
Update #543 introduces the usage of Angular compiler which solves the issue with This compiler tries to replicate the behavior of Angular Compiler Plugin. The compiler only follows the path for JIT mode, AOT mode is more complex and requires ESM full support which is not available now in Apparently, using Angular compiler host via createCompilerHost seems to do the trick after running Regarding to the usage of transformers:
I only see the need of using these 2 transformers from Angular, not sure yet about other transformers. |
Yeah, I had a look at these two transformers, I used the downlevel transformer in #406 and took some inspiration from the I can take over the integration of these in the AngularJestTransformer 👍 |
Yes the benefit of using
A potential future feature is type checking template, but that seems to be only done with AOT because AOT has static analysis. Anyways, it’s a good transformer for us to follow and apply. I’m not sure if that will affect JIT tests or not, worth to try out. |
According to angular/angular-cli#15044, I am thinking about 2 ways to tackle this:
Force users to run ngccWe can check This approach has the advantage that it helps us to reduce the amount of work on The disadvantage is not so convenient. But since jest-preset-angular runs ngcc before running testsTo achieve this, we need to create an async function and ask users to use it in
Because Besides, if I am not wrong, when using jest Overall, I prefer the approach Force users to run ngcc What is your opinion @wtho ? |
I think the second version will be much more convenient for I really like the second version, but this is a comfort-level feature. We have no hurry to implement it. We can open a new issue and maybe find contributors who would want to tackle this. We could offer something like this: // jest.config.js
const initNgcc = require('jest-preset-angular/init-ngcc')
module.exports = async () => {
await initNgcc()
return {
verbose: true,
};
}; |
Ye expose an async function is simple. The only problem is it is limited to use only in root I think in the meantime, we can implement 1st approach. 2nd approach is nice to have so it can come later. Seem like angular already had something for us, see example in https://github.com/angular/angular/blob/master/packages/compiler-cli/ngcc/main-ngcc.ts |
More information on Operations done by ngcc
Reference: https://indepth.dev/angular-compatability-compiler/ So that means |
v9.0.0-next.1 is out under With this release, it is now possible to use We, the maintainers, highly appreciate the help from community with testing. Feel free to open any issues related to this |
What is stopping this Are there any specific aspects you would like us to pay more attention to? |
Currently we are checking about performance. I myself saw a downgrade in performance with my work's projects so still needs some investigation there. In general, for now there are 2 blockers:
|
9.0.0-next.2 is out. This release improves performance over 9.0.0-next.1. At least from my work’s projects, I can see the performance is more less similar to 8.3.2. |
Updated I've tried to integrate I found a way to run |
v9.0.0-next.3 is out. This release provides a util script to run To use the util script, you can just define it in your root
|
Not sure if this is related but we're seeing |
Do you have a reproduce repo for it ? The util script tries to invoke |
Looks like that was an issue with and outdated Jest package. With v6 it works. Still getting other errors but I suspect they're unrelated. Thanks. |
9.0.0-next.4 was out with support for Jest 27. |
I'm still seeing really slow start (after ngcc, it appears to hang before any tests complete, but it does finish the first tests after 5-8 minutes, then other tests complete approximately at "normal" speed). Do you have any suggestions for troubleshooting this phase of the test run? I was seeing this in the earlier next versions as well. Would be happy to open a separate issue, but it would be nice to be able to identify the cause. For example, is there a way to list which files are being compiled? |
Setting the environment variable TS_JEST_LOG=ts-jest.log should produce a log file which contains all loggings. In that file, there will be some loggings containing file name with the text "getCompiledOutput". That is the logging for file names which are compiled. Also follow tips https://kulshekhar.github.io/ts-jest/docs/options/isolatedModules#performance will help a bit. Bootstrap speed depends mainly on the amount of files to read. This includes Jest runtime file set + TypeScript compiler(internal jest-preset-angular) file set. The optimal file set for TypeScript compiler should only include type definition files so compiler API will spend less time on reading file system. |
v9.0.0-next.5 was out. In this release we use replace resources transformer from
|
v9.0.0-next.6 was out. In this release, both Besides, ESM support for both |
9.0.0-next.8 was out with an important change is test speed on Windows. Now Windows test speed should be more less similar to 8.3.2. Besides, |
I will close this issue as now we have reached the stability from feature point of view with next-10 (work similar to Karma + Jasmine) as well as documentation is ready (choose Now only wait for Jest and some potential fixes from |
@ahnpnl What are we waiting for from Jest and ts-jest? I don't know what issues I should track 😄 |
we are only waiting for official release of Jest 27 (and |
v9.0.0 was out. |
I just felt the need to post how eternally grateful I am for this thread. Seriously, you guys are forever in my debt. Little backstory: I spent the past week or so migrating a fairly low-key enterprise app to Jasmine/Karma to Jest, utilizing of course And then, after re-reaching 99% coverage locally, with all 1200+ tests passing, I expected that sweet row of greens in Jenkins...and didn't get it. Tests were blowing up for the strangest things:
Troubleshooting this was a bit of a nightmare: it is, after all, the dreaded "works on my machine" scenario. All of my Googling was failing me, and I spent a whole day on this getting absolutely nowhere. Late last night, after mostly focusing on individual symptoms (i.e. what would cause tests to fail for missing components?) I remembered that was something different from JIT to AOT. I started finding old threads about
JIT Compiler? In my AOT-enabled application? Why? Well, I still can't answer that. I'm so far down the rabbit hole I don't foresee our DevOps guys being able to give me a good answer (although I plan to try anyway). And besides, the following line in
And so it was, a gloriously green build, and my sanity has returned. Thank you all! |
Background
To turn TypeScript into JavaScript, Angular uses the TypeScript compiler, while also taking advantage of its own enhancements and processes. This practice was taken to the next level when the novel Ivy compiler was introduced, which optimizes the build even more and makes Angular a high-level web framework.
If tests running in jest just apply the TS-to-JS-compilation via
ts-jest
on the Angular code and try to run a tiny Angular App for a test case, many specialized scenarios miss the enhancements the Angular compiler does during Angular development.The following identified scenarios are possibly such, although there are probably more:
entryComponents
entryComponents with Angular 9 (Ivy) #353ngZone
Angular: Jest without Zone (noNgZone). #354To keep up with Ivy and further Angular enhancements, we want to depend more on the tools Angular provides.
PR #406 shows we are able to add Angular transformers in the preset.
Basic Transformer Analysis
When looking for
TransformatorFactory
in the Angular codebase (July 2020), we find several transformers, such asinline_resources.ts
A transformer to inline resources (such astemplateUrl
andstyleUrls
)jest-preset-angular
since feat: angular ctor params transformer #406.d.ts
filesFurther objects referenced as
transformers
are used inprogram.ts
While we could just try to include all of them, it is a much better path to understand what we are doing and why.
Any help analyzing these and figuring out what these do does help a lot.
The text was updated successfully, but these errors were encountered: