# HG changeset patch # User Drew Perttula # Date 2016-06-05 22:41:04 # Node ID 168262618f2d88c4b32e2e5528ba4c060d2f8372 # Parent c20dc52e5593a84bbe3d51d5d54ea0652981ca42 new test_js target for testing SyncedGraph Ignore-this: fda788c5e8f5cf1190eb383e1cf2b1ad diff --git a/light9/web/graph.coffee b/light9/web/graph.coffee --- a/light9/web/graph.coffee +++ b/light9/web/graph.coffee @@ -3,6 +3,13 @@ log = console.log # Patch is {addQuads: , delQuads: } # is [{subject: s, ...}, ...] +# for mocha +if require? + `window = {}` + `N3 = require('./lib/N3.js-1d2d975c10ad3252d38393c3ea97b36fd3ab986a/N3.js')` + `RdfDbClient = require('./rdfdbclient.js').RdfDbClient` + module.exports = window + # (sloppily shared to rdfdbclient.coffee too) window.patchSizeSummary = (patch) -> '-' + patch.delQuads.length + ' +' + patch.addQuads.length @@ -60,8 +67,9 @@ class window.SyncedGraph @_watchers = new GraphWatchers() @clearGraph() - @_client = new RdfDbClient(@patchSenderUrl, @clearGraph.bind(@), - @_applyPatch.bind(@), @setStatus) + if @patchSenderUrl + @_client = new RdfDbClient(@patchSenderUrl, @clearGraph.bind(@), + @_applyPatch.bind(@), @setStatus) clearGraph: -> log('SyncedGraph clear') diff --git a/light9/web/graph_test.coffee b/light9/web/graph_test.coffee new file mode 100644 --- /dev/null +++ b/light9/web/graph_test.coffee @@ -0,0 +1,10 @@ +assert = require('chai').assert +SyncedGraph = require('./graph.js').SyncedGraph + +describe 'SyncedGraph', -> + describe 'constructor', -> + it 'should successfully make an empty graph without connecting to rdfdb', -> + g = new SyncedGraph() + g.quads() + assert.equal(g.quads().length, 0) + diff --git a/light9/web/rdfdbclient.coffee b/light9/web/rdfdbclient.coffee --- a/light9/web/rdfdbclient.coffee +++ b/light9/web/rdfdbclient.coffee @@ -1,5 +1,11 @@ log = console.log +# for mocha +if require? + `window = {}` + `N3 = require('./lib/N3.js-1d2d975c10ad3252d38393c3ea97b36fd3ab986a/N3.js')` + module.exports = window + toJsonPatch = (jsPatch, cb) -> out = {patch: {adds: '', deletes: ''}} diff --git a/makefile b/makefile --- a/makefile +++ b/makefile @@ -10,6 +10,13 @@ tests_watch: tests_coverage: eval env/bin/nosetests --with-coverage --cover-erase --cover-html --cover-html-dir=/tmp/light9-cov/ --cover-package=light9 --cover-branches $(NOSEARGS) +test_js_init: + npm install + +test_js: + coffee -c light9/web/*.coffee + node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --globals window,N3 light9/web/graph_test.coffee + # needed packages: python-gtk2 python-imaging binexec: diff --git a/package.json b/package.json new file mode 100644 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "light9", + "version": "1.0.0", + "description": "Mini instructions:", + "main": "index.js", + "directories": { + "test": "test" + }, + "dependencies": { + "chai": "^3.5.0", + "mocha": "^2.5.3" + }, + "devDependencies": { + "mocha": "^2.5.3" + }, + "scripts": { + "test": "mocha" + } +}