From 2442edee9e72eb906a1f7c99d1da2e1862cf249f Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 1 Aug 2013 11:53:10 -0400 Subject: [PATCH] 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) --- tools/test-js-with-node | 4 ++++ zephyr/tests/frontend/node/message_tour.js | 2 +- zephyr/tests/frontend/node/search.js | 8 ++++---- zephyr/tests/frontend/node/unread.js | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 44ace579be..ff00c0151a 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -2,6 +2,10 @@ 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 message_tour.js diff --git a/zephyr/tests/frontend/node/message_tour.js b/zephyr/tests/frontend/node/message_tour.js index b0787e3068..bdfd047a00 100644 --- a/zephyr/tests/frontend/node/message_tour.js +++ b/zephyr/tests/frontend/node/message_tour.js @@ -3,7 +3,7 @@ // purpose, but, briefly, it provides an API to keep track of // 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'); (function test_basic_tour() { diff --git a/zephyr/tests/frontend/node/search.js b/zephyr/tests/frontend/node/search.js index 6bcc9ae73a..b0c2242851 100644 --- a/zephyr/tests/frontend/node/search.js +++ b/zephyr/tests/frontend/node/search.js @@ -8,7 +8,7 @@ var assert = require('assert'); function set_up_dependencies() { - var _ = global._ = require('../../../../static/third/underscore/underscore.js'); + var _ = global._ = require('third/underscore/underscore.js'); global.Handlebars = require('handlebars'); // We stub out most of jQuery, which is irrelevant to most of these tests. @@ -21,8 +21,8 @@ function set_up_dependencies() { $.map = _.map; $.grep = _.filter; - var actual_narrow = require('../../../../static/js/narrow.js'); - var search = require('../../../../static/js/search.js'); + var actual_narrow = require('js/narrow.js'); + var search = require('js/search.js'); global.narrow = { parse: actual_narrow.parse, @@ -39,7 +39,7 @@ function set_up_dependencies() { 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 = {}; diff --git a/zephyr/tests/frontend/node/unread.js b/zephyr/tests/frontend/node/unread.js index 47ddacd073..aa4ba171fe 100644 --- a/zephyr/tests/frontend/node/unread.js +++ b/zephyr/tests/frontend/node/unread.js @@ -7,8 +7,8 @@ // clean up after themselves, and they should explicitly stub all // dependencies (except _). -global._ = require('../../../../static/third/underscore/underscore.js'); -var unread = require('../../../../static/js/unread.js'); +global._ = require('third/underscore/underscore.js'); +var unread = require('js/unread.js'); var assert = require('assert'); var narrow = {};