global.assert = require('assert'); var fs = require('fs'); var path = require('path'); var Handlebars = require('handlebars'); require('third/string-prototype-codepointat/codepointat.js'); global.Dict = require('js/dict'); global._ = require('third/underscore/underscore.js'); var _ = global._; // Run all the JS scripts in our test directory. Tests do NOT run // in isolation. var oneFileFilter = []; var testsDifference = []; if (process.argv[2] ) { oneFileFilter = process.argv .slice(2) .map(function (filename) {return filename.replace(/\.js$/i, '');}); } var tests = fs.readdirSync(__dirname) .filter(function (filename) {return (/\.js$/i).test(filename);}) .map(function (filename) {return filename.replace(/\.js$/i, '');}); if (oneFileFilter.length > 0) { tests = tests.filter(function (filename) { return oneFileFilter.indexOf(filename) !== -1; }); testsDifference = _.difference(oneFileFilter, tests); } tests.sort(); var dependencies = []; var old_builtins = {}; global.set_global = function (name, val) { global[name] = val; dependencies.push(name); return val; }; global.patch_builtin = function (name, val) { old_builtins[name] = global[name]; global[name] = val; return val; }; global.add_dependencies = function (dct) { _.each(dct, function (fn, name) { var obj = require(fn); set_global(name, obj); }); }; function template_dir() { return __dirname + '/../../static/templates/'; } global.make_sure_all_templates_have_been_compiled = function () { var dir = template_dir(); var fns = fs.readdirSync(dir).filter(function (fn) { return (/\.handlebars/).test(fn); }); _.each(fns, function (fn) { var name = fn.split('.')[0]; if (!Handlebars.templates[name]) { throw "The file " + fn + " has no test coverage."; } }); }; global.use_template = function (name) { if (Handlebars.templates === undefined) { Handlebars.templates = {}; } var data = fs.readFileSync(template_dir() + name + '.handlebars').toString(); Handlebars.templates[name] = Handlebars.compile(data); }; function stylesheets() { // TODO: Automatically get all relevant styles. var data = ''; data += '\n'; data += '\n'; data += '\n'; data += '\n'; data += '\n'; data += '\n'; return data; } var mkdir_p = function (path) { // This works like mkdir -p in Unix. try { fs.mkdirSync(path); } catch(e) { if ( e.code !== 'EEXIST' ) { throw e; } } return path; }; var output_dir = (function () { mkdir_p('var'); var dir = mkdir_p('var/test-js-with-node'); return dir; }()); var output_fn = path.join(output_dir, 'output.html'); var index_fn = path.join(output_dir, 'index.html'); (function () { var data = ''; data += stylesheets(); data += '\n'; data += '\n'; data += ''; data += '
Any test can output HTML to be viewed here:
\n'; data += 'Output of non-template.js testsThese are specifically from templates.js
\n'; fs.writeFileSync(index_fn, data); }()); global.write_test_output = function (label, output) { var data = ''; data += '