This repository was archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathtests-main-compiled.js
More file actions
89 lines (75 loc) · 2.73 KB
/
tests-main-compiled.js
File metadata and controls
89 lines (75 loc) · 2.73 KB
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
/**
* Monkey patching for RequireJS 'define' method in order to remove ^app/ substring in
* dependency path for controllers, filters, services and directives.
*/
(function (global) {
var original_define = global.define;
// reg exp for testing if dependency is app file
var isAppFile = /^Source\//;
// Override
global.define = function (name, deps, callback) {
var args = Array.prototype.slice.apply(arguments);
// Process only anonymous definitions
if (args.length != 2) {
return original_define.apply(null, args);
}
// basically deps and callback are defined only for specs for testing
var deps = args[0], callback = args[1];
if (deps instanceof Array && typeof callback == "function") {
for (var i = 0; i < deps.length; i++) {
if (isAppFile.test(deps[i])) {
deps[i] = deps[i].replace('Source/', 'js/');
}
}
}
original_define.apply(null, args);
};
// Enable AMD mode
// Without this code line libs such as 'moment' or 'accounting' aren't being loaded
// when we try to run tests for compiled .js file
global.define.amd = original_define.amd;
})(this);
/**
* another one monkey patch to prevent "no timestamp" error
* https://github.com/karma-runner/karma-requirejs/issues/6#issuecomment-23037725
*/
(function (global) {
var fileWithoutLeadingSlash;
// array where all spec files will be included
global.tests = [];
for (var file in global.__karma__.files) {
if (global.__karma__.files.hasOwnProperty(file)) {
// get rid of leading slash in file path - prevents "no timestamp" error
fileWithoutLeadingSlash = file.replace(/^\//, '');
global.__karma__.files[fileWithoutLeadingSlash] = global.__karma__.files[file];
delete global.__karma__.files[file];
// we get all the test files automatically and store to window.tests array
if (/spec\.js$/.test(fileWithoutLeadingSlash)) {
global.tests.push(fileWithoutLeadingSlash);
}
}
}
}(this));
require(['base/source/js/config-require'], function (config) {
// improve config
config.baseUrl = 'base/build/';
config.deps = ['require', './js/main'];
config.callback = function (require) {
// to ensure that source is already loaded before tests are tried to run
require(
// array with all spec files
window.tests,
// callback
window.__karma__.start
);
};
// adapt paths to work with built app
for (var i in config.paths) {
config.paths[i] = config.paths[i].replace('../vendor', './vendor');
}
// add config for test dependencies
config.paths['angular-mocks'] = './vendor/angular-mocks/angular-mocks';
config.shim['angular-mocks'] = ['angular'];
// apply config to require
window.require.config(config);
});