changeset 1362:168262618f2d

new test_js target for testing SyncedGraph Ignore-this: fda788c5e8f5cf1190eb383e1cf2b1ad
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 05 Jun 2016 22:41:04 +0000
parents c20dc52e5593
children 233b81d9bd9d
files light9/web/graph.coffee light9/web/graph_test.coffee light9/web/rdfdbclient.coffee makefile package.json
diffstat 5 files changed, 52 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/graph.coffee	Sun Jun 05 09:53:24 2016 +0000
+++ b/light9/web/graph.coffee	Sun Jun 05 22:41:04 2016 +0000
@@ -3,6 +3,13 @@
 # Patch is {addQuads: <quads>, delQuads: <quads>}
 # <quads> 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 @@
     @_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')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/web/graph_test.coffee	Sun Jun 05 22:41:04 2016 +0000
@@ -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)
+
--- a/light9/web/rdfdbclient.coffee	Sun Jun 05 09:53:24 2016 +0000
+++ b/light9/web/rdfdbclient.coffee	Sun Jun 05 22:41:04 2016 +0000
@@ -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: ''}}
--- a/makefile	Sun Jun 05 09:53:24 2016 +0000
+++ b/makefile	Sun Jun 05 22:41:04 2016 +0000
@@ -10,6 +10,13 @@
 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:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package.json	Sun Jun 05 22:41:04 2016 +0000
@@ -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"
+  }
+}