diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-20 13:25:32 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-20 21:36:37 +0300 |
| commit | c919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch) | |
| tree | dd6394603680976c48801b53321e8085b0db1505 /tests | |
| parent | f1f4e937932f52c630831d0d501f8f8756b37531 (diff) | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/output/test_analyzer.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_analyzer.js.stdout | 7 | ||||
| -rw-r--r-- | tests/output/test_app.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_app.js.stdout | 1 | ||||
| -rw-r--r-- | tests/output/test_globals.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_globals.js.stdout | 11 | ||||
| -rw-r--r-- | tests/output/test_require_js.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_require_js.js.stdout | 17 | ||||
| -rw-r--r-- | tests/output/test_script_jsdom.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_script_jsdom.js.stdout | 1 | ||||
| -rw-r--r-- | tests/output/test_sub_process.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_sub_process.js.stdout | 2 | ||||
| -rw-r--r-- | tests/output/test_util.js.stderr | 0 | ||||
| -rw-r--r-- | tests/output/test_util.js.stdout | 0 | ||||
| -rw-r--r-- | tests/run_tests.js | 31 | ||||
| -rw-r--r-- | tests/test_analyzer.js | 87 | ||||
| -rw-r--r-- | tests/test_nan_problem.js | 78 | ||||
| -rw-r--r-- | tests/weizmann.json | 1 |
18 files changed, 89 insertions, 147 deletions
diff --git a/tests/output/test_analyzer.js.stderr b/tests/output/test_analyzer.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_analyzer.js.stderr diff --git a/tests/output/test_analyzer.js.stdout b/tests/output/test_analyzer.js.stdout new file mode 100644 index 00000000..5db6c9ac --- /dev/null +++ b/tests/output/test_analyzer.js.stdout @@ -0,0 +1,7 @@ +addScript: loaded ../scripts/external/require.js +app: running under node +addScript: loaded ../scripts/app.js +test harness: starting script loading with requirejs +test harness: main loaded +Rhizi main started +rhizi: init drag-n-drop diff --git a/tests/output/test_app.js.stderr b/tests/output/test_app.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_app.js.stderr diff --git a/tests/output/test_app.js.stdout b/tests/output/test_app.js.stdout new file mode 100644 index 00000000..2d2c7940 --- /dev/null +++ b/tests/output/test_app.js.stdout @@ -0,0 +1 @@ +test_app: running under node diff --git a/tests/output/test_globals.js.stderr b/tests/output/test_globals.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_globals.js.stderr diff --git a/tests/output/test_globals.js.stdout b/tests/output/test_globals.js.stdout new file mode 100644 index 00000000..a6b915ca --- /dev/null +++ b/tests/output/test_globals.js.stdout @@ -0,0 +1,11 @@ +before fields count: 187 +addScript: loaded ../scripts/external/require.js +app: running under node +addScript: loaded ../scripts/app.js +test harness: starting script loading with requirejs +test harness: main loaded +Rhizi main started +rhizi: init drag-n-drop +after fields count: 195 +new fields count: 8 +requirejs,require,define,rhizi_require_config,$,jQuery,d3,saveAs diff --git a/tests/output/test_require_js.js.stderr b/tests/output/test_require_js.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_require_js.js.stderr diff --git a/tests/output/test_require_js.js.stdout b/tests/output/test_require_js.js.stdout new file mode 100644 index 00000000..821c4a6d --- /dev/null +++ b/tests/output/test_require_js.js.stdout @@ -0,0 +1,17 @@ +addScript: loaded ../scripts/external/require.js +test_app: running under node +addScript: loaded test_app.js +callback after test_app.js loading +{ paths: + { jquery: 'external/jquery', + 'jquery-ui': 'external/jquery-ui', + caret: 'external/caret', + d3: 'external/d3/d3', + autocomplete: 'external/autocomplete', + FileSaver: 'external/FileSaver' }, + baseUrl: '../scripts/' } +hello from test factory +here we are after test_app prerequisites +42 +Rhizi main started +rhizi: init drag-n-drop diff --git a/tests/output/test_script_jsdom.js.stderr b/tests/output/test_script_jsdom.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_script_jsdom.js.stderr diff --git a/tests/output/test_script_jsdom.js.stdout b/tests/output/test_script_jsdom.js.stdout new file mode 100644 index 00000000..02b09a7b --- /dev/null +++ b/tests/output/test_script_jsdom.js.stdout @@ -0,0 +1 @@ +{ foo: 'bar' } diff --git a/tests/output/test_sub_process.js.stderr b/tests/output/test_sub_process.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_sub_process.js.stderr diff --git a/tests/output/test_sub_process.js.stdout b/tests/output/test_sub_process.js.stdout new file mode 100644 index 00000000..61ac4e96 --- /dev/null +++ b/tests/output/test_sub_process.js.stdout @@ -0,0 +1,2 @@ +stdout 200 +closed, 0, null diff --git a/tests/output/test_util.js.stderr b/tests/output/test_util.js.stderr new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_util.js.stderr diff --git a/tests/output/test_util.js.stdout b/tests/output/test_util.js.stdout new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/output/test_util.js.stdout diff --git a/tests/run_tests.js b/tests/run_tests.js new file mode 100644 index 00000000..bfc129eb --- /dev/null +++ b/tests/run_tests.js @@ -0,0 +1,31 @@ +var fs = require('fs'); +var spawn = require('child_process').spawn; + +var tests = fs.readdirSync('.').filter(function (x) { return /^test_.*\.js$/.test(x); }); +var i; +var testname; + +function store_output(proc, args, stdout, stderr) +{ + var out = fs.openSync(stdout, 'w+'); + var err = fs.openSync(stderr, 'w+'); + var p = spawn(proc, args); + + p.stdout.on('data', function (data) { + console.log(args + ' gives ' + data.length); + fs.appendFileSync(stdout, data); + }); + p.stderr.on('data', function (data) { + console.log(args + ' gives ' + data.length + ' (err)'); + fs.appendFileSync(stderr, data); + }); + p.on('close', function (code, signal) { + console.log(proc + '(' + args.join(', ') + ') exited with ' + code); + }); + +} + +for (i in tests) { + testname = tests[i]; + store_output('/usr/bin/node', [__dirname + '/' + testname], 'output/' + testname + '.stdout', 'output/' + testname + '.stderr'); +} diff --git a/tests/test_analyzer.js b/tests/test_analyzer.js index b7b66a66..d003f8f6 100644 --- a/tests/test_analyzer.js +++ b/tests/test_analyzer.js @@ -1,55 +1,4 @@ -var fs = require('fs'), - jsdom = require('jsdom'); - -var script_filenames = [ - "external/scripts/d3/d3.js", - "external/scripts/jquery.js", - "external/scripts/jquery-ui.js", - "external/scripts/autocomplete.js", - - "scripts/caret.js", - "scripts/history.js", - "scripts/rhizicore.js", - "scripts/textanalysis.js", - "scripts/textanalysis-ui.js", - "scripts/buttons.js", - "scripts/drag_n_drop.js", - "scripts/robot.js", - "scripts/watchdog.js", - "scripts/gant.js"].map(function(x) { return "../" + x; }); - -function dump_nodes(window) { - var nodes = window.force.nodes(); - for(var i = 0 ; i < nodes.length; ++i) { - console.log('nodes[' + nodes[i].id + '/' + nodes[i].type + '].[xy] = (' + nodes[i].x + ',' + nodes[i].y + ')'); - } -} - -function dump_graphviz(window) { - var i; - var nodes = window.force.nodes(); - var links = window.force.links(); - var q = function(s) { - if (s.search(' ') == -1) { - return s; - } - return '"' + s + '"'; - }; - - console.log('digraph {'); - for (i = 0 ; i < nodes.length; ++i) { - if (nodes[i].type == 'bubble') { - console.log(' BUBBLE;'); - } else { - console.log(' ' + q(nodes[i].name) + ';'); - } - } - for (i = 0 ; i < links.length; ++i) { - var link = links[i]; - console.log(' ' + q(link.source.name) + ' -> ' + q(link.target.name) + ';'); - } - console.log('}'); -} +var base = require('./base'); var data = [ ["#a hello there #b", ["a", "b"], [["a", "b", "hello there"]], @@ -66,21 +15,21 @@ sometimes #z and #ab aren't friends I like to work with #a */ - -var done = function (errors, window) { - debugger; - if (process.argv.length > 2) { - window.analyzeSentence(process.argv.slice(2).join(" "), true); - dump_graphviz(window); +base.run_tests({ + done: function (errors, window) { + debugger; + if (process.argv.length > 2) { + window.analyzeSentence(process.argv.slice(2).join(" "), true); + dump_graphviz(window); + } else { + for (var k in data) { + var sentence = data[k][0]; + var expected_nodes = data[k][1]; + var expected_links = data[k][2]; + window.analyzeSentence(sentence, true); + // TODO - compare graphs + } + } + process.exit(); } - process.exit(); -} - -var env = jsdom.env({ - scripts: script_filenames, - html: "<html><body></body></html>", - created: function(errors, window) { - window.console.log = console.log; // slightly evil - window.process = process; // more evil - }, - done: done}); +}); diff --git a/tests/test_nan_problem.js b/tests/test_nan_problem.js deleted file mode 100644 index fab9df34..00000000 --- a/tests/test_nan_problem.js +++ /dev/null @@ -1,78 +0,0 @@ -var fs = require('fs'), - jsdom = require('jsdom'); - -var script_filenames = [ - "external/scripts/d3/d3.js", - "external/scripts/jquery.js", - "external/scripts/jquery-ui.js", - "external/scripts/autocomplete.js", - - "scripts/caret.js", - "scripts/history.js", - "scripts/rhizicore.js", - "scripts/textanalysis.js", - "scripts/textanalysis-ui.js", - "scripts/buttons.js", - "scripts/drag_n_drop.js", - "scripts/robot.js", - "scripts/watchdog.js", - "scripts/gant.js"].map(function(x) { return "../" + x; }); - -function feed_sentence(window, s, finalize) -{ - var i; - console.log('******* feeding: ' + s); - for (i = 1 ; i <= s.length; ++i) { - console.log('======= ' + s.substr(0, i)); - window.analyzeSentence(s.substr(0, i), false); - } - if (finalize) { - window.analyzeSentence(s, true); - } -} - -function dump_nodes(window) { - var nodes = window.force.nodes(); - for(var i = 0 ; i < nodes.length; ++i) { - console.log('nodes[' + nodes[i].id + '/' + nodes[i].type + '].[xy] = (' + nodes[i].x + ',' + nodes[i].y + ')'); - } -} - -var env = jsdom.env({ - scripts: script_filenames, - html: "<html><body></body></html>", - created: function(errors, window) { - window.console.log = console.log; // slightly evil - window.process = process; // more evil - }, - done: function (errors, window) { - var i; - var s1 = "#a"; - var s2 = "#a is"; - var nodes; - - window.force - .nodes(window.nodes) - .links(window.links) - .alpha(0.1) - .start(); - console.log('---------'); - console.log(errors); - console.log('---------'); - //console.log(window.textAnalyser2("#a")); - feed_sentence(window, s1, true); - dump_nodes(window); - feed_sentence(window, s2, false); - console.log(window.force.alpha()); - dump_nodes(window); - debugger; - window.force.tick(); - console.log(window.force.alpha()); - dump_nodes(window); - //console.log(window.nodes); - //console.log(window.links); - process.exit(); - window.debug_print(window.force); - //process.exit(); - } -}); diff --git a/tests/weizmann.json b/tests/weizmann.json new file mode 100644 index 00000000..326c9fc9 --- /dev/null +++ b/tests/weizmann.json @@ -0,0 +1 @@ +{"nodes":[{"id":"Oren","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Hila","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Yuval","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Pareto Morphology","type":"project","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Avi","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"circuits","type":"project","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Pablo","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"FCD","type":"project","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"animals","type":"project","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"ParTI","type":"project","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"genotypes","type":"project","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Miri","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Jean","type":"person","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Physisist","type":"skill","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Chemist","type":"skill","state":"perm","start":0,"end":0,"status":"unknown"},{"id":"Mathematician","type":"skill","state":"perm","start":0,"end":0,"status":"unknown"}],"links":[{"source":"Yuval","target":"Pareto Morphology","name":"work on "},{"source":"Oren","target":"Pareto Morphology","name":"work on "},{"source":"Oren","target":"Pareto Morphology","name":"work on "},{"source":"Hila","target":"Pareto Morphology","name":"work on "},{"source":"Hila","target":"Pareto Morphology","name":"work on "},{"source":"Avi","target":"Pareto Morphology","name":"works on "},{"source":"Avi","target":"Pareto Morphology","name":"works on "},{"source":"Avi","target":"circuits","name":"works on "},{"source":"Avi","target":"circuits","name":"works on "},{"source":"Pablo","target":"circuits","name":"works on "},{"source":"Pablo","target":"circuits","name":"works on "},{"source":"Pablo","target":"FCD","name":"works on "},{"source":"Pablo","target":"animals","name":"works on "},{"source":"Pablo","target":"ParTI","name":"works on "},{"source":"Avi","target":"circuits","name":"works on "},{"source":"Avi","target":"circuits","name":"works on "},{"source":"Avi","target":"FCD","name":"works on "},{"source":"Avi","target":"animals","name":"works on "},{"source":"Yuval","target":"ParTI","name":"works on "},{"source":"Yuval","target":"ParTI","name":"works on "},{"source":"Hila","target":"circuits","name":"works on "},{"source":"Hila","target":"circuits","name":"works on "},{"source":"Hila","target":"genotypes","name":"works on "},{"source":"Miri","target":"FCD","name":"works on "},{"source":"Miri","target":"FCD","name":"works on "},{"source":"Hila","target":"ParTI","name":"wrote the code and consulted with the math in "},{"source":"Hila","target":"ParTI","name":"wrote the code and consulted with the math in "},{"source":"Avi","target":"ParTI","name":"prepared graphical interface to "},{"source":"Avi","target":"ParTI","name":"prepared graphical interface to "},{"source":"Jean","target":"ParTI","name":"helped with biological interpretations in the project "},{"source":"Jean","target":"ParTI","name":"helped with biological interpretations in the project "},{"source":"Pablo","target":"Physisist","name":"is a "},{"source":"Physisist","target":"Chemist","name":" and a "},{"source":"Pablo","target":"Physisist","name":"is a "},{"source":"Pablo","target":"Chemist","name":"is a "},{"source":"Yuval","target":"Physisist","name":"is a "},{"source":"Physisist","target":"Mathematician","name":" and a "},{"source":"Hila","target":"Physisist","name":"is a "},{"source":"Hila","target":"Mathematician","name":"is a "},{"source":"Yuval","target":"Physisist","name":"is a "},{"source":"Yuval","target":"Mathematician","name":"is a "}]}
\ No newline at end of file |
