This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
forked from proverma/arrow
-
Notifications
You must be signed in to change notification settings - Fork 59
/
arrow.js
93 lines (74 loc) · 2.89 KB
/
arrow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*jslint forin:true sub:true anon:true, sloppy:true, stupid:true nomen:true, node:true continue:true*/
/*
* Copyright (c) 2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
var log4js = require("log4js");
var path = require("path");
function Arrow(config, args) {
this.logger = log4js.getLogger("Arrow");
this.config = config;
this.args = args;
Arrow.instance = this;
}
Arrow.instance = null;
Arrow.getInstance = function () {
return Arrow.instance;
};
Arrow.prototype.run = function () {
var SessionFactory = require("../session/sessionfactory"),
sf;
sf = new SessionFactory(this.config, this.args);
sf.runAllTestSessions();
};
Arrow.prototype.runController = function (controllerName, testConfig, testParams, driver, callback) {
var self = this,
ControllerClass,
controller;
if (!testConfig) { testConfig = {}; }
if (!testParams) { testParams = {}; }
if (controllerName) {
if (controllerName.indexOf(".js") !== -1) {
controllerName = path.resolve(process.cwd(), controllerName);
} else {
controllerName = this.config["arrowModuleRoot"] + "lib/controller/" + controllerName;
}
} else {
controllerName = this.config["arrowModuleRoot"] + "lib/controller/default"; // default controller
}
ControllerClass = require(controllerName);
controller = new ControllerClass(testConfig, testParams, driver);
this.logger.info("Executing controller: " + controllerName);
if (testParams.scenario) {
driver.reports.startScenarioReport();
} else {
driver.reports.startReport();
}
controller.execute(function (error, data) {
var errorMsg;
if (error) {
if (testParams.testName) {
errorMsg = "Test failed: " + testParams.testName +
", Detailed error: " + error +
", Controller: " + controllerName;
} else {
errorMsg = error + ", Controller: " + controllerName;
}
self.logger.error(errorMsg);
if (!testParams.test && !testParams.scenario) {
driver.reports.addReport({"error" : errorMsg, "controller" : controllerName, "params" : testParams});
} else if (testParams.test && !testParams.scenario) {
driver.reports.addReport({"error" : errorMsg, "controller" : controllerName, "params" : testParams});
}
} else {
if (!testParams.test && !testParams.scenario) {
driver.reports.addReport({"controller" : controllerName, "params" : testParams});
}
driver.reports.popReportAtom();
}
// error, data from previous controller, controller instance
callback(error, data, controller);
});
};
module.exports = Arrow;