Skip to content

feat(upgrade): provide test helpers for wiring up injectors - #16848

Closed
petebacondarwin wants to merge 3 commits into
angular:masterfrom
petebacondarwin:ngupgrade-testing-api
Closed

petebacondarwin wants to merge 3 commits into
angular:masterfrom
petebacondarwin:ngupgrade-testing-api

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented May 17, 2017 •

Copy link
Copy Markdown
Contributor

Sits on top of #29466

This PR provides two test helpers for the upgrade/static library, which wire up the Angular and AngularJS injectors without the need for a full bootstrap of a hybrid app.

  • createAngularJSTestingModule() should be used in AngularJS tests
  • createAngularTestingModule() should be used in Angular tests

Check out the spec files for example usage.

@mhevery

mhevery commented May 17, 2017

Copy link
Copy Markdown
Contributor

Looking good! I think we need some more documentation on how to use this. Can this be part of the API docs?

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

I'll add docs but wanted feedback on whether this is the right API first.

@gkalpak

gkalpak commented May 22, 2017

Copy link
Copy Markdown
Member

As a reminder, the helpers need to be exported and upgrade/testing should be added to a bunch of lists for it to appear in the docs etc.

@juliemr

juliemr commented Jun 23, 2017

Copy link
Copy Markdown
Contributor

Ping?

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

Sorry I have been distracted. I will tidy it up this week.

@petebacondarwin petebacondarwin self-assigned this Jun 25, 2017
@petebacondarwin
petebacondarwin force-pushed the ngupgrade-testing-api branch from c73b392 to 52735ee Compare July 3, 2017 12:40
@petebacondarwin

Copy link
Copy Markdown
Contributor Author

I have made the suggested changes, where appropriate, added documentation and included this new module in as many configuration files as I could find.

PTAL: @mhevery @juliemr @gkalpak

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

And of course this PR falls foul of the change from CircleCI v1 to v2.

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

Just checking to see if closing and reopening helps with CircleCI

@gkalpak gkalpak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits. Looks great so far (except that I have no idea about all the places we need to list a new package 😁)
I assume more tests will be added when this is finalized.

One thing I am a little concerned with is the namespacing of the module. Typically @angular/foo/testing is for testing @angular/foo/bar. So, I would expect the testing package for @angular/upgrade/static to be @angular/upgrade/static/testing (while @angular/upgrade/testing sounds more about testing @angular/upgrade).
I hope that eventually, @angular/upgrade will get dropped and @angular/upgrade/static will be moved to @angular/upgrade (together with its testing module).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR: Does this include upgrade/static? Shouldn't it be explicitly imported?

@kieranblight

kieranblight commented Jul 21, 2017 •

Copy link
Copy Markdown

Hi @petebacondarwin, I am just wondering what the rough timeline for this to be release will be?

@petebacondarwin
petebacondarwin force-pushed the ngupgrade-testing-api branch from 0743841 to 0260634 Compare July 22, 2017 15:04
@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@kieranblight - I have been having difficulties getting the new package into the system. I hope to finish this and get it in by the end of this week.

@kieranblight

Copy link
Copy Markdown

@petebacondarwin thank you, look forward to it :)!

@petebacondarwin
petebacondarwin force-pushed the ngupgrade-testing-api branch 3 times, most recently from 0ca84ba to 733d0aa Compare July 29, 2017 21:47
@petebacondarwin
petebacondarwin force-pushed the ngupgrade-testing-api branch 2 times, most recently from d3c0ab5 to 590e8c2 Compare August 17, 2017 10:02
@mary-poppins

Copy link
Copy Markdown

You can preview ba85f2e at https://pr16848-ba85f2e.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview c4c98e4 at https://pr16848-c4c98e4.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview b9193f6 at https://pr16848-b9193f6.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 81184b9 at https://pr16848-81184b9.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 5984a60 at https://pr16848-5984a60.ngbuilds.io/.

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

We should also provide an "injector only version" that does not require a full TestBed to be compiled. E.g. Something like this (thanks to @jbedard)

export function provideInjector(...providers: StaticProvider[]) {
    return function($provide: angular.auto.IProvideService) {
        $provide.factory("$$angularInjector", ["$injector", function($injector: angular.auto.IInjectorService) {
            return Injector.create([
                ...providers,
                {provide: "$injector", useValue: $injector}
            ]);
        }]);
        $provide.factory("$$angularLazyModuleRef", ["$$angularInjector", (injector) => ({injector, needsNgZone: true})]);
    };
}

@theandrewlane

Copy link
Copy Markdown

Would be cool if this got merged in! 😬

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@pburgmer (regarding #16848 (comment)). There is a bug in the stringify() method of the Angular compiler, which a commit in this PR now fixes.

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

Looks like the failure is legit. I'll have to work on that.

@fzxt

fzxt commented Apr 13, 2019

Copy link
Copy Markdown

@petebacondarwin any plans to get this in soon? do appreciate the work going on here.

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@fzxt - I will need help resolving the Windows CI failures...

@fzxt

fzxt commented Apr 20, 2019

Copy link
Copy Markdown

Ping? It would be nice to get these helpers in soon. Can any googlers help out with the review?

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@jasonaden is working on it :-)

@zuzusik

zuzusik commented Jun 13, 2019

Copy link
Copy Markdown

any expectations on when this is going to be finished?

thanks!

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

Apart from the conflicts it is ready to be reviewed. It is unlikely to land before 8.2 or 9 now.
I'll rebase tomorrow and chase someone (like @IgorMinar) to take a view.

Adds two new helper functions that can be used when unit testing Angular services
that depend upon upgraded AngularJS services, or vice versa.
The functions return a module (AngularJS or NgModule) that is configured to wire up
the Angular and AngularJS injectors without the need to actually bootstrap a full
hybrid application.

This makes it simpler and faster to unit test services.

@alxhub alxhub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for compiler.

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm for API changes.

@AndrewKushnir

Copy link
Copy Markdown
Contributor

VE presubmit

@AndrewKushnir

Copy link
Copy Markdown
Contributor

Presubmit indicated that we need to perform additional changes in build files in g3 to land this PR. I've added "cleanup" label for now and will look into the build files update asap. Thank you.

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

Thanks @AndrewKushnir

@AndrewKushnir

Copy link
Copy Markdown
Contributor

New VE presubmit, including g3 changes.

Note to Caretaker: this PR requires additional change in g3: cl/254085499, to update BUILD file with extra rules to build upgrade/testing package.

@samjulien

Copy link
Copy Markdown
Contributor

For anyone who finds this thread in the future, these helpers are available. Check out the docs here: https://angular.io/api/upgrade/static/testing

@angular-automatic-lock-bot

Copy link
Copy Markdown

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: upgrade Issues related to AngularJS → Angular upgrade APIs cla: yes feature Label used to distinguish feature request from other issues merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.