From edf254c6e520def4f4b36914254ce59e3699cbbe Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Mon, 2 Feb 2015 17:34:00 +0300 Subject: [PATCH] Use karma-env-preprocessor --- karma-all-tests.js | 1 - karma.conf.js | 16 ++++++++-------- lib/net/base.js | 3 ++- package.json | 1 + test.js | 4 +--- 5 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 karma-all-tests.js diff --git a/karma-all-tests.js b/karma-all-tests.js deleted file mode 100644 index 8b55cbe..0000000 --- a/karma-all-tests.js +++ /dev/null @@ -1 +0,0 @@ -window.ALL_TESTS = true; diff --git a/karma.conf.js b/karma.conf.js index 6569e19..74b08ef 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,10 +1,5 @@ process.env.CHROME_BIN = "chromium-browser"; -var allTests = !!process.env.ALL_TESTS; -var files = ["test.js"]; -if (allTests) { - // Kludgy way to pass a variable to `test.js`. - files.unshift("karma-all-tests.js"); -}; +var allTests = process.env.ALL_TESTS === "1"; module.exports = function(config) { config.set({ @@ -19,16 +14,21 @@ module.exports = function(config) { // list of files / patterns to load in the browser - files: files, + files: ["test.js"], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - "test.js": ["browserify"], + "test.js": ["browserify", "env"], }, + envPreprocessor: [ + "ALL_TESTS", + ], + + // list of files to exclude exclude: [ ], diff --git a/lib/net/base.js b/lib/net/base.js index 19cb5e1..7eb7c8d 100644 --- a/lib/net/base.js +++ b/lib/net/base.js @@ -40,7 +40,8 @@ BaseTransport.prototype.bootstrap = function() { /** * Connect to the transport-specific address. - * Should emit `open` event when the connection is established. + * Should emit `open` event after successful connect and `established` + * event after `verack` messages exchange. * @abstract */ BaseTransport.prototype.connect = function() { diff --git a/package.json b/package.json index b49604b..028dc38 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "karma-browserify": "^2.0.0", "karma-chrome-launcher": "^0.1.7", "karma-cli": "~0.0.4", + "karma-env-preprocessor": "^0.1.0", "karma-firefox-launcher": "^0.1.4", "karma-mocha": "^0.1.10", "karma-mocha-reporter": "^0.3.1", diff --git a/test.js b/test.js index fb5bb5c..b461327 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,5 @@ var expect = require("chai").expect; -var allTests = typeof window === "undefined" ? - !!process.env.ALL_TESTS : - window.ALL_TESTS; +var allTests = (global.__env__ || process.env).ALL_TESTS === "1"; var bufferEqual = require("buffer-equal"); var bitmessage = require("./lib");