forked from mozilla/fireplace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-main.js
103 lines (92 loc) · 2.86 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var allTestFiles = ['init'];
var TEST_REGEXP = /tests\/.*\.js$/i;
// Automatically clenaup sinon spies and stubs.
var realSinon = sinon;
beforeEach(function() {
sinon = realSinon.sandbox.create();
});
afterEach(function() {
sinon.restore();
sinon = realSinon;
// Ensure that body is empty for the next test.
Array.prototype.forEach.call(document.body.children, function(child) {
document.body.removeChild(child);
});
});
function withSettings(changes, test) {
var settings = require('core/settings');
var changed = {};
Object.keys(changes).forEach(function(key) {
// Remember if it exists so we can delete it if it doesn't.
if (key in settings) {
changed[key] = settings[key];
}
settings[key] = changes[key];
});
test();
Object.keys(changes).forEach(function(key) {
if (key in changed) {
settings[key] = changed[key];
} else {
delete settings[key];
}
});
}
var pathToModule = function(path) {
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
}
});
function bowerPath(path) {
return '../../../bower_components/' + path;
}
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/src/media/js',
paths: {
'carriers': 'lib/carriers',
'collection_colors': 'lib/collection_colors',
'core': bowerPath('marketplace-core-modules/core'),
'document-register-element': 'lib/document-register-element.max',
'flipsnap': 'lib/flipsnap',
'fxpay': 'lib/fxpay.min',
'jquery': 'lib/jquery',
'marketplace-elements': 'lib/marketplace-elements',
'regions': 'lib/regions',
'salvattore': 'lib/salvattore',
'Squire': bowerPath('squire/src/Squire'),
'templates': '../../templates',
'tests': '../../../tests',
'underscore': 'lib/underscore',
},
shim: {
'document-register-element': {
'exports': 'window.document.registerElement'
},
'flipsnap': {
'exports': 'Flipsnap'
},
'fxpay': {
'exports': 'fxpay'
},
'marketplace-elements': {
'exports': 'window.document.registerElement',
'deps': ['document-register-element'],
},
'salvattore': {
'exports': 'salvattore'
},
'underscore': {
'exports': '_',
},
},
});
// Using this instead of `deps` and `callback` in the `require.config` seems to
// prevent Squire from causing tests to run twice.
require(allTestFiles, function() {
window.__karma__.start();
});