|
1 | | -var TEST_REGEXP = /_spec.*/; |
2 | | - |
3 | | -Object.keys(window.__karma__.files).forEach(function(path) { |
4 | | - if (TEST_REGEXP.test(path)) { |
5 | | - var moduleName = window.file2moduleName(path); |
6 | | - var mod = System.get(moduleName); |
7 | | - if (mod && mod.main) { |
8 | | - mod.main(); |
9 | | - } |
10 | | - } |
| 1 | +// Use "register" extension from systemjs. |
| 2 | +// That's what Traceur outputs: `System.register()`. |
| 3 | +register(System); |
| 4 | + |
| 5 | + |
| 6 | +// Cancel Karma's synchronous start, |
| 7 | +// we will call `__karma__.start()` later, once all the specs are loaded. |
| 8 | +__karma__.loaded = function() {}; |
| 9 | + |
| 10 | + |
| 11 | +System.baseURL = '/base/modules/'; |
| 12 | + |
| 13 | +// So that we can import packages like `core/foo`, instead of `core/src/foo`. |
| 14 | +System.paths = { |
| 15 | + 'core/*': './core/src/*.js', |
| 16 | + 'core/test/*': './core/test/*.js', |
| 17 | + |
| 18 | + 'change_detection/*': './change_detection/src/*.js', |
| 19 | + 'change_detection/test/*': './change_detection/test/*.js', |
| 20 | + |
| 21 | + 'facade/*': './facade/src/*.js', |
| 22 | + 'facade/test/*': './facade/test/*.js', |
| 23 | + |
| 24 | + 'di/*': './di/src/*.js', |
| 25 | + 'di/test/*': './di/test/*.js', |
| 26 | + |
| 27 | + 'rtts_assert/*': './rtts_assert/src/*.js', |
| 28 | + 'rtts_assert/test/*': './rtts_assert/test/*.js', |
| 29 | + |
| 30 | + 'test_lib/*': './test_lib/src/*.js', |
| 31 | + 'test_lib/test/*': './test_lib/test/*.js', |
| 32 | + |
| 33 | + 'transpiler/*': '../tools/transpiler/*.js' |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +// Import all the specs, execute their `main()` method and kick off Karma (Jasmine). |
| 38 | +Promise.all( |
| 39 | + Object.keys(window.__karma__.files) // All files served by Karma. |
| 40 | + .filter(onlySpecFiles) |
| 41 | + .map(window.file2moduleName) // Normalize paths to module names. |
| 42 | + .map(function(path) { |
| 43 | + return System.import(path).then(function(module) { |
| 44 | + if (module.hasOwnProperty('main')) { |
| 45 | + module.main() |
| 46 | + } else { |
| 47 | + throw new Error('Module ' + path + ' does not implement main() method.'); |
| 48 | + } |
| 49 | + }); |
| 50 | + })).then(function() { |
| 51 | + __karma__.start(); |
| 52 | +}, function(error) { |
| 53 | + console.error(error.stack || error) |
| 54 | + __karma__.start(); |
11 | 55 | }); |
| 56 | + |
| 57 | + |
| 58 | +function onlySpecFiles(path) { |
| 59 | + return /_spec\.js$/.test(path); |
| 60 | +} |
0 commit comments