Comparing version 1.0.1 to 2.0.0
@@ -22,4 +22,2 @@ "use strict"; | ||
__export(require("./helpers/wait")); | ||
/** logging */ | ||
__export(require("./logging/plugins/ilogging-plugin")); | ||
__export(require("./logging/test-log")); | ||
@@ -26,0 +24,0 @@ __export(require("./logging/test-log-options")); |
import { TestLogLevel } from "../test-log-level"; | ||
import { TestResult } from "../../integrations/test-cases/test-result"; | ||
import { Constructor } from "../../construction/constructor"; | ||
export interface ILoggingPlugin { | ||
@@ -12,5 +11,1 @@ name: string; | ||
} | ||
export declare namespace ILoggingPlugin { | ||
function getPluginConstructors(): Constructor<ILoggingPlugin>[]; | ||
function register<T extends Constructor<ILoggingPlugin>>(ctor: T): T; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ILoggingPlugin; | ||
(function (ILoggingPlugin) { | ||
var pluginConstructors = []; | ||
function getPluginConstructors() { | ||
return pluginConstructors; | ||
} | ||
ILoggingPlugin.getPluginConstructors = getPluginConstructors; | ||
function register(ctor) { | ||
pluginConstructors.push(ctor); | ||
return ctor; | ||
} | ||
ILoggingPlugin.register = register; | ||
})(ILoggingPlugin = exports.ILoggingPlugin || (exports.ILoggingPlugin = {})); | ||
//# sourceMappingURL=ilogging-plugin.js.map |
@@ -7,2 +7,3 @@ import { IInitialiseOptions } from "../construction/iinitialise-options"; | ||
level: TestLogLevel; | ||
pluginNames: string[]; | ||
constructor(name: string); | ||
@@ -13,3 +14,5 @@ private formatName; | ||
var LOGLEVEL_KEY: string; | ||
var PLUGINS_KEY: string; | ||
function level(lvl?: TestLogLevel): Promise<TestLogLevel>; | ||
function pluginNames(...pluginNames: string[]): Promise<string[]>; | ||
} |
@@ -61,2 +61,3 @@ "use strict"; | ||
TestLogOptions.LOGLEVEL_KEY = 'testloglevel'; | ||
TestLogOptions.PLUGINS_KEY = 'logging_plugins'; | ||
function level(lvl) { | ||
@@ -71,3 +72,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
} | ||
return [4 /*yield*/, test_config_1.TestConfig.getValueOrDefault('testloglevel', test_log_level_1.TestLogLevel.info.name)]; | ||
return [4 /*yield*/, test_config_1.TestConfig.getValueOrDefault(TestLogOptions.LOGLEVEL_KEY, test_log_level_1.TestLogLevel.info.name)]; | ||
case 1: | ||
@@ -82,4 +83,26 @@ levelStr = _a.sent(); | ||
TestLogOptions.level = level; | ||
function pluginNames() { | ||
var pluginNames = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
pluginNames[_i] = arguments[_i]; | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pNames; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (pluginNames && pluginNames.length > 0) { | ||
test_config_1.TestConfig.setGlobalValue(TestLogOptions.PLUGINS_KEY, pluginNames.join(',')); | ||
} | ||
return [4 /*yield*/, test_config_1.TestConfig.getValueOrDefault(TestLogOptions.PLUGINS_KEY)]; | ||
case 1: | ||
pNames = _a.sent(); | ||
return [2 /*return*/, (pNames) ? pNames.split(',') : []]; | ||
} | ||
}); | ||
}); | ||
} | ||
TestLogOptions.pluginNames = pluginNames; | ||
})(TestLogOptions = exports.TestLogOptions || (exports.TestLogOptions = {})); | ||
exports.TestLogOptions = TestLogOptions; | ||
//# sourceMappingURL=test-log-options.js.map |
import { TestLogOptions } from "./test-log-options"; | ||
import { TestResult } from "../integrations/test-cases/test-result"; | ||
import { ILoggingPlugin } from "./plugins/ilogging-plugin"; | ||
import { IDisposable } from "../helpers/idisposable"; | ||
@@ -9,6 +10,7 @@ import { TestLogLevel } from "./test-log-level"; | ||
options: TestLogOptions; | ||
private plugins; | ||
constructor(options: TestLogOptions); | ||
private _lvl; | ||
level(): Promise<TestLogLevel>; | ||
private _plugins; | ||
plugins(): Promise<ILoggingPlugin[]>; | ||
trace(message: string): Promise<void>; | ||
@@ -15,0 +17,0 @@ debug(message: string): Promise<void>; |
@@ -38,22 +38,31 @@ "use strict"; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var test_log_options_1 = require("./test-log-options"); | ||
var ilogging_plugin_1 = require("./plugins/ilogging-plugin"); | ||
var test_log_level_1 = require("./test-log-level"); | ||
var plugin_loader_1 = require("../construction/plugin-loader"); | ||
var TestLog = /** @class */ (function () { | ||
function TestLog(options) { | ||
this.stepCount = 0; | ||
this.plugins = []; | ||
this.name = options.name; | ||
this.options = options; | ||
// create plugin instances unique to this logger | ||
var pluginCtors = ilogging_plugin_1.ILoggingPlugin.getPluginConstructors(); | ||
for (var i = 0; i < pluginCtors.length; i++) { | ||
try { | ||
this.plugins.push(new pluginCtors[i]()); | ||
} | ||
catch (e) { | ||
this.warn("unable to create instance of ILoggingPlugin due to: " + e); | ||
} | ||
} | ||
} | ||
@@ -82,2 +91,27 @@ TestLog.prototype.level = function () { | ||
}; | ||
TestLog.prototype.plugins = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var names, _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!!this._plugins) return [3 /*break*/, 4]; | ||
_a = this.options.pluginNames; | ||
if (_a) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, test_log_options_1.TestLogOptions.pluginNames()]; | ||
case 1: | ||
_a = (_c.sent()); | ||
_c.label = 2; | ||
case 2: | ||
names = _a; | ||
_b = this; | ||
return [4 /*yield*/, plugin_loader_1.PluginLoader.load.apply(plugin_loader_1.PluginLoader, __spread(names))]; | ||
case 3: | ||
_b._plugins = _c.sent(); | ||
_c.label = 4; | ||
case 4: return [2 /*return*/, this._plugins]; | ||
} | ||
}); | ||
}); | ||
}; | ||
TestLog.prototype.trace = function (message) { | ||
@@ -181,3 +215,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var l, i, p, enabled, e_1; | ||
var l, plugins, i, p, enabled, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -191,27 +225,30 @@ switch (_a.label) { | ||
} | ||
return [4 /*yield*/, this.plugins()]; | ||
case 2: | ||
plugins = _a.sent(); | ||
i = 0; | ||
_a.label = 2; | ||
case 2: | ||
if (!(i < this.plugins.length)) return [3 /*break*/, 9]; | ||
p = this.plugins[i]; | ||
_a.label = 3; | ||
case 3: | ||
_a.trys.push([3, 7, , 8]); | ||
if (!(i < plugins.length)) return [3 /*break*/, 10]; | ||
p = plugins[i]; | ||
_a.label = 4; | ||
case 4: | ||
_a.trys.push([4, 8, , 9]); | ||
return [4 /*yield*/, p.enabled()]; | ||
case 4: | ||
case 5: | ||
enabled = _a.sent(); | ||
if (!enabled) return [3 /*break*/, 6]; | ||
if (!enabled) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, p.log(level, message)]; | ||
case 5: | ||
case 6: | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: return [3 /*break*/, 8]; | ||
case 7: | ||
_a.label = 7; | ||
case 7: return [3 /*break*/, 9]; | ||
case 8: | ||
e_1 = _a.sent(); | ||
console.log(TestLog.format(this.name, test_log_level_1.TestLogLevel.warn, "unable to send log message to '" + p.name + "' plugin due to: " + e_1)); | ||
return [3 /*break*/, 8]; | ||
case 8: | ||
return [3 /*break*/, 9]; | ||
case 9: | ||
i++; | ||
return [3 /*break*/, 2]; | ||
case 9: return [2 /*return*/]; | ||
return [3 /*break*/, 3]; | ||
case 10: return [2 /*return*/]; | ||
} | ||
@@ -223,32 +260,34 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var i, p, enabled, r, e_2; | ||
var plugins, i, p, enabled, r, e_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
case 0: return [4 /*yield*/, this.plugins()]; | ||
case 1: | ||
plugins = _a.sent(); | ||
i = 0; | ||
_a.label = 1; | ||
case 1: | ||
if (!(i < this.plugins.length)) return [3 /*break*/, 8]; | ||
p = this.plugins[i]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 6, , 7]); | ||
if (!(i < plugins.length)) return [3 /*break*/, 9]; | ||
p = plugins[i]; | ||
_a.label = 3; | ||
case 3: | ||
_a.trys.push([3, 7, , 8]); | ||
return [4 /*yield*/, p.enabled()]; | ||
case 3: | ||
case 4: | ||
enabled = _a.sent(); | ||
if (!enabled) return [3 /*break*/, 5]; | ||
if (!enabled) return [3 /*break*/, 6]; | ||
r = result.clone(); | ||
return [4 /*yield*/, p.logResult(r)]; | ||
case 4: | ||
case 5: | ||
_a.sent(); | ||
_a.label = 5; | ||
case 5: return [3 /*break*/, 7]; | ||
case 6: | ||
_a.label = 6; | ||
case 6: return [3 /*break*/, 8]; | ||
case 7: | ||
e_2 = _a.sent(); | ||
console.log(TestLog.format(this.name, test_log_level_1.TestLogLevel.warn, "unable to send result to '" + p.name + "' plugin due to: " + e_2)); | ||
return [3 /*break*/, 7]; | ||
case 7: | ||
return [3 /*break*/, 8]; | ||
case 8: | ||
i++; | ||
return [3 /*break*/, 1]; | ||
case 8: return [2 /*return*/]; | ||
return [3 /*break*/, 2]; | ||
case 9: return [2 /*return*/]; | ||
} | ||
@@ -260,31 +299,33 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var i, p, enabled, e_3; | ||
var plugins, i, p, enabled, e_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
case 0: return [4 /*yield*/, this.plugins()]; | ||
case 1: | ||
plugins = _a.sent(); | ||
i = 0; | ||
_a.label = 1; | ||
case 1: | ||
if (!(i < this.plugins.length)) return [3 /*break*/, 8]; | ||
p = this.plugins[i]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 6, , 7]); | ||
if (!(i < plugins.length)) return [3 /*break*/, 9]; | ||
p = plugins[i]; | ||
_a.label = 3; | ||
case 3: | ||
_a.trys.push([3, 7, , 8]); | ||
return [4 /*yield*/, p.enabled()]; | ||
case 3: | ||
case 4: | ||
enabled = _a.sent(); | ||
if (!enabled) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.plugins[i].finalise()]; | ||
case 4: | ||
if (!enabled) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, plugins[i].finalise()]; | ||
case 5: | ||
_a.sent(); | ||
_a.label = 5; | ||
case 5: return [3 /*break*/, 7]; | ||
case 6: | ||
_a.label = 6; | ||
case 6: return [3 /*break*/, 8]; | ||
case 7: | ||
e_3 = _a.sent(); | ||
console.log(TestLog.format(this.name, test_log_level_1.TestLogLevel.warn, "unable to call finalise on " + p.name + " due to: " + e_3)); | ||
return [3 /*break*/, 7]; | ||
case 7: | ||
return [3 /*break*/, 8]; | ||
case 8: | ||
i++; | ||
return [3 /*break*/, 1]; | ||
case 8: return [2 /*return*/]; | ||
return [3 /*break*/, 2]; | ||
case 9: return [2 /*return*/]; | ||
} | ||
@@ -291,0 +332,0 @@ }); |
{ | ||
"name": "aft-core", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Automation Framework for Testing (AFT) package supporting JavaScript unit, integration and functional testing", | ||
@@ -37,3 +37,3 @@ "repository": { | ||
"@types/jasmine": "^3.4.4", | ||
"@types/node": "^12.7.12", | ||
"@types/node": "^12.12.35", | ||
"@types/uuid": "3.4.6", | ||
@@ -40,0 +40,0 @@ "jasmine": "^3.5.0", |
@@ -48,5 +48,13 @@ # AFT-Core | ||
### Logging Plugin | ||
to create a logging plugin you simply need to implment the `ILoggingPlugin` interface and add `@ILoggingPlugin.register` above the class. | ||
to create a logging plugin you simply need to implment the `ILoggingPlugin` interface in a class with a constructor accepting no arguments. Then, in your `aftconfig.json` add the following (where your `ILoggingPlugin` implementations are contained in files at `./relative/path/to/logging-plugin1.ts` and `/full/path/to/logging-plugin2.ts`): | ||
```json | ||
{ | ||
"logging_plugins": "./relative/path/to/logging-plugin1,/full/path/to/logging-plugin2" | ||
} | ||
``` | ||
``` | ||
NOTE: if the plugins are referenced as external npm packages you may leave off the path and just reference by package name | ||
``` | ||
#### Example Logging Plugin | ||
```typescript | ||
@ILoggingPlugin.register | ||
export class ExternalLogger implements ILoggingPlugin { | ||
@@ -53,0 +61,0 @@ name: string = 'externallogger'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
136266
103
2184
84
0
5