Closed scozv closed 10 years ago
It is not easy or quick to read file from browser.
How about use Node.js environment to read file and run our unit tests. If so, we may use Grunt.js to run some tasks.
I have tested the following pattern successfully in Node.js environment and browser, which is inspired by Require.js, comparing require.js with r.js for Node.
// module file
var env;
if (typeof window !== 'undefined' && window) {
env = (window.Sorting = window.Sorting || {});
} else if (typeof process !== 'undefined' && process.versions && !!process.versions.node) {
env = exports;
} else {
// or throw new Error('invalid environment');
env = 'invalid environment';
}
(function(Sorting, undefined){
Sorting.isSorted = function () {};
})(env);
Applying this, we can require(./fileName.js)
in Node.js environment, or run JavaScript in browser.
// application file
var Sorting = require('./sorting.js');
Sorting.isSorted();
From Algo.js of Google Code on September 21, 2013 21:26:42
See unit test of graph, we place lots of input edges data in
q-graph.js
. It is better to read input file.Original issue: http://code.google.com/p/algo-js/issues/detail?id=18