From 5e85ae4ab78d5482a2027c2703491320a4d2832f Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Mon, 2 Feb 2015 18:30:05 +0300 Subject: [PATCH] Functional tests stub --- karma.conf.js | 6 ++++-- lib/net/base.js | 2 +- lib/net/tcp.browser.js | 2 +- package.json | 9 ++++++--- tests/functional.js | 16 ++++++++++++++++ tests/index.js | 17 +++++++++++++++++ tests/run-test-nodes.js | 7 +++++++ test.js => tests/unit.js | 4 ++-- 8 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 tests/functional.js create mode 100644 tests/index.js create mode 100644 tests/run-test-nodes.js rename test.js => tests/unit.js (99%) diff --git a/karma.conf.js b/karma.conf.js index 74b08ef..c5aba59 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,5 +1,6 @@ process.env.CHROME_BIN = "chromium-browser"; var allTests = process.env.ALL_TESTS === "1"; +if (process.env.TEST_MODE !== "unit") require("./tests/run-test-nodes.js")(); module.exports = function(config) { config.set({ @@ -14,18 +15,19 @@ module.exports = function(config) { // list of files / patterns to load in the browser - files: ["test.js"], + files: ["tests/index.js"], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - "test.js": ["browserify", "env"], + "tests/index.js": ["browserify", "env"], }, envPreprocessor: [ "ALL_TESTS", + "TEST_MODE", ], diff --git a/lib/net/base.js b/lib/net/base.js index 7eb7c8d..5dfff95 100644 --- a/lib/net/base.js +++ b/lib/net/base.js @@ -9,7 +9,7 @@ var inherits = require("inherits"); var EventEmitter = require("events").EventEmitter; -var PPromise = require("./platform").Promise; +var PPromise = require("../platform").Promise; /** * Network transport base class. diff --git a/lib/net/tcp.browser.js b/lib/net/tcp.browser.js index 3e631c2..fd53046 100644 --- a/lib/net/tcp.browser.js +++ b/lib/net/tcp.browser.js @@ -1 +1 @@ -throw new Error("Not implemented"); +throw new Error("TCP transport is not supported by Browser platform"); diff --git a/package.json b/package.json index 028dc38..99136e4 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,13 @@ }, "scripts": { "install": "node-gyp rebuild || exit 0", - "test": "ALL_TESTS=1 mocha && ALL_TESTS=1 xvfb-run -a karma start --browsers Chromium && ALL_TESTS=1 xvfb-run -a karma start --browsers Firefox && jshint .", - "m": "mocha", - "k": "xvfb-run -a karma start", + "test": "ALL_TESTS=1 mocha tests/index.js && ALL_TESTS=1 xvfb-run -a karma start --browsers Chromium && ALL_TESTS=1 xvfb-run -a karma start --browsers Firefox && jshint .", + "m": "mocha tests/index.js", + "mu": "TEST_MODE=unit mocha tests/index.js", + "mf": "TEST_MODE=functional mocha tests/index.js", "kc": "xvfb-run -a karma start --browsers Chromium", + "kcu": "TEST_MODE=unit xvfb-run -a karma start --browsers Chromium", + "kcf": "TEST_MODE=functional xvfb-run -a karma start --browsers Chromium", "kf": "xvfb-run -a karma start --browsers Firefox", "j": "jshint .", "d": "jsdoc -c jsdoc.json", diff --git a/tests/functional.js b/tests/functional.js new file mode 100644 index 0000000..562fe54 --- /dev/null +++ b/tests/functional.js @@ -0,0 +1,16 @@ +var bitmessage = require("../lib"); +var structs = bitmessage.structs; +var message = structs.message; +// var WsTransport = require("../lib/net/ws").Transport; + +if (!process.browser) { + var TcpTransport = require("../lib/net/tcp").Transport; + + describe("TCP transport", function() { + it("should allow to communicate between two nodes"); + }); +} + +describe("WebSocket transport", function() { + it("should allow to communicate between two nodes"); +}); diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..0709cd4 --- /dev/null +++ b/tests/index.js @@ -0,0 +1,17 @@ +var testMode = (global.__env__ || process.env).TEST_MODE; + +if (testMode !== "functional") { + describe("Unit tests", function() { + require("./unit"); + }); +} + +if (testMode !== "unit") { + // For Browser tests nodes are runned from karma.conf.js because we + // are _already_ in browser context here. + if (!process.browser) require("./run-test-nodes.js")(); + + describe("Functional tests", function() { + require("./functional"); + }); +} diff --git a/tests/run-test-nodes.js b/tests/run-test-nodes.js new file mode 100644 index 0000000..dc5cb31 --- /dev/null +++ b/tests/run-test-nodes.js @@ -0,0 +1,7 @@ +// Run test nodes for all known transports so we can test library in +// functional test suites. Stop nodes when testing is complete. + +// Note that this file is executed only on Node.js platform. + +module.exports = function() { +}; diff --git a/test.js b/tests/unit.js similarity index 99% rename from test.js rename to tests/unit.js index b461327..8cc20bb 100644 --- a/test.js +++ b/tests/unit.js @@ -2,8 +2,8 @@ var expect = require("chai").expect; var allTests = (global.__env__ || process.env).ALL_TESTS === "1"; var bufferEqual = require("buffer-equal"); -var bitmessage = require("./lib"); -var bmcrypto = require("./lib/crypto"); +var bitmessage = require("../lib"); +var bmcrypto = require("../lib/crypto"); var structs = bitmessage.structs; var message = structs.message; var object = structs.object;