|
1 |
| -/*global jasmine, __karma__, window*/ |
2 |
| -(function () { |
3 |
| - |
4 |
| -// Error.stackTraceLimit = Infinity; |
5 |
| - |
| 1 | +// /*global jasmine, __karma__, window*/ |
| 2 | +Error.stackTraceLimit = Infinity; |
6 | 3 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
|
7 | 4 |
|
8 |
| -// Cancel Karma's synchronous start, |
9 |
| -// we call `__karma__.start()` later, once all the specs are loaded. |
10 |
| -__karma__.loaded = function () { }; |
11 |
| - |
12 |
| -// SET THE RUNTIME APPLICATION ROOT HERE |
13 |
| -var appRoot ='app'; // no trailing slash! |
14 |
| - |
15 |
| -// RegExp for client application base path within karma (which always starts 'base\') |
16 |
| -var karmaBase = '^\/base\/'; // RegEx string for base of karma folders |
17 |
| -var appPackage = 'base/' + appRoot; //e.g., base/app |
18 |
| -var appRootRe = new RegExp(karmaBase + appRoot + '\/'); |
19 |
| -var onlyAppFilesRe = new RegExp(karmaBase + appRoot + '\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$'); |
20 |
| - |
21 |
| -var moduleNames = []; |
22 |
| - |
23 |
| -// Configure systemjs packages to use the .js extension for imports from the app folder |
24 |
| -var packages = {}; |
25 |
| -packages[appPackage] = { |
26 |
| - defaultExtension: false, |
27 |
| - format: 'register', |
28 |
| - map: Object.keys(window.__karma__.files) |
29 |
| - .filter(onlyAppFiles) |
30 |
| - // Create local module name mapping to karma file path for app files |
31 |
| - // with karma's fingerprint in query string, e.g.: |
32 |
| - // './hero.service': '/base/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e' |
33 |
| - .reduce(function (pathsMapping, appPath) { |
34 |
| - var moduleName = appPath.replace(appRootRe, './').replace(/\.js$/, ''); |
35 |
| - pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]; |
36 |
| - return pathsMapping; |
37 |
| - }, {}) |
38 |
| - } |
39 |
| - |
40 |
| -System.config({ packages: packages }); |
41 |
| - |
42 |
| -// Configure Angular for the browser and |
43 |
| -// with test versions of the platform providers |
44 |
| - Promise.all([ |
45 |
| - System.import('angular2/testing'), |
46 |
| - System.import('angular2/platform/testing/browser') |
47 |
| - ]) |
48 |
| - .then(function (results) { |
49 |
| - var testing = results[0]; |
50 |
| - var browser = results[1]; |
51 |
| - testing.setBaseTestProviders( |
52 |
| - browser.TEST_BROWSER_PLATFORM_PROVIDERS, |
53 |
| - browser.TEST_BROWSER_APPLICATION_PROVIDERS); |
54 |
| - |
55 |
| - // Load all spec files |
56 |
| - // (e.g. 'base/app/hero.service.spec.js') |
57 |
| - return Promise.all( |
58 |
| - Object.keys(window.__karma__.files) |
59 |
| - .filter(onlySpecFiles) |
60 |
| - .map(function (moduleName) { |
61 |
| - moduleNames.push(moduleName); |
62 |
| - return System.import(moduleName); |
63 |
| - })); |
64 |
| - }) |
65 |
| - |
66 |
| - .then(success, fail); |
67 |
| - |
68 |
| -////// Helpers ////// |
69 |
| - |
70 |
| -function onlyAppFiles(filePath) { |
71 |
| - return onlyAppFilesRe.test(filePath); |
| 5 | +__karma__.loaded = function () { |
| 6 | +}; |
| 7 | + |
| 8 | +function isJsFile(path) { |
| 9 | + return path.slice(-3) == '.js'; |
72 | 10 | }
|
73 | 11 |
|
74 |
| -function onlySpecFiles(filePath) { |
75 |
| - return /\.spec\.js$/.test(filePath); |
| 12 | +function isSpecFile(path) { |
| 13 | + return /\.spec\.js$/.test(path); |
76 | 14 | }
|
77 | 15 |
|
78 |
| -function success () { |
79 |
| - console.log( |
80 |
| - 'Spec files loaded:\n ' + |
81 |
| - moduleNames.join('\n ') + |
82 |
| - '\nStarting Jasmine testrunner'); |
83 |
| - __karma__.start(); |
| 16 | +function isBuiltFile(path) { |
| 17 | + var builtPath = '/base/app/'; |
| 18 | + return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath); |
84 | 19 | }
|
85 | 20 |
|
86 |
| -function fail(error) { |
87 |
| - __karma__.error(error.stack || error); |
| 21 | +var allSpecFiles = Object.keys(window.__karma__.files) |
| 22 | + .filter(isSpecFile) |
| 23 | + .filter(isBuiltFile); |
| 24 | + |
| 25 | +////////////////////////// |
| 26 | +// Load our SystemJS configuration. |
| 27 | + |
| 28 | +// map tells the System loader where to look for things |
| 29 | +var map = { |
| 30 | + 'app': 'app', |
| 31 | + |
| 32 | + '@angular': 'node_modules/@angular', |
| 33 | + 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', |
| 34 | + 'rxjs': 'node_modules/rxjs' |
| 35 | +}; |
| 36 | + |
| 37 | +// packages tells the System loader how to load when no filename and/or no extension |
| 38 | +var packages = { |
| 39 | + 'app': { main: 'main.js', defaultExtension: 'js' }, |
| 40 | + 'rxjs': { defaultExtension: 'js' }, |
| 41 | + 'angular2-in-memory-web-api': { defaultExtension: 'js' }, |
| 42 | +}; |
| 43 | + |
| 44 | +var ngPackageNames = [ |
| 45 | + 'common', |
| 46 | + 'compiler', |
| 47 | + 'core', |
| 48 | + 'http', |
| 49 | + 'platform-browser', |
| 50 | + 'platform-browser-dynamic', |
| 51 | + 'router', |
| 52 | + 'router-deprecated', |
| 53 | + 'upgrade', |
| 54 | +]; |
| 55 | + |
| 56 | +// Add package entries for angular packages |
| 57 | +ngPackageNames.forEach(function(pkgName) { |
| 58 | + |
| 59 | + // Bundled (~40 requests): DOESN'T WORK IN KARMA OR WALLABY (YET?) |
| 60 | + //packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' }; |
| 61 | + |
| 62 | + // Individual files (~300 requests): |
| 63 | + packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; |
| 64 | +}); |
| 65 | + |
| 66 | +var config = { |
| 67 | + baseURL: '/base', |
| 68 | + map: map, |
| 69 | + packages: packages |
88 | 70 | }
|
89 | 71 |
|
90 |
| -})(); |
| 72 | +System.config(config); |
| 73 | +////////////// |
| 74 | + |
| 75 | +Promise.all([ |
| 76 | + System.import('@angular/core/testing'), |
| 77 | + System.import('@angular/platform-browser-dynamic/testing') |
| 78 | +]).then(function (providers) { |
| 79 | + var testing = providers[0]; |
| 80 | + var testingBrowser = providers[1]; |
| 81 | + |
| 82 | + testing.setBaseTestProviders( |
| 83 | + 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); |
0 commit comments