1+ // #docregion
12// /*global jasmine, __karma__, window*/
2- Error . stackTraceLimit = Infinity ;
3+ Error . stackTraceLimit = 0 ; // "No stacktrace"" is usually best for app testing.
4+
5+ // Uncomment to get full stacktrace output. Sometimes helpful, usually not.
6+ // Error.stackTraceLimit = Infinity; //
7+
38jasmine . DEFAULT_TIMEOUT_INTERVAL = 1000 ;
49
5- __karma__ . loaded = function ( ) {
6- } ;
10+ var builtPath = '/base/app/' ;
11+
12+ __karma__ . loaded = function ( ) { } ;
713
814function isJsFile ( path ) {
915 return path . slice ( - 3 ) == '.js' ;
1016}
1117
1218function isSpecFile ( path ) {
13- return / \. s p e c \. j s $ / . test ( path ) ;
19+ return / \. s p e c \. ( . * \. ) ? j s $ / . test ( path ) ;
1420}
1521
1622function isBuiltFile ( path ) {
17- var builtPath = '/base/app/' ;
1823 return isJsFile ( path ) && ( path . substr ( 0 , builtPath . length ) == builtPath ) ;
1924}
2025
@@ -24,31 +29,61 @@ var allSpecFiles = Object.keys(window.__karma__.files)
2429
2530System . config ( {
2631 baseURL : '/base' ,
27- packageWithIndex : true // sadly, we can't use umd packages (yet?)
32+ // Extend usual application package list with test folder
33+ packages : { 'testing' : { main : 'index.js' , defaultExtension : 'js' } } ,
34+
35+ // Assume npm: is set in `paths` in systemjs.config
36+ // Map the angular testing umd bundles
37+ map : {
38+ '@angular/core/testing' : 'npm:@angular/core/bundles/core-testing.umd.js' ,
39+ '@angular/common/testing' : 'npm:@angular/common/bundles/common-testing.umd.js' ,
40+ '@angular/compiler/testing' : 'npm:@angular/compiler/bundles/compiler-testing.umd.js' ,
41+ '@angular/platform-browser/testing' : 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js' ,
42+ '@angular/platform-browser-dynamic/testing' : 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js' ,
43+ '@angular/http/testing' : 'npm:@angular/http/bundles/http-testing.umd.js' ,
44+ '@angular/router/testing' : 'npm:@angular/router/bundles/router-testing.umd.js' ,
45+ '@angular/forms/testing' : 'npm:@angular/forms/bundles/forms-testing.umd.js' ,
46+ } ,
2847} ) ;
2948
3049System . import ( 'systemjs.config.js' )
31- . then ( function ( ) {
32- return Promise . all ( [
33- System . import ( '@angular/core/testing' ) ,
34- System . import ( '@angular/platform-browser-dynamic/testing' )
35- ] )
36- } )
37- . then ( function ( providers ) {
38- var testing = providers [ 0 ] ;
39- var testingBrowser = providers [ 1 ] ;
50+ // .then(importSystemJsExtras)
51+ . then ( initTestBed )
52+ . then ( initTesting ) ;
4053
41- testing . setBaseTestProviders (
42- testingBrowser . TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS ,
43- testingBrowser . TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS ) ;
54+ /** Optional SystemJS configuration extras. Keep going w/o it */
55+ function importSystemJsExtras ( ) {
56+ return System . import ( 'systemjs.config.extras.js' )
57+ . catch ( function ( reason ) {
58+ console . log (
59+ 'WARNING: System.import could not load "systemjs.config.extras.js"; continuing without it.'
60+ ) ;
61+ console . log ( reason ) ;
62+ } ) ;
63+ }
4464
65+ function initTestBed ( ) {
66+ return Promise . all ( [
67+ System . import ( '@angular/core/testing' ) ,
68+ System . import ( '@angular/platform-browser-dynamic/testing' )
69+ ] )
70+
71+ . then ( function ( providers ) {
72+ var coreTesting = providers [ 0 ] ;
73+ var browserTesting = providers [ 1 ] ;
74+
75+ coreTesting . TestBed . initTestEnvironment (
76+ browserTesting . BrowserDynamicTestingModule ,
77+ browserTesting . platformBrowserDynamicTesting ( ) ) ;
4578 } )
46- . then ( function ( ) {
47- // Finally, load all spec files.
48- // This will run the tests directly.
49- return Promise . all (
50- allSpecFiles . map ( function ( moduleName ) {
51- return System . import ( moduleName ) ;
52- } ) ) ;
53- } )
54- . then ( __karma__ . start , __karma__ . error ) ;
79+ }
80+
81+ // Import all spec files and start karma
82+ function initTesting ( ) {
83+ return Promise . all (
84+ allSpecFiles . map ( function ( moduleName ) {
85+ return System . import ( moduleName ) ;
86+ } )
87+ )
88+ . then ( __karma__ . start , __karma__ . error ) ;
89+ }
0 commit comments