Skip to content
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

(Feature Request) Ability to use AOT in unit testing #6650

Closed
Quramy opened this issue Jun 12, 2017 · 27 comments · Fixed by ngx-rocket/generator-ngx-rocket#172
Closed

(Feature Request) Ability to use AOT in unit testing #6650

Quramy opened this issue Jun 12, 2017 · 27 comments · Fixed by ngx-rocket/generator-ngx-rocket#172
Labels
Milestone

Comments

@Quramy
Copy link
Contributor

Quramy commented Jun 12, 2017

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Versions.

Repro steps.

The log given by the failure.

Desired functionality.

At @angular/core/testing v4.2.0, .ngSummary.ts files are introduced to support to use AOT in unit testing ( https://github.com/angular/angular/blob/master/CHANGELOG.md#features-4 ). Do you have a milestone about this?
I think it's useful to run unit testing with something like ng test --aot .

Mention any other details that might be useful.

@Brocco Brocco added P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity2: inconvenient labels Jun 14, 2017
@pgrm
Copy link

pgrm commented Sep 16, 2017

If we could run unit tests in AOT than we would have caught the latest bug which was published with 4.4.1 (angular/angular#19219) already on our build server, not just in staging, so this would be super useful.

I read in multiple places, that AOT should become default for angular 5 - is this true? would that resolve this issue afterwards?

@sinedied
Copy link
Contributor

sinedied commented Nov 6, 2017

Now that Angular@5 is released, this should be have more priority since we now need the reflect-es7 polyfills just to be able to run the unit tests: AOT can be enabled for serve/build, but not unit tests which is against the "AOT by default" promoted with Angular@5.

Or maybe there is another way to enable AOT for tests (unit/e2e) or workaround for this, @hansl any ideas?

@JBoothUA
Copy link

Sorry for asking a question here but this is a blocking issue for us.

Can anyone explain to me how to use relative template urls (aot style) in the source code, and then unit test that same source code with JIT.. i seem to be missing a trick?

or is there another trick to unit test with AOT?

thanks!

@willgm
Copy link

willgm commented Feb 13, 2018

Any update on this issue?

@filipesilva
Copy link
Contributor

There is a PR for it (#8007), as as mentioned in #8007 (comment) this support is still experimental and we'll wait until the feature stabilizes before incorporating it into the CLI.

@brian428
Copy link

brian428 commented Mar 5, 2018

Just a +1 for this. Hopefully the compiler folks determine that AoT support is stable soon. Not only would this catch AoT compile errors, but it should also vastly speed up test runs because all of the components won't need to be re-compiled over and over again for every single spec method.

@5c0r
Copy link

5c0r commented Mar 8, 2018

This would be very useful. Since we are adopting AOT since 4.0, we ended up having another build step with AOT to ensure everything works

@seawave23
Copy link

Really, nothing has happened since June 2017? AOT is meanwhile almost a must and tests don't adopt it?

@sinedied
Copy link
Contributor

@seawave23 Agree, and it's so sad that at a time where the focus is put on reducing the bundle size (Ivy renderer...) we still must keep the reflect-es7 polyfill just because of we cannot use AOT in unit tests 😕

@timbru31
Copy link

@sinedied with Angular CLI v6 you could use a separate polyfills.ts for the Unit tests in JIT mode. That means you don't need the reflect-ts7 for the real build 🎉

@sinedied
Copy link
Contributor

@sinedied with Angular CLI v6 you could use a separate polyfills.ts for the Unit tests in JIT mode. That means you don't need the reflect-ts7 for the real build 🎉

That's good news for a start, but still I don't like the fact that the code going to production is not the same one being tested, with different polyfills and build methods.

@timbru31
Copy link

timbru31 commented Jun 4, 2018

That's good news for a start, but still I don't like the fact that the code going to production is not the same one being tested, with different polyfills and build methods.

Our development, QA and E2E testing is done using AOT mode - I can "live" with that danger/rsik that JIT it used for the unit tests for the time being, but totally agree that the AOT support is long overdue :)

@aarmora
Copy link

aarmora commented Jul 2, 2018

@timbru31 How are you running your E2E tests in AOT mode? I am on ng6 and there is no --aot option.

@boldwade
Copy link

boldwade commented Jul 21, 2018

Just as a note, the wiki states it is possible, or implies it anyways...
https://github.com/angular/angular-cli/wiki/test

@giggio
Copy link

giggio commented Jul 24, 2018

@boldwade I can't find anything on the wiki you linked that states that aot can be used.

@boldwade
Copy link

It's ambiguous. The wiki page (listed above) links to the ng test page with supposed options that are available for said command. At the very least, it implies, at least to me, that I can run ng test with --prod options.

@giggio
Copy link

giggio commented Jul 31, 2018

But does this mean that aot will/can be used?

@boldwade
Copy link

boldwade commented Aug 2, 2018

right, see the confusion...

@mnahkies
Copy link
Contributor

I suspect this would also make it possible to include template binding expressions in code coverage reports (as suggested here angular/angular#427) which would be useful - currently I find the code coverage report pretty meaningless for components that include a lot of logic in their templates.

@ngbot ngbot bot added this to the Backlog milestone Oct 1, 2019
@filipesilva filipesilva removed P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity2: inconvenient labels Oct 1, 2019
@sharikovvladislav
Copy link

sharikovvladislav commented Oct 30, 2019

@filipesilva by what feature/bug is this blocked?

@sharikovvladislav
Copy link

Yesterday, I tried to run tests in AOT + IVY and got some success for some simple tests.

I got problem with type checking in templates. I had NO_ERRORS_SCHEME but type checking was enabled for unknown components.

@Quramy
Copy link
Contributor Author

Quramy commented Dec 4, 2019

I tried Karma and enableIvy: true too. And I checked out R3TestBedCompiler(not AoT but JiT) makes unit tests so faster 🎉

For now, I close this issue because my motivation, which was to improve performance of unit testing, has already achieved .

@Quramy Quramy closed this as completed Dec 4, 2019
@Goodwine
Copy link

Goodwine commented Dec 4, 2019

@Quramy Which version did you try?

@Quramy
Copy link
Contributor Author

Quramy commented Dec 4, 2019

@Goodwine


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 8.3.20
Node: 10.16.0
OS: darwin x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.20
@angular-devkit/build-angular     0.803.20
@angular-devkit/build-optimizer   0.803.20
@angular-devkit/build-webpack     0.803.20
@angular-devkit/core              8.3.20
@angular-devkit/schematics        8.3.20
@angular/cli                      8.3.20
@ngtools/webpack                  8.3.20
@schematics/angular               8.3.20
@schematics/update                0.803.20
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

@giggio
Copy link

giggio commented Dec 5, 2019

@Quramy I couldn't find any references to R3TestBedCompiler. Can you post more info?

@Quramy
Copy link
Contributor Author

Quramy commented Dec 5, 2019

@giggio I've commented angular/angular#12409 (comment)

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet