Add the "static" directory to NODE_PATH for unit tests.

I added our "static" directory to NODE_PATH for our JS unit tests.
This eliminates most of the verbosity in our require statements, but
it still requires us to explicitly call out "js" or "third"
subdirectories, which should make it a bit easier for folks reading
the tests to distinguish modules from js, third, or node itself.

(imported from commit b77a5283135d388d46f4b7e511acc59986f1a8ba)
This commit is contained in:
Steve Howell 2013-08-01 11:53:10 -04:00
parent 44e59dfaea
commit 2442edee9e
4 changed files with 11 additions and 7 deletions

View File

@ -2,6 +2,10 @@
cd "$(dirname "$0")"/../zephyr/tests/frontend/node cd "$(dirname "$0")"/../zephyr/tests/frontend/node
STATIC_DIR=`python -c 'import os;print os.path.realpath("../../../../static")'`
export NODE_PATH=$STATIC_DIR
NODEJS=$(which nodejs || which node) NODEJS=$(which nodejs || which node)
$NODEJS message_tour.js $NODEJS message_tour.js

View File

@ -3,7 +3,7 @@
// purpose, but, briefly, it provides an API to keep track of // purpose, but, briefly, it provides an API to keep track of
// messages that you visit on a "tour." // messages that you visit on a "tour."
var message_tour = require('../../../../static/js/message_tour.js'); var message_tour = require('js/message_tour.js');
var assert = require('assert'); var assert = require('assert');
(function test_basic_tour() { (function test_basic_tour() {

View File

@ -8,7 +8,7 @@
var assert = require('assert'); var assert = require('assert');
function set_up_dependencies() { function set_up_dependencies() {
var _ = global._ = require('../../../../static/third/underscore/underscore.js'); var _ = global._ = require('third/underscore/underscore.js');
global.Handlebars = require('handlebars'); global.Handlebars = require('handlebars');
// We stub out most of jQuery, which is irrelevant to most of these tests. // We stub out most of jQuery, which is irrelevant to most of these tests.
@ -21,8 +21,8 @@ function set_up_dependencies() {
$.map = _.map; $.map = _.map;
$.grep = _.filter; $.grep = _.filter;
var actual_narrow = require('../../../../static/js/narrow.js'); var actual_narrow = require('js/narrow.js');
var search = require('../../../../static/js/search.js'); var search = require('js/search.js');
global.narrow = { global.narrow = {
parse: actual_narrow.parse, parse: actual_narrow.parse,
@ -39,7 +39,7 @@ function set_up_dependencies() {
canonicalized_name: function (name) { return name; } canonicalized_name: function (name) { return name; }
}; };
global.typeahead_helper = require('../../../../static/js/typeahead_helper.js'); global.typeahead_helper = require('js/typeahead_helper.js');
global.recent_subjects = {}; global.recent_subjects = {};

View File

@ -7,8 +7,8 @@
// clean up after themselves, and they should explicitly stub all // clean up after themselves, and they should explicitly stub all
// dependencies (except _). // dependencies (except _).
global._ = require('../../../../static/third/underscore/underscore.js'); global._ = require('third/underscore/underscore.js');
var unread = require('../../../../static/js/unread.js'); var unread = require('js/unread.js');
var assert = require('assert'); var assert = require('assert');
var narrow = {}; var narrow = {};