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(test): allow tests to specify the platform and application providers used #5975
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS, | ||
ADDITIONAL_TEST_BROWSER_PROVIDERS | ||
} from 'angular2/platform/testing/browser_static'; | ||
|
||
import {BROWSER_APP_PROVIDERS} from 'angular2/platform/browser'; | ||
|
||
|
||
import {CONST_EXPR} from 'angular2/src/facade/lang'; | ||
|
||
/** | ||
* Default patform providers for testing. | ||
*/ | ||
export const TEST_BROWSER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = | ||
CONST_EXPR([TEST_BROWSER_STATIC_PLATFORM_PROVIDERS]); | ||
|
||
/** | ||
* Default application providers for testing. | ||
*/ | ||
export const TEST_BROWSER_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = | ||
CONST_EXPR([BROWSER_APP_PROVIDERS, ADDITIONAL_TEST_BROWSER_PROVIDERS]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
APP_ID, | ||
DirectiveResolver, | ||
NgZone, | ||
Provider, | ||
ViewResolver, | ||
PLATFORM_COMMON_PROVIDERS, | ||
PLATFORM_INITIALIZER | ||
} from 'angular2/core'; | ||
import {BROWSER_APP_COMMON_PROVIDERS} from 'angular2/src/platform/browser_common'; | ||
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter'; | ||
|
||
import {AnimationBuilder} from 'angular2/src/animate/animation_builder'; | ||
import {MockAnimationBuilder} from 'angular2/src/mock/animation_builder_mock'; | ||
import {MockDirectiveResolver} from 'angular2/src/mock/directive_resolver_mock'; | ||
import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock'; | ||
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy'; | ||
import {LocationStrategy} from 'angular2/src/router/location_strategy'; | ||
import {MockNgZone} from 'angular2/src/mock/ng_zone_mock'; | ||
|
||
import {XHRImpl} from "angular2/src/platform/browser/xhr_impl"; | ||
import {XHR} from 'angular2/compiler'; | ||
|
||
import {TestComponentBuilder} from 'angular2/src/testing/test_component_builder'; | ||
|
||
import {BrowserDetection} from 'angular2/src/testing/utils'; | ||
|
||
import {ELEMENT_PROBE_PROVIDERS} from 'angular2/platform/common_dom'; | ||
|
||
import {CONST_EXPR} from 'angular2/src/facade/lang'; | ||
|
||
import {Log} from 'angular2/src/testing/utils'; | ||
|
||
function initBrowserTests() { | ||
BrowserDomAdapter.makeCurrent(); | ||
BrowserDetection.setup(); | ||
} | ||
|
||
/** | ||
* Default patform providers for testing without a compiler. | ||
*/ | ||
export const TEST_BROWSER_STATIC_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = | ||
CONST_EXPR([ | ||
PLATFORM_COMMON_PROVIDERS, | ||
new Provider(PLATFORM_INITIALIZER, {useValue: initBrowserTests, multi: true}) | ||
]); | ||
|
||
export const ADDITIONAL_TEST_BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = | ||
CONST_EXPR([ | ||
new Provider(APP_ID, {useValue: 'a'}), | ||
ELEMENT_PROBE_PROVIDERS, | ||
new Provider(DirectiveResolver, {useClass: MockDirectiveResolver}), | ||
new Provider(ViewResolver, {useClass: MockViewResolver}), | ||
Log, | ||
TestComponentBuilder, | ||
new Provider(NgZone, {useClass: MockNgZone}), | ||
new Provider(LocationStrategy, {useClass: MockLocationStrategy}), | ||
new Provider(AnimationBuilder, {useClass: MockAnimationBuilder}), | ||
]); | ||
|
||
/** | ||
* Default application providers for testing without a compiler. | ||
*/ | ||
export const TEST_BROWSER_STATIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = | ||
CONST_EXPR([ | ||
BROWSER_APP_COMMON_PROVIDERS, | ||
new Provider(XHR, {useClass: XHRImpl}), | ||
ADDITIONAL_TEST_BROWSER_PROVIDERS | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Intentionally blank, the Parse5Adapater bindings for JavaScript don't apply. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
APP_ID, | ||
DirectiveResolver, | ||
NgZone, | ||
Provider, | ||
ViewResolver, | ||
PLATFORM_COMMON_PROVIDERS, | ||
PLATFORM_INITIALIZER, | ||
APPLICATION_COMMON_PROVIDERS, | ||
Renderer | ||
} from 'angular2/core'; | ||
import {Parse5DomAdapter} from 'angular2/src/platform/server/parse5_adapter'; | ||
|
||
import {AnimationBuilder} from 'angular2/src/animate/animation_builder'; | ||
import {MockAnimationBuilder} from 'angular2/src/mock/animation_builder_mock'; | ||
import {MockDirectiveResolver} from 'angular2/src/mock/directive_resolver_mock'; | ||
import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock'; | ||
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy'; | ||
import {LocationStrategy} from 'angular2/src/router/location_strategy'; | ||
import {MockNgZone} from 'angular2/src/mock/ng_zone_mock'; | ||
|
||
import {TestComponentBuilder} from 'angular2/src/testing/test_component_builder'; | ||
import {XHR} from 'angular2/src/compiler/xhr'; | ||
import {BrowserDetection} from 'angular2/src/testing/utils'; | ||
|
||
import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler'; | ||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens'; | ||
import {DOM} from 'angular2/src/platform/dom/dom_adapter'; | ||
import {RootRenderer} from 'angular2/src/core/render/api'; | ||
import {DomRootRenderer, DomRootRenderer_} from 'angular2/src/platform/dom/dom_renderer'; | ||
import {DomSharedStylesHost} from 'angular2/src/platform/dom/shared_styles_host'; | ||
|
||
import { | ||
EventManager, | ||
EVENT_MANAGER_PLUGINS, | ||
ELEMENT_PROBE_PROVIDERS | ||
} from 'angular2/platform/common_dom'; | ||
import {DomEventsPlugin} from 'angular2/src/platform/dom/events/dom_events'; | ||
|
||
import {CONST_EXPR} from 'angular2/src/facade/lang'; | ||
|
||
import {Log} from 'angular2/src/testing/utils'; | ||
|
||
function initServerTests() { | ||
Parse5DomAdapter.makeCurrent(); | ||
BrowserDetection.setup(); | ||
} | ||
|
||
/** | ||
* Default patform providers for testing. | ||
*/ | ||
export const TEST_SERVER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([ | ||
PLATFORM_COMMON_PROVIDERS, | ||
new Provider(PLATFORM_INITIALIZER, {useValue: initServerTests, multi: true}) | ||
]); | ||
|
||
function appDoc() { | ||
try { | ||
return DOM.defaultDoc(); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Default application providers for testing. | ||
*/ | ||
export const TEST_SERVER_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = | ||
CONST_EXPR([ | ||
// TODO(julie): when angular2/platform/server is available, use that instead of making our own | ||
// list here. | ||
APPLICATION_COMMON_PROVIDERS, | ||
COMPILER_PROVIDERS, | ||
new Provider(DOCUMENT, {useFactory: appDoc}), | ||
new Provider(DomRootRenderer, {useClass: DomRootRenderer_}), | ||
new Provider(RootRenderer, {useExisting: DomRootRenderer}), | ||
EventManager, | ||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true}), | ||
new Provider(XHR, {useClass: XHR}), | ||
new Provider(APP_ID, {useValue: 'a'}), | ||
DomSharedStylesHost, | ||
ELEMENT_PROBE_PROVIDERS, | ||
new Provider(DirectiveResolver, {useClass: MockDirectiveResolver}), | ||
new Provider(ViewResolver, {useClass: MockViewResolver}), | ||
Log, | ||
TestComponentBuilder, | ||
new Provider(NgZone, {useClass: MockNgZone}), | ||
new Provider(LocationStrategy, {useClass: MockLocationStrategy}), | ||
new Provider(AnimationBuilder, {useClass: MockAnimationBuilder}), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can't we reexport
browser_static.ts
here rather than duplicating most of the file?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.
done.