forked from willmruzek/starter-backbone-requirejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-test.js
63 lines (53 loc) · 1.62 KB
/
main-test.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
57
58
59
60
61
62
63
/**
* This is entry-point for testing with karma-runner and requirejs
* based on sinpped from: http://karma-runner.github.io/0.8/plus/RequireJS.html
*/
(function() {
var allTestFiles = null;
var baseUrl = '';
var requirejsCallback = null;
var TEST_REGEXP = /\.spec\.js$/;
var pathToModule = function(path) {
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};
// if invoked in karma-runner environment
if (typeof window != 'undefined' && window.__karma__ != undefined) {
// Karma serves files from '/base'
baseUrl = '/base';
requirejsCallback = window.__karma__.start;
// looking for *.spec.js files
allTestFiles = [];
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
}
});
}
requirejs.config({
baseUrl: baseUrl,
paths : {
'text': 'vendor/requirejs-text/text',
'jquery': 'vendor/jquery/jquery',
'underscore': 'vendor/underscore/underscore',
'backbone': 'vendor/backbone/backbone',
'chai': 'node_modules/chai/chai'
},
shim : {
'jquery' : {
exports : 'jQuery'
},
'underscore' : {
exports : '_'
},
'backbone' : {
deps : ['jquery', 'underscore'],
exports : 'Backbone'
}
},
// ask Require.js to load these files (all our tests)
deps: allTestFiles,
// start test run, once Require.js is done
callback: requirejsCallback
});
})();