UNPKG

4.21 kBJavaScriptView Raw
1/*global jasmine, __karma__, window*/
2Error.stackTraceLimit = Infinity;
3jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
4
5__karma__.loaded = function () {
6};
7
8
9function isJsFile(path) {
10 return path.slice(-3) == '.js';
11}
12
13function isSpecFile(path) {
14 return path.slice(-8) == '.spec.js';
15}
16
17function isBuiltFile(path) {
18 var builtPath = '/base/src/';
19 return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
20}
21
22var allSpecFiles = Object.keys(window.__karma__.files)
23 .filter(isSpecFile)
24 .filter(isBuiltFile);
25
26// Load our SystemJS configuration.
27System.config({
28 baseURL: '/base'
29});
30
31System.config({
32 map: {
33 'rxjs': 'node_modules/rxjs',
34 '@angular': 'node_modules/@angular',
35 'app': 'src'
36 },
37 packages: {
38 'app': {
39 main: 'main.js',
40 defaultExtension: 'js'
41 },
42 '@angular/core': {
43 main: 'index.js',
44 defaultExtension: 'js'
45 },
46 '@angular/compiler': {
47 main: 'index.js',
48 defaultExtension: 'js'
49 },
50 '@angular/common': {
51 main: 'index.js',
52 defaultExtension: 'js'
53 },
54 '@angular/platform-browser': {
55 main: 'index.js',
56 defaultExtension: 'js'
57 },
58 '@angular/platform-browser-dynamic': {
59 main: 'index.js',
60 defaultExtension: 'js'
61 },
62 // '@angular/router-deprecated': {
63 // main: 'index.js',
64 // defaultExtension: 'js'
65 // },
66 // '@angular/router': {
67 // main: 'index.js',
68 // defaultExtension: 'js'
69 // },
70 'rxjs': {
71 defaultExtension: 'js'
72 }
73 }
74});
75//
76// Promise.all([
77// // System.import('@angular/core/testing'),
78// System.import('@angular/platform-browser-dynamic/testing')
79// ]).then(function (providers) {
80// var testing = providers[0];
81// var testingBrowser = providers[1];
82//
83// testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
84// testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
85//
86// }).then(function() {
87// // Finally, load all spec files.
88// // This will run the tests directly.
89// return Promise.all(
90// allSpecFiles.map(function (moduleName) {
91// return System.import(moduleName);
92// }));
93// }).then(__karma__.start, __karma__.error);
94
95// Tun on full stack traces in errors to help debugging
96// Error.stackTraceLimit = Infinity;
97//
98// jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
99//
100// // // Cancel Karma's synchronous start,
101// // // we will call `__karma__.start()` later, once all the specs are loaded.
102// __karma__.loaded = function() {};
103//
104// System.config({
105// packages: {
106// 'base/dist': {
107// defaultExtension: false,
108// format: 'cjs',
109// map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
110// }
111// }
112// });
113
114System.import('@angular/core/testing')
115 // .then(function(browser_adapter) { browser_adapter.BrowserDomAdapter.makeCurrent(); })
116 .then(function() { return Promise.all(resolveTestFiles()); })
117 .then(function() { __karma__.start(); }, function(error) { __karma__.error(error.stack || error); });
118
119// function createPathRecords(pathsMapping, appPath) {
120// // creates local module name mapping to global path with karma's fingerprint in path, e.g.:
121// // './vg-player/vg-player':
122// // '/base/dist/vg-player/vg-player.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
123// var pathParts = appPath.split('/');
124// var moduleName = './' + pathParts.slice(Math.max(pathParts.length - 2, 1)).join('/');
125// moduleName = moduleName.replace(/\.js$/, '');
126// pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
127// return pathsMapping;
128// }
129//
130// function onlyAppFiles(filePath) {
131// return /\/base\/dist\/(?!.*\.spec\.js$).*\.js$/.test(filePath);
132// }
133
134function onlySpecFiles(path) {
135 return /\.spec\.js$/.test(path);
136}
137
138function resolveTestFiles() {
139 return Object.keys(window.__karma__.files) // All files served by Karma.
140 .filter(onlySpecFiles)
141 .filter(isBuiltFile)
142 .map(function(moduleName) {
143 // loads all spec files via their global module names (e.g.
144 // 'base/dist/vg-player/vg-player.spec')
145 return System.import(moduleName);
146 });
147}