#!/usr/bin/env node // a script to RUN TESTS. You can specify WHAT TESTS to run by // populating an environment variable 'WHAT_TESTS'. Values include: // * 'front' - frontend unit tests run headlessly (requires phantomjs to be installed) // * 'back' - backend unit tests with a zero-dependency json db // * 'back_mysql - backend unit tests against mysql (requires mysql installed) // * 'all' - of it const spawn = require('child_process').spawn, path = require('path'); // WHAT TESTS are we running? var whatTests = []; if (!process.env['WHAT_TESTS']) { whatTests = [ 'all' ]; } else { whatTests.push(process.env['WHAT_TESTS']); } if (whatTests[0] == 'all') whatTests = [ 'back_mysql', 'back', 'front' ]; var ec = 0; function run() { if (!whatTests.length) process.exit(ec); var testName = whatTests.shift(); const availConf = { front: { what: "Front end unit tests under PhantomJS", node_env: 'test_json', script: 'test_frontend' }, back: { what: "API level unit tests using a JSON database", node_env: 'test_json', script: 'test_backend' }, back_mysql: { what: "API level unit tests using MySQL", node_env: 'test_mysql', script: 'test_backend' } }; var conf = availConf[testName]; if (!conf) { console.log('I don\'t know how to run this test: "' + testName + '"'); console.log('valid choices include:', Object.keys(availConf).join(', ')); ec = 1; return run(); } console.log(">>> Now Running:", conf.what); process.env['NODE_ENV'] = conf.node_env; var kid = spawn(path.join(__dirname, conf.script)); kid.stdout.on('data', function(d) { process.stdout.write(d); }); kid.stderr.on('data', function(d) { process.stderr.write(d); }); kid.on('exit', function(code) { if (code) ec = code; run(); }); } run();