Skip to content

Commit

Permalink
Merge pull request #242 from null-a/browser-tests
Browse files Browse the repository at this point in the history
Add basic browser tests.
  • Loading branch information
stuhlmueller committed Oct 7, 2015
2 parents 873bdf4 + e130dd5 commit 611f342
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiled/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SRCFILES = $(wildcard ../src/*.js) \
MAINFILE = ../src/browser.js
MINIFIED = webppl.min.js
BROWSERIFIED = webppl.js
TESTS = ../tests/browser/index.html

all: $(MINIFIED)

Expand All @@ -15,5 +16,8 @@ $(MINIFIED): $(BROWSERIFIED)
$(BROWSERIFIED): $(SRCFILES)
browserify -t brfs $(MAINFILE) > $@

test: $(BROWSERIFIED)
node -e "require('open')(process.argv[1], process.env.BROWSER)" $(TESTS)

clean:
rm -f $(MINIFIED) $(BROWSERIFIED)
15 changes: 13 additions & 2 deletions docs/development/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ many of them automatically using::

To compile webppl for use in browser, run::

npm install -g browserify
browserify -t brfs src/browser.js > compiled/webppl.js
npm install -g browserify uglifyjs
cd compiled
make clean
make

Then, to run the browser tests use::

make test

The tests will run in the default browser. Specify a different browser
using the ``BROWSER`` environment variable. For example::

BROWSER="Google Chrome" make test

Packages can also be used in the browser. For example, to include the
``webppl-viz`` package use::
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-gjslint": "^0.1.6",
"nodeunit": "^0.9.1",
"open": "0.0.5",
"seedrandom": "^2.4.2",
"through2": "^2.0.0"
},
Expand Down
15 changes: 15 additions & 0 deletions tests/browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebPPL</title>
<script src="../../compiled/webppl.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.19.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="http://code.jquery.com/qunit/qunit-1.19.0.js"></script>
<script src="tests.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions tests/browser/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

QUnit.test('run', function(test) {
webppl.run('Enumerate(flip)', function(s, erp) {
test.ok(_.isEqual([false, true], erp.support().sort()));
});
});

QUnit.test('compile', function(test) {
test.ok(_.isString(webppl.compile('1 + 1')));
});

QUnit.test('cps', function(test) {
var code = webppl.cps('100');
eval(code)(function(val) {
test.strictEqual(100, val);
});
});

QUnit.test('naming', function(test) {
var code = webppl.naming('100');
test.strictEqual(100, eval(code)());
});

0 comments on commit 611f342

Please sign in to comment.