Skip to content

Commit 1945e85

Browse files
authored
Fixing the test in webpack by waiting for the platform to be initialized. (#1507)
1 parent a85a507 commit 1945e85

File tree

1 file changed

+19
-16
lines changed
  • addon/ng2/blueprints/ng2/files/__path__

1 file changed

+19
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
/*global jasmine, __karma__, window*/
31
import 'core-js/es6';
42
import 'core-js/es7/reflect';
53

@@ -16,22 +14,27 @@ import 'zone.js/dist/sync-test';
1614
// RxJS
1715
import 'rxjs/Rx';
1816

19-
Promise.all([
20-
System.import('@angular/core/testing'),
21-
System.import('@angular/platform-browser-dynamic/testing')
22-
]).then(function (providers) {
23-
let testing = providers[0];
24-
let testingBrowser = providers[1];
17+
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
18+
declare var __karma__: any;
19+
20+
// Prevent Karma from running prematurely.
21+
__karma__.loaded = function () {};
22+
2523

24+
Promise.all([
25+
System.import('@angular/core/testing'),
26+
System.import('@angular/platform-browser-dynamic/testing')
27+
])
28+
// First, initialize the Angular testing environment.
29+
.then(([testing, testingBrowser]) => {
2630
testing.setBaseTestProviders(
2731
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
2832
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
2933
);
30-
});
31-
32-
let testContext: any = require.context('./', true, /\.spec\.ts/);
33-
function requireAll(requireContext: any) {
34-
return requireContext.keys().map(requireContext);
35-
}
36-
37-
requireAll(testContext);
34+
})
35+
// Then we find all the tests.
36+
.then(() => require.context('./', true, /\.spec\.ts/))
37+
// And load the modules.
38+
.then(context => context.keys().map(context))
39+
// Finally, start Karma to run the tests.
40+
.then(__karma__.start, __karma__.error);

0 commit comments

Comments
 (0)