dcagent
Version:
an analytics sdk for HTML5 app and web game
133 lines (126 loc) • 3.59 kB
HTML
<html>
<head lang="en">
<meta charset="UTF-8">
<title>DCAgent Test Suite</title>
<link rel="shortcut icon" type="image/png" href="./libs/jasmine_favicon.png">
<link rel="stylesheet" href="./libs/jasmine.css">
<style media="screen">
#choice {
margin-bottom: 20px;
padding: 5px;
font-size: 14px;
font-family: Monaco, "Lucida Console", monospace;
line-height: 14px;
color: #333;
}
#choice h1 {
margin-bottom: 20px;
color: #8a4182;
text-align: center;
}
#choice ul {
margin-left: 40px;
margin-bottom: 20px;
}
#choice ul li {
padding: 4px 0;
}
#choice ul li a {
float: right;
margin-right: 60px;
}
#choice * {
margin: 0;
padding: 0;
}
#run_all {
text-align: center;
}
</style>
</head>
<body>
<script>
/* jshint ignore:start */
var DCAGENT_DEBUG_OPEN = true
var ASAP_TIMEOUT = 2000
// 每个Spec开始的时候重新加载SDK避免被上次的结果影响
function loadDCAgent(done) {
var script = document.createElement('script')
script.src = '../dist/dcagent.v2.src.js?v=' + Date.now()
script.setAttribute('id', 'dcagent')
script.onload = done
document.body.appendChild(script)
}
// 每个Spec结束的时候销毁SDK,避免遗漏的Timer影响数据
function destroyDCAgent(done) {
var script = document.querySelector('#dcagent')
document.body.removeChild(script)
DCAgent.destroy()
DCAgent = null
done()
}
var files = [
'test.createRole',
'test.destroy',
'test.init',
'test.login',
'test.onCoinGet',
'test.onCoinUse',
'test.onEvent',
'test.onItemBuy',
'test.onItemProduce',
'test.onItemUse',
'test.onLevelUp',
'test.onMissionFinished',
'test.onMissionUnfinished',
'test.onPayment',
'test.onTaskFinished',
'test.onTaskUnfinished',
'test.rateLimit',
'test.setAccountType',
'test.setAge',
'test.setGameServer',
'test.setGender',
'test.setRoleInfo'
]
document.write('<div id="choice"><h1>Choose Test Suite</h1>')
document.write('<ul>')
files.forEach(function(file) {
document.write('<li><span>' + file + '.js</span> ' +
'<a href="?' + file + '.js">Run</a></li>')
})
document.write('</ul>')
document.write('<div id="run_all"><a href="?all">Run All Tests</a></div></div>')
/* jshint ignore:end */
</script>
<script src="./libs/jasmine.js"></script>
<script src="./libs/jasmine-html.js"></script>
<script src="./libs/boot.js"></script>
<script src="./libs/mock-ajax.js"></script>
<script>
/* jshint ignore:start */
/**
* 这里需要在所有Spec执行前执行,且每个Spec执行的时候不需要uninstall
* node环境里面无所谓因为加载SDK时通过的
* 浏览器里面比较特殊,异步容易相互影响。
* 所以clock提前设置好避免出现不必要的BUG
*/
jasmine.clock().install()
// 这里也必须mockDate,不然有些Spec会失败
jasmine.clock().mockDate(new Date(2015, 11, 1))
var currentFile = location.search.slice(1)
// 执行单个spec
if (currentFile.indexOf('.js') !== -1) {
document.write('<script src="src/' + currentFile + '"><' + '/script>')
document.title = 'Running ' + currentFile
} else if (currentFile.indexOf('all') > -1) {
files.forEach(function(file) {
document.write('<script src="src/' + file + '.js"><' + '/script>')
})
document.title = 'Running all tests'
}
/* jshint ignore:end */
</script>
</body>
</html>