Skip to content
Browse files

JS tests now run headless via PhantomJS.

- Makefile pulls required PhantomJS distribution and runs QUnit tests.
- Updated contributing doc to reflect new make targets.
- Fixed failing test by mocking call to $.getscript and returning a stub function.
  • Loading branch information...
1 parent 5e286d4 commit 6c3d600d0c2d4591b34b1abfcca2ed280cc410f8 @pads pads committed Aug 8, 2012
Showing with 54 additions and 10 deletions.
  1. +43 −9 Makefile
  2. +3 −1 doc/CONTRIBUTING
  3. +6 −0 src/test/fixtures/requests.js
  4. +2 −0 src/test/index.html
View
52 Makefile
@@ -1,31 +1,48 @@
-.PHONY: test remotes jslib qunit dist release deploy pypi dev clean purge
+.PHONY: test remotes jslib qunit phantomjs jstest pytest dist release deploy pypi dev clean purge
+
+OS := $(shell uname)
+ARCH := $(shell uname -m)
+PHANTOMJS_MAC := phantomjs-1.6.1-macosx-static.zip
+PHANTOMJS_LINUX_32 := phantomjs-1.6.1-linux-i686-dynamic.tar.bz2
+PHANTOMJS_LINUX_64 := phantomjs-1.6.1-linux-x86_64-dynamic.tar.bz2
+ifeq ($(OS), Linux)
+ ifeq ($(ARCH), x86_64)
+ PHANTOMJS_DL := $(PHANTOMJS_LINUX_64)
+ else
+ PHANTOMJS_DL := $(PHANTOMJS_LINUX_32)
+ endif
+endif
+ifeq ($(OS), Darwin)
+ PHANTOMJS_DL := $(PHANTOMJS_MAC)
+endif
wrap_jslib = curl -L -s $(2) | \
{ \
echo "/***"; echo $(2); echo "***/"; \
echo "//{{{"; cat -; echo "//}}}"; \
} > $(1)
-test:
+pytest:
py.test -x test
+
+test: pytest jstest
tiddlywiki:
mkdir src/externals || true
mkdir tiddlywebplugins/tiddlyspace/resources || true
- wget http://tiddlywiki.com/beta/empty.html \
+ wget http://tiddlywiki.github.com/beta/empty.html \
-O tiddlywebplugins/tiddlyspace/resources/beta.html
- wget http://tiddlywiki.com/alpha/empty.html \
+ wget http://tiddlywiki.github.com/alpha/empty.html \
-O tiddlywebplugins/tiddlyspace/resources/alpha.html
- wget http://tiddlywiki.com/alpha/tiddlywiki_externaljs_tiddlyspace.html \
+ wget http://tiddlywiki.github.com/alpha/tiddlywiki_externaljs_tiddlyspace.html \
-O tiddlywebplugins/tiddlyspace/resources/external_alpha.html
- wget http://tiddlywiki.com/alpha/jquery.js \
+ wget http://tiddlywiki.github.com/alpha/jquery.js \
-O src/externals/alpha_jquery.js.js
- wget http://tiddlywiki.com/alpha/jQuery.twStylesheet.js \
+ wget http://tiddlywiki.github.com/alpha/jQuery.twStylesheet.js \
-O src/externals/alpha_jQuery.twStylesheet.js.js
- wget http://tiddlywiki.com/alpha/twcore.js \
+ wget http://tiddlywiki.github.com/alpha/twcore.js \
-O src/externals/alpha_twcore.js.js
-
remotes: tiddlywiki jslib
./cacher
@@ -46,6 +63,8 @@ jslib: qunit
http://jquery-json.googlecode.com/files/jquery.json-2.3.min.js)
$(call wrap_jslib, src/lib/jquery-form.js.js, \
https://raw.github.com/malsup/form/master/jquery.form.js)
+ $(call wrap_jslib, src/lib/jquery.timeago.js.js, \
+ http://timeago.yarp.com/jquery.timeago.js)
qunit:
mkdir -p src/test/qunit
@@ -58,6 +77,20 @@ qunit:
http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js
curl -Lo src/test/lib/jquery-json.js \
http://jquery-json.googlecode.com/files/jquery.json-2.2.js
+ curl -Lo src/test/lib/jquery.mockjax.js \
+ https://raw.github.com/appendto/jquery-mockjax/master/jquery.mockjax.js
+ curl -Lo src/test/run-qunit.js \
+ https://raw.github.com/ariya/phantomjs/1.6/examples/run-qunit.js
+
+phantomjs:
+ wget http://phantomjs.googlecode.com/files/$(PHANTOMJS_DL) \
+ -O phantomjs.tar.bz2
+ tar xjf phantomjs.tar.bz2
+ mv phantomjs-* phantomjs
+
+jstest:
+ @cd phantomjs/bin && \
+ phantomjs ../../src/test/run-qunit.js ../../src/test/index.html
dist: clean remotes test
python setup.py sdist
@@ -93,6 +126,7 @@ clean:
rm -rf tiddlywebplugins/tiddlyspace/resources || true
rm -f src/externals/* || true
rm -r test_instance || true
+ rm -r phantomjs* || true
purge: clean
cat .gitignore | while read -r entry; do rm -r $$entry; done || true
View
4 doc/CONTRIBUTING
@@ -9,9 +9,11 @@ also see STYLE guide
Unit Tests
==========
-* `make test` runs all tests
+* `make test` runs all tests.
+* From scratch you should run `make remotes phantomjs test`
* Python: test directory, using py.test (http://pytest.org)
* JavaScript: src/test directory, using QUnit (http://docs.jquery.com/QUnit)
+* `make jstest` runs the QUnit tests using PhantomJS (http://phantomjs.org/)
Development Instance
====================
View
6 src/test/fixtures/requests.js
@@ -0,0 +1,6 @@
+$.mockjax({
+ url: '/bags/common/tiddlers/_reply-button.js',
+ response: function() {
+ this.responseText = 'function createReplyButton() {}';
+ }
+});
View
2 src/test/index.html
@@ -17,11 +17,13 @@ <h2 id="qunit-userAgent"></h2>
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="lib/jquery-json.js" type="text/javascript"></script>
+ <script src="lib/jquery.mockjax.js" type="text/javascript"></script>
<script src="../lib/chrjs.js" type="text/javascript"></script>
<script src="../lib/chrjs.space.js" type="text/javascript"></script>
<script src="space.js" type="text/javascript"></script>
+ <script src="fixtures/requests.js" type="text/javascript"></script>
<script src="fixtures/tiddlywiki.js" type="text/javascript"></script>
<script src="fixtures/tiddlyweb.js" type="text/javascript"></script>
<script src="fixtures/tiddlyspace.js" type="text/javascript"></script>

0 comments on commit 6c3d600

Please sign in to comment.
Something went wrong with that request. Please try again.