This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test-main.js
74 lines (64 loc) · 1.88 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
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;
});
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: {
'core': bowerPath('marketplace-core-modules/core'),
'jquery': 'lib/jquery',
'Squire': bowerPath('squire/src/Squire'),
'templates': '../../templates',
'tests': '../../../tests',
'underscore': 'lib/underscore',
},
shim: {
'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();
});