From c919c4bfef4ad9e2dc25d040c0727dd29ad541ae Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 20 Oct 2014 13:25:32 +0300 Subject: introduce require.js and rewrite tests Yes, I'm being lazy. The purpose of require.js is to allow writing modules, i.e. individual smaller then the whole files with clear dependencies. This is achieved by using a new api provided by require.js: define, require, requirejs Read more at [requirejs] (http://requirejs.org) Tests have been rewritten to work correctly with require.js; they still use jsdom. Test output is now stored in the repository, all tests are run via run_tests.js; This is a hack - once a good harness (with assertions, suites - unittest like) presents itself it will be used. Hidden here is also using FileSaver for history saving, so history is saved to history.json instead to a random name. Plus dropping some dead code. --- scripts/util.js | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'scripts/util.js') diff --git a/scripts/util.js b/scripts/util.js index 4eb94266..4af7a7cf 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -1,12 +1,39 @@ -function set_from_array(a) { +/* + Craziness to deal with the bolted on module systems that we use: + In browser: require.js, it uses a global function named 'define' + On server for tests: Node, it provides a module definition time object named 'exports' +*/ +(function(factory) { + if (typeof define != 'undefined') { + define('util', factory); + } else { + if (typeof exports == 'object') { + var obj = factory(); + for (var i in obj) { + exports[i] = obj[i]; + } + } + } +})(function() { +return { + +set_from_array: function (a) { var ret = {}; for (var k = 0 ; k < a.length ; ++k) { ret[a[k]] = 1; } return ret; -} +}, + +set_from_object: function(o) { + var ret = {} + for (var k in o) { + ret[k] = 1; + } + return ret; +}, -function set_diff(sa, sb) { +set_diff: function(sa, sb) { var ret = {a_b:[], b_a:[]}; var i; for (i in sa) { @@ -20,16 +47,12 @@ function set_diff(sa, sb) { } } return ret; -} +}, -function array_diff(aa, ab) { +array_diff: function(aa, ab) { var sa = set_from_array(aa); var sb = set_from_array(ab); return set_diff(sa, sb); -} +}, -if (typeof(exports) != 'undefined') { - exports.set_diff = set_diff; - exports.array_diff = array_diff; - exports.set_from_array = set_from_array; -} +}}); -- cgit v1.3.1