From 2ad302a67c05458ffd851838d99153245169ecf9 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sat, 22 Jul 2017 14:14:50 +0700 Subject: [PATCH] Autotests --- Gulpfile.coffee | 23 +++++++++++++---- game/begin.coffee | 38 ++++++++++++++-------------- html/en.html | 6 ++--- html/index.html | 6 ++--- html/test.html | 64 +++++++++++++++++++++++++++++++++++++++++++++++ test/main.js | 36 ++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 html/test.html create mode 100644 test/main.js diff --git a/Gulpfile.coffee b/Gulpfile.coffee index ed1bfc8..171a9bc 100644 --- a/Gulpfile.coffee +++ b/Gulpfile.coffee @@ -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', () -> diff --git a/game/begin.coffee b/game/begin.coffee index 6637c2d..0b82563 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -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() ) diff --git a/html/en.html b/html/en.html index 8e59fc7..bdacd1f 100644 --- a/html/en.html +++ b/html/en.html @@ -74,9 +74,9 @@ - - - + + + diff --git a/html/index.html b/html/index.html index 4c9f922..9830002 100644 --- a/html/index.html +++ b/html/index.html @@ -74,9 +74,9 @@ - - - + + + diff --git a/html/test.html b/html/test.html new file mode 100644 index 0000000..82d91a8 --- /dev/null +++ b/html/test.html @@ -0,0 +1,64 @@ + + + + + + + + + + +
+
+
+
+ +
+
+
+
+ +
+ + +
+
+
+ +
+
+ + + + + + + + + + + + + + diff --git a/test/main.js b/test/main.js new file mode 100644 index 0000000..95305ac --- /dev/null +++ b/test/main.js @@ -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); + } + } + }); +});