From 8f021a49acbf8d2fc410012c2ab9074d960a1a7f Mon Sep 17 00:00:00 2001 From: Daniel Park Date: Fri, 21 Feb 2014 00:30:01 +0000 Subject: [PATCH 1/2] added start/end events --- lib/interface/arrow.js | 10 +++++++++- lib/session/sessionfactory.js | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/interface/arrow.js b/lib/interface/arrow.js index 816dfc39..8478fe68 100644 --- a/lib/interface/arrow.js +++ b/lib/interface/arrow.js @@ -9,6 +9,7 @@ var log4js = require("log4js"); var path = require("path"); var fs = require("fs"); +var events = require("events"); function Arrow(config, args) { this.logger = log4js.getLogger("Arrow"); @@ -23,11 +24,18 @@ Arrow.getInstance = function () { return Arrow.instance; }; +Arrow.prototype.__proto__ = events.EventEmitter.prototype; + Arrow.prototype.run = function () { var SessionFactory = require("../session/sessionfactory"), - sf; + sf, + arrow = this; + this.emit('start'); sf = new SessionFactory(this.config, this.args); + sf.on('end', function(e) { + arrow.emit('end', e) + }); sf.runAllTestSessions(); }; diff --git a/lib/session/sessionfactory.js b/lib/session/sessionfactory.js index 229ad030..ee1f716f 100644 --- a/lib/session/sessionfactory.js +++ b/lib/session/sessionfactory.js @@ -20,6 +20,7 @@ var os = require("os"); var ProxyManager = require("../proxy/proxymanager"); var Servermanager = require("../../arrow_server/arrowservermanager.js"); var PhantomJsSetup = require("../util/phantomJsSetup.js"); +var events = require("events"); /** * SessionFactory is the main entry point for all Arrow Tests. @@ -106,6 +107,8 @@ function SessionFactory(config, args) { } +SessionFactory.prototype.__proto__ = events.EventEmitter.prototype; + SessionFactory.prototype.runAllTestSessions = function () { var self = this, testExecutor = new TestExecutor(self); @@ -401,6 +404,7 @@ SessionFactory.prototype.tearDown = function (testQueue, wdSessions) { PhantomJsSetup.stopPhantomJs(); } + this.emit('end'); if (global.workingDirectory) { failed = false; From 0433b5ec298efe95c7bd533d9c9657baf0550ff5 Mon Sep 17 00:00:00 2001 From: Daniel Park Date: Fri, 21 Feb 2014 00:51:51 +0000 Subject: [PATCH 2/2] added unit tests --- lib/interface/arrow.js | 3 +++ tests/unit/lib/interface/arrow-tests.js | 28 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/interface/arrow.js b/lib/interface/arrow.js index 8478fe68..a1cb0189 100644 --- a/lib/interface/arrow.js +++ b/lib/interface/arrow.js @@ -47,6 +47,8 @@ Arrow.prototype.runController = function (controllerName, testConfig, testParams getControllerFromShareLib, errorMsg; + this.emit('start'); + if (!testConfig) { testConfig = {}; } @@ -135,6 +137,7 @@ Arrow.prototype.runController = function (controllerName, testConfig, testParams } // error, data from previous controller, controller instance + self.emit('end'); callback(error, data, controller); } diff --git a/tests/unit/lib/interface/arrow-tests.js b/tests/unit/lib/interface/arrow-tests.js index b620aa95..ebb48457 100644 --- a/tests/unit/lib/interface/arrow-tests.js +++ b/tests/unit/lib/interface/arrow-tests.js @@ -69,6 +69,34 @@ YUI.add('arrow-tests', function (Y, NAME) { }); A.isTrue(executed, 'Should have executed controller with testName'); + }, + + 'test start event': function() { + var driver = new StubDriver(), + arrow = new Arrow(), + got_event = false; + + arrow.on('start', function() { + got_event = true; + }); + + arrow.runController(controllerName, {}, {}, driver, function(error, data, controller) { + A.isTrue(got_event, 'should be true'); + }); + }, + + 'test end event': function() { + var driver = new StubDriver(), + arrow = new Arrow(), + got_event = false; + + arrow.on('end', function() { + got_event = true; + }); + + arrow.runController(controllerName, {}, {}, driver, function(error, data, controller) { + A.isTrue(got_event, 'should be true'); + }); } }));