-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-main.js
45 lines (37 loc) · 1.09 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
/**
* @file testMain 测试脚本载入器
* @author harttle(harttle@harttle.com)
*/
/* globals mocha: true */
var TEST_FILES = Object.keys(window.__karma__.files).filter(isTestFile);
// 依赖配置
require.config({
baseUrl: '/base/src',
paths: {
test: '/base/test',
'@searchfe': '/base/amd_modules/@searchfe'
}
});
// 启动测试
// Important: 禁用__karma__.loaded(),它会在DOM载入后立即调用 mocha.run()
// 此时esl尚未载入测试脚本。
window.__karma__.loaded = function () {};
// 设置DEBUG环境
window.DEBUG || (window.DEBUG = false);
var mods = TEST_FILES.map(getModuleId);
require(mods, function () {
// eslint-disable-next-line
console.log(mods.length + ' test modules loaded');
mocha.allowUncaught = true;
window.__karma__.start();
// clear mocha listener, since mocha.allowUncaught() not working
window.onerror = null;
});
function isTestFile(filepath) {
return /\/base\/test\//.test(filepath);
}
function getModuleId(filepath) {
// 0123456
// /base/test/xx.js => test/xx
return filepath.slice(6, -3);
}