From 0bad58abe31df4495984865965028d87ecf97665 Mon Sep 17 00:00:00 2001 From: Pelle Nilsson Date: Sun, 16 Jun 2013 09:41:32 +0200 Subject: [PATCH] Stubs for testing html template javascript using node.js. --- .gitignore | 3 ++- Makefile | 12 ++++++++++-- readme.org | 19 +++++++++++++++++++ templates/html/script.html | 6 ++++++ test/templatejs/.gitignore | 1 + test/templatejs/testhtmlscripts.js | 17 +++++++++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/templatejs/.gitignore create mode 100755 test/templatejs/testhtmlscripts.js diff --git a/.gitignore b/.gitignore index 312d250..9e7cf02 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ test.html target *.map .uploadto -readme.html \ No newline at end of file +readme.html +node_modules \ No newline at end of file diff --git a/Makefile b/Makefile index feb018a..18da4e3 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ readme.html: readme.org %.png: %.dot dot -Tpng $< > $@ -test: unittest checkexpected +test: unittest checkexpected templatejstest expected: all $(RM) expected/* && cp examples/*.{rtf,tex,html,debug,txt,dot,map} \ @@ -55,9 +55,17 @@ unittest: *.py upload: html png pdf rtf if [ -n "$(uploadto)" ]; then \ - scp examples/*.html examples/*.png examples/*.pdf examples/*.rtf $(uploadto);\ + scp examples/*.html examples/*.png examples/*.pdf examples/*.rtf \ + $(uploadto);\ fi +test/templatejs/htmlscripts.js: $(wildcard templates/html/*script.html) + ./templates.py html script > $@ + +templatejstest: test/templatejs/htmlscripts.js \ + test/templatejs/testhtmlscripts.js + node test/templatejs/testhtmlscripts.js + clean: $(RM) examples/*rtf examples/*.html examples/*.tex \ examples/*.txt examples/*.debug examples/*.log \ diff --git a/readme.org b/readme.org index 1aada26..64004f7 100644 --- a/readme.org +++ b/readme.org @@ -43,6 +43,25 @@ configuration (eg /C-c C-q/ to edit section tags). References to sections can be followed using /C-c C-o/ while editing the book in org-mode. +** Dependencies + +*** Required +- Python 2.7 :: To run formatgamebook.py. + +*** Optional +To make something useful from some of the outputted files. +- pdflatex :: Make pdf from tex files. +- Graphviz :: Includes the dot command that can make images from dot files. + +*** Development +The following are only needed for working on improving +the scripts (and even then you can proabbly do without all or most). +- GNU make :: Runs tests and various other useful development tasks. + (This in turn depends on some tools like diff, but if you + have make installed you probably have them as well.) +- node.js :: To run some tests of HTML (JavaScript) templates. +- nodeunit :: Unit test framework for node.js. + ** License Copyright (c) 2013 Pelle Nilsson diff --git a/templates/html/script.html b/templates/html/script.html index 1082c96..b9ca4a5 100644 --- a/templates/html/script.html +++ b/templates/html/script.html @@ -3,3 +3,9 @@ #include "extra-gamebookscript" }; +// little hack to make easy to test from node.js +if (typeof exports !== 'undefined') { + exports.gamebook = gamebook; +} + + diff --git a/test/templatejs/.gitignore b/test/templatejs/.gitignore new file mode 100644 index 0000000..6c78d37 --- /dev/null +++ b/test/templatejs/.gitignore @@ -0,0 +1 @@ +htmlscripts.js diff --git a/test/templatejs/testhtmlscripts.js b/test/templatejs/testhtmlscripts.js new file mode 100755 index 0000000..ea66cfc --- /dev/null +++ b/test/templatejs/testhtmlscripts.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +exports.setUp = function(cb) { + this.hs = hs = require('./htmlscripts.js'); + cb(); +}; + +exports.test1 = function(test) { + test.deepEqual(this.hs.gamebook.player.collections, {}); + test.done(); +}; + +var reporter = require('nodeunit').reporters['default']; + +process.chdir(__dirname); +reporter.run(['./testhtmlscripts.js']); +