forked from webgme/webgme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-main.js
94 lines (74 loc) · 2.79 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
/*globals require*/
/*jshint browser: true*/
'use strict';
var allTestFiles = [],
TEST_REGEXP = /(spec|test)\.js$/i,
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));
}
});
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base',
paths: {
js: './src/client/js',
client: './node_modules/webgme-engine/src/client',
plugin: './node_modules/webgme-engine/src/plugin',
text: './node_modules/webgme-engine/src/common/lib/requirejs/text',
// plugins
// 'plugin/MinimalWorkingExample': './src/plugin/coreplugins',
executor: './node_modules/webgme-engine/src/common/executor',
blob: './node_modules/webgme-engine/src/common/blob',
common: './node_modules/webgme-engine/src/common',
// common libs
superagent: './node_modules/webgme-engine/src/common/lib/superagent/superagent',
debug: './node_modules/webgme-engine/src/common/lib/debug/debug',
chance: './node_modules/webgme-engine/src/common/lib/chance/chance',
q: './node_modules/webgme-engine/src/common/lib/q/q',
'webgme-ot': './node_modules/webgme-engine/src/common/lib/webgme-ot/webgme-ot',
// webgme app specific libs
jquery: './src/client/bower_components/jquery/dist/jquery',
urlparse: './src/client/lib/purl/purl.min',
karmatest: './test-karma'
},
// dynamically load all test files
deps: allTestFiles,
// we have to kickoff jasmine, as it is asynchronous
callback: testServerConnection
});
function done(err) {
if (err) {
console.error(err);
}
window.__karma__.start();
}
function testServerConnection () {
requirejs(['superagent'], function (superagent) {
var maxTries = 20,
i = 0,
timeout = 300;
function tryToGetGmeConfig() {
console.log('Trying to get gmeConfig.json ... ', i, i * timeout / 1000);
superagent.get('/base/gmeConfig.json')
.end(function (err, res) {
if (res && res.status === 200) {
console.log('Got gmeConfig.json');
done();
} else {
i += 1;
if (i < maxTries) {
setTimeout(tryToGetGmeConfig, timeout);
} else {
done(err, res);
}
}
});
}
tryToGetGmeConfig();
});
}