forked from BTMorton/angular2-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-main.js
56 lines (51 loc) · 1.84 KB
/
test-main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* global System */
/* global __karma__ */
/* global System */
/* global __karma__ */
// Cancel Karma's synchronous start,
// we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function () { };
// Set the base url of our scripts
System.baseURL = '/base/';
// Here we set all the preffixes so that we'll
// be able for example to import 'test/test_name'
// instead of 'scripts/build/test_name'
System.defaultJSExtensions = true;
System.config({
paths: {
'angular2/*': 'node_modules/angular2/*'
},
packages: {
'dist': {defaultExtension: 'js', format: 'register'},
'test': {defaultExtension: 'js', format: 'register'}
}
})
// paths that include spec and ends with .js
function onlySpecFiles(path) {
return /spec\.js$/.test(path);
}
// takes paths and normalize them to module names
// by removing a base url preffix and .js suffix
function karmaFileToModule(fileName) {
return fileName.replace(System.baseURL, '')
.replace('.js', '');
}
Promise.all(
Object.keys(window.__karma__.files) // Takes all files that served by karma
.filter(onlySpecFiles) // choose only test files
.map(karmaFileToModule) // normalize them to module names
.map(function (moduleName) {
return System.import(moduleName) // import each module
.then(function (module) {
if (module.hasOwnProperty('main')) {
module.main(); //expose the tests
} else {
throw new Error('Module ' + moduleName + ' does not implement main() method.');
}
});
})).then(function () {
__karma__.start(); // after all tests were exposed
}, function (error) {
console.error(error.stack || error);
__karma__.start();
});