X Tutup
Skip to content

feat(test): allow tests to specify the platform and application providers used#5975

Closed
juliemr wants to merge 1 commit intoangular:masterfrom
juliemr:test-with-bundles-2-b
Closed

feat(test): allow tests to specify the platform and application providers used#5975
juliemr wants to merge 1 commit intoangular:masterfrom
juliemr:test-with-bundles-2-b

Conversation

@juliemr
Copy link
Copy Markdown
Member

@juliemr juliemr commented Dec 17, 2015

With providers split into bundles, the test injector is now able to
use providers for a given bundle. Suggested provider lists for tests are
available in angular2/platform/testing/<platform>.

Change the providers for a test suite using setBaseTestProviders. This
should be done once at the start of the test suite, before any test cases
run.

BREAKING CHANGE: Tests are now required to use setBaseTestProviders
to set up. Assuming your tests are run on a browser, setup would change
as follows.

Before:

// Somewhere in test setup
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter';
BrowserDomAdapter.makeCurrent

After:

// Somewhere in the test setup
import {setBaseTestProviders} from 'angular2/testing';
import {
  TEST_BROWSER_PLATFORM_PROVIDERS,
  TEST_BROWSER_APPLICATION_PROVIDERS
} from 'angular2/platform/testing/browser';

setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS,
                     TEST_BROWSER_APPLICATION_PROVIDERS);

Closes #5351, Closes #5585

@juliemr juliemr added action: discuss area: testing Issues related to Angular testing features, such as TestBed labels Dec 17, 2015
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 17, 2015

Still to do:

  • web worker tests are failing. Need to create angular2/platform/testing/web_worker.ts or some such and use it there instead.
  • dart package angular2_testing is not yet updated.
  • test.unit.cjs is still failing - they're never set up with base providers. Figure out where to do this and what providers they should have.

@juliemr juliemr force-pushed the test-with-bundles-2-b branch 2 times, most recently from 822918a to 8fba327 Compare December 18, 2015 22:21
@juliemr juliemr changed the title WIP - design for refactoring and allowing different platforms in unit tests feat(test): allow tests to specify the platform and application providers used Dec 18, 2015
@juliemr juliemr added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: discuss labels Dec 18, 2015
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 18, 2015

This is now squashed and has a real commit message noting the breaking change. Waiting for Travis, but all the unit test suites are passing locally. Ready for review!

@juliemr juliemr force-pushed the test-with-bundles-2-b branch 4 times, most recently from ad916ed to 0891f79 Compare December 18, 2015 23:38
@juliemr juliemr assigned IgorMinar and vsavkin and unassigned IgorMinar Dec 18, 2015
@juliemr juliemr added this to the beta.1 milestone Dec 18, 2015
@juliemr juliemr force-pushed the test-with-bundles-2-b branch from 0891f79 to 6e48522 Compare December 18, 2015 23:52
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 18, 2015

Note that this will require a change in g3 to remove a use of createTestInjectorWithRuntimeCompiler and createTestInjector.

@wardbell
Copy link
Copy Markdown
Contributor

I'm a bit confused because I'm not sure what "platform providers" are.

I know what PLATFORM_DIRECTIVES are. I know what PLATFORM_PIPES are. We need to account for both of these during our testing ... both to load them by default perhaps AND to facilitate mocking them under test.

We have a mechanism for setting up providers and for overloading the (implicit) providers that A2 registers by default.

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 19, 2015

platform providers is analogous to the terminology we use in platform(<providers>).application(<providers>).boostrap(<component>).

The PLATFORM_DIRECTIVES and PLATFORM_PIPES are now loaded by default if you set up with angular2/plaform/testing/browser.

@juliemr juliemr force-pushed the test-with-bundles-2-b branch from 6e48522 to d26204c Compare December 19, 2015 00:39
@wardbell
Copy link
Copy Markdown
Contributor

The terminology challenge for me is that provider != directive != pipe.

I must have missed something along the way. I hadn't realized that directives, components, and pipe are all "provided" ... like anything else I toss in the injector. I thought they went somewhere special with their own namespace.

This also means that, withing the same injector, I can replace any directive by writing

provide(SomeDirective, {useClass: MyAlternativeDirective})

I can do that in my production code, not just in tests.

Does that sound right? I haven't tried it.

@wardbell
Copy link
Copy Markdown
Contributor

Is it save to assume that you reset the "standard directives set" if I mock one of them out during a test?

Suppose I spy on the DatePipe or on NgModel. That goes away next test, yes?

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 19, 2015

Yes, everything is reset between tests.

@wardbell
Copy link
Copy Markdown
Contributor

For the record, based on our conversation, I had the wrong mental model.

Here is my revised understanding ... which we hope conforms to reality.

Providers, Directives, and Pipes are their own categories. There are good reasons why we have separate providers, directives, and pipes arrays in metadata.

The "provider" with the token "PLATFORM_DIRECTIVES" is an array of directives that Angular stashes in the top injector.

When Angular gets ready to look for directives in a template, it combines what we list in our directives metadata array with the platform directives that it retrieved from the injector under the "PLATFORM_DIRECTIVES" token.

The test apparatus described in this PR is a way to configure the platform common providers and platform directives for the test suite.

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 21, 2015

Dear merge-master:

This will require a small change to g3. Here's a doc with all the info: https://docs.google.com/document/d/10N5YrdavEECZt-WJhYw7967RFrzF7tmLiihHXAhKxc8

After a talk with users teams, it sounds like we should wait until after the holidays to make any sort of changes, so consider this ready but waiting.

@juliemr juliemr added action: merge The PR is ready for merge by the caretaker and removed action: merge The PR is ready for merge by the caretaker labels Dec 21, 2015
@alexeagle
Copy link
Copy Markdown
Contributor

the doc says "We should wait until after the holiday freeze to be sure the
ACX team is around" - so we should wait, right?
Also, https://rotation.googleplex.com/#rotation?id=5710658318368768
(there seems to be a rumor that I'm caretaker?)

On Mon, Dec 21, 2015 at 3:05 PM Julie Ralph notifications@github.com
wrote:

Dear merge-master: @alexeagle https://github.com/alexeagle

This is OKd by Tobias to go in now, and ready to merge! It will require a
sall change to g3. Here's a doc with all the info:
https://docs.google.com/document/d/10N5YrdavEECZt-WJhYw7967RFrzF7tmLiihHXAhKxc8


Reply to this email directly or view it on GitHub
#5975 (comment).

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Dec 22, 2015

Yes! Sorry, my comment was edited to say that but edits don't get out to emails.

I did not start the rumor :)

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 8, 2016

FYI - this is now rebased on top of the recent freezing code changes.

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 8, 2016

Test failures are due to new saucelabs_required test target. @mgol do you happen to have time to take a look and see if these are legitimate? I'm surprised by all the zone failures.

@juliemr juliemr force-pushed the test-with-bundles-2-b branch 3 times, most recently from 33de8d6 to ee6d1b9 Compare January 12, 2016 00:15
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 12, 2016

The failures on FireFox and IE were due to a global setup on load in testing utils BrowserDetection. Because the new test platform initializer, which set up the DOM, was not called until after files were loaded, BrowserDetection broke. This is now fixed.

@juliemr juliemr force-pushed the test-with-bundles-2-b branch from ee6d1b9 to 1357bee Compare January 12, 2016 00:18
…ders used

With providers split into bundles, the test injector is now able to
use providers for a given bundle. Suggested provider lists for tests are
available in `angular2/platform/testing/<platform>`.

Change the providers for a test suite using `setBaseTestProviders`. This
should be done once at the start of the test suite, before any test cases
run.

BREAKING CHANGE: Tests are now required to use `setBaseTestProviders`
to set up. Assuming your tests are run on a browser, setup would change
as follows.

Before:

```js
// Somewhere in test setup
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter';
BrowserDomAdapter.makeCurrent
```

After:

```js
// Somewhere in the test setup
import {setBaseTestProviders} from 'angular2/testing';
import {
  TEST_BROWSER_PLATFORM_PROVIDERS,
  TEST_BROWSER_APPLICATION_PROVIDERS
} from 'angular2/platform/testing/browser';

setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS,
                     TEST_BROWSER_APPLICATION_PROVIDERS);
```

Closes angular#5351, Closes angular#5585
@juliemr juliemr force-pushed the test-with-bundles-2-b branch from 1357bee to 60943fe Compare January 12, 2016 00:28
@rkirov rkirov added action: merge The PR is ready for merge by the caretaker zomg_admin: do merge labels Jan 12, 2016
@mary-poppins
Copy link
Copy Markdown

Merging PR #5975 on behalf of @rkirov to branch presubmit-rkirov-pr-5975.

@rolandjitsu
Copy link
Copy Markdown

Did this made it to beta.2? Because I cannot find neither of TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS nor angular2/platform/testing/browser in the testing.dev.js bundle.
@juliemr

@pkozlowski-opensource
Copy link
Copy Markdown
Member

@rolandjitsu see #6771

@rolandjitsu
Copy link
Copy Markdown

@pkozlowski-opensource thanks.

@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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
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: testing Issues related to Angular testing features, such as TestBed cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLATFORM_DIRECTIVES not defined in tests test injector should work smoothly with new bundles
X Tutup