Autotests

This commit is contained in:
Alexander Yakovlev 2017-07-22 14:14:50 +07:00
parent c9bd8f7a8a
commit 2ad302a67c
6 changed files with 143 additions and 30 deletions

View File

@ -12,9 +12,15 @@ CSON = require 'cson'
reload = browserSync.reload
html = (target) ->
html = (target, debug) ->
return () ->
gulp.src(['html/*.html'])
sources = [
'html/index.html'
'html/en.html'
]
if (debug)
sources.push('html/test.html')
gulp.src(sources)
.pipe(gulp.dest(target))
gulp.src(['node_modules/salet/lib/index.min.js'])
.pipe(rename('salet.min.js'))
@ -39,7 +45,7 @@ translations = (target) ->
json = JSON.stringify(data) + '\n'
fs.writeFileSync(target+"/translations/"+language+".json", json)
gulp.task('html', html('./build'))
gulp.task('html', html('./build', true))
gulp.task('img', img('./build/img'))
gulp.task('audio', audio('./build/audio'))
gulp.task('translations', translations('./build/game'))
@ -51,6 +57,12 @@ gulp.task('sass', () ->
.pipe(gulp.dest('./build/css'))
)
# Autotests
gulp.task('tests', () ->
gulp.src('test/*.js')
.pipe(gulp.dest('./build/test/'))
)
gulp.task('concatCoffee', () ->
gulp.src([
## additional functions
@ -73,7 +85,8 @@ gulp.task('build', [
'sass',
'coffee',
'audio',
'translations'
'translations',
'tests'
])
gulp.task('serve', ['build'], () ->
@ -100,7 +113,7 @@ gulp.task('serve', ['build'], () ->
browserSync.reload)
)
gulp.task('html-dist', html('./dist'))
gulp.task('html-dist', html('./dist', false))
gulp.task('img-dist', img('./dist/img'))
gulp.task('audio-dist', audio('./dist/audio'))
gulp.task('legal-dist', () ->

View File

@ -64,25 +64,25 @@ $(document).ready(() ->
TogetherJS.send(options)
)
window.remote = false
TogetherJS.config("ignoreForms", true)
TogetherJS.config("ignoreMessages", [
"cursor-update"
"keydown"
"scroll-update"
"form-focus"
"cursor-click"
])
TogetherJS.hub.on("click", (msg) ->
if (! msg.sameUrl)
return
window.remote = true
if msg.id != undefined
$("##{msg.id}").trigger("click")
else if msg.href != undefined
$("#page a[href=#{msg.href}]").trigger("click")
window.remote = false
)
if (window.hasOwnProperty('TogetherJS'))
TogetherJS.config("ignoreForms", true)
TogetherJS.config("ignoreMessages", [
"cursor-update"
"keydown"
"scroll-update"
"form-focus"
"cursor-click"
])
TogetherJS.hub.on("click", (msg) ->
if (! msg.sameUrl)
return
window.remote = true
if msg.id != undefined
$("##{msg.id}").trigger("click")
else if msg.href != undefined
$("#page a[href=#{msg.href}]").trigger("click")
window.remote = false
)
salet.beginGame()
)

View File

@ -74,9 +74,9 @@
</div> <!-- End of div.page -->
<!-- CDN JS Libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js" integrity="sha256-SRRubnX77KKxTl1/uluP1zGweVqx3pTO7aEaTecZB4g=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js"></script>
<script src="game/salet.min.js"></script>
<script src="https://togetherjs.com/togetherjs-min.js"></script>

View File

@ -74,9 +74,9 @@
</div> <!-- End of div.page -->
<!-- CDN JS Libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js" integrity="sha256-SRRubnX77KKxTl1/uluP1zGweVqx3pTO7aEaTecZB4g=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js"></script>
<script src="game/salet.min.js"></script>
<script src="https://togetherjs.com/togetherjs-min.js"></script>

64
html/test.html Normal file
View File

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.3.3.css">
<style>#page{display: none}</style>
</head>
<body>
<div id="page">
<div class="container">
<div class="row">
<div class='ways'>
<ul class="nav nav-pills" id="ways">
</ul>
</div>
</div> <!-- End of div.tools_wrapper -->
<div id="content_wrapper">
<div id="content" class="content narrow">
<noscript>This game requires Javascript.</noscript>
</div>
<div class="sidebar">
<div class="ui">
<a href="#" id="storytab" class="tab active"></a>
<a href="inventory" id="chartab" class="tab"></a>
<a href="map" id="maptab" class="tab"></a>
</div>
<div class="action">
<div class="verb" data-verb="examine">Examine</div>
<ul class="objects" id="examinelist" data-verb="examine">
</ul>
<div class="verb" data-verb="take">Take</div>
<ul class="objects" id="takelist" data-verb="take">
</ul>
<div class="verb" data-verb="drop">Drop</div>
<ul class="objects" id="droplist" data-verb="drop">
</ul>
<div class="verb" data-verb="wear">Wear</div>
<ul class="objects" id="wearlist" data-verb="wear">
</ul>
</div>
</div>
<a name="end_of_content"></a>
</div>
</div>
</div> <!-- End of div.page -->
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<!-- Dependency JS Libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js"></script>
<script src="https://code.jquery.com/qunit/qunit-2.3.3.js"></script>
<script src="game/salet.min.js"></script>
<script src="game/main.js"></script>
<script defer="defer" src="test/main.js"></script>
</body>
</html>

36
test/main.js Normal file
View File

@ -0,0 +1,36 @@
salet.autosave = false;
salet.autoload = false;
$(document).ready(function() {
QUnit.test("The game starts okay.", function(assert) {
assert.notEqual(salet, void 0, "Salet is initialized");
return assert.equal(salet.current, "start", "Salet is in the room called 'start'");
});
QUnit.test("There are no game-breaking bugs when entering rooms.", function(assert) {
for (var key in salet.rooms) {
// skip loop if the property is from prototype
if (!salet.rooms.hasOwnProperty(key)) continue;
var room = salet.rooms[key];
assert.ok(salet.goTo(room.name), "Entered room "+room.name);
}
});
QUnit.test("There are no game-breaking bugs in all actions.", function(assert) {
for (var key in salet.rooms) {
// skip loop if the property is from prototype
if (!salet.rooms.hasOwnProperty(key)) continue;
var room = salet.rooms[key];
salet.goTo(room.name);
for (var act in room.actions) {
if (!room.actions.hasOwnProperty(act)) continue;
assert.ok(act.fcall(room), "Executed action "+act);
}
for (var act in room.writers) {
if (!room.writers.hasOwnProperty(act)) continue;
assert.ok(act.fcall(room), "Executed action "+act);
}
}
});
});