-
Notifications
You must be signed in to change notification settings - Fork 306
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
feat: use angular compiler api to transform codes #562
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you added the downlevelConstructorParameters
!
Wow this is so cool! I wish I would have been more involved into this, but I was quite busy recently.
Once more thanks again!
}, | ||
}, | ||
transform: { | ||
'^.+\\.(ts|js|html)$': 'ts-jest', | ||
'^.+\\.(ts|js|html)$': 'jest-preset-angular', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this is it! Haha, will have to get used to it!
Still have some fine tunings to do but we are pretty close. The current state is already in pretty good shape. Probably next week I can push this out in 9.0.0-next.1 once this one is done. |
NgJestCompiler
NgJestCompiler
What's still open? Is there still more to address? |
I have published this PR under 9.0.0-next.1 release so it's easier to test with real projects. |
NgJestCompiler
Closes #108 Closes #288 Closes #322 Closes #353 BREAKING CHANGE: With the new jest transformer, `jest-preset-angular` now switches to default to use this new transformer and no longer use `ts-jest` to transform codes. Users who are currently doing in jest config ``` // jest.config.js module.exports = { // [...] transform: { '^.+\\.(ts|js|html)$': 'ts-jest', }, } ``` should change to ``` // jest.config.js module.exports = { // [...] transform: { '^.+\\.(ts|js|html)$': 'jest-preset-angular', }, } ``` `isolatedModule: true` will still use `ts-jest` to compile `ts` to `js` but you won't get full compatibility with Ivy. To make sure tests work, please always run `ngcc` in postinstall hook
Solved the addressed problem in #622
Jest parallel mode doesn't allow `ngcc` to run. The only way to run `ngcc` with Jest is invoking `ngcc` directly in `jest.config.js`. Because Jest reads `jest.config.js` only once before running tests, running `ngcc` is possible with it
In a jest transformer, `process` is the place where code transformation happens. Therefore, we should only create `NgJestTransformer` instance in `process`, not when creating `NgJestConfig` instance
Summary
See individual commits
NgJestCompiler
takes care of compiling files and return a string which is the compiled output concatenating with source map string. The compiler also does type checking.This compiler is mainly inspired by AngularCompilerPlugin in combination with
ts-jest
LanguageService.Closes #108
Closes #288
Closes #322
Closes #353
Closes #622
Check list
Type checking
Code compilation
Memory cache for
Program
Allow custom compiler module, e.g
ttypescript
(viats-jest
option)Downlevel ctor transformer
hoisting (from
ts-jest
)ngcc
util scriptTest plan
Added unit tests
Added e2e test which is taken from entryComponents with Angular 9 (Ivy) #353
Added e2e test for
forwardRef
Does this PR introduce a breaking change?
With the new jest transformer,
jest-preset-angular
now switches to default to use this new transformer and no longer usets-jest
to transform codes.Users who are currently doing in jest config
should change to
isolatedModule: true
will still usets-jest
to compilets
tojs
but you won't get full compatibility with Ivy.Other information
N.A.