skutter
Version:
Skutter: Opinionated BDD Browser based test framework
90 lines (89 loc) • 2.98 kB
JavaScript
;
const execution_marks_1 = require("./execution-marks");
const stop_watch_1 = require("../services/stop-watch");
const logged_message_1 = require("./../result-aggregator/logged-message");
let _log = null;
let _featureSetupStore = [];
let _scenarioSetupStore = [];
let _stepStore = new Map();
let _scenarioTeardownStore = [];
let _featureTeardownStore = [];
let _targetStore = null;
let _contextStopWatch = null;
class ExecutionLogger {
constructor(consoleLog) {
this._stepStack = [];
_log = consoleLog;
}
log(message, ...args) {
if (!(_targetStore === undefined || _targetStore === null)) {
let elapsed = _contextStopWatch.elapsedMilliseconds;
_targetStore.push(new logged_message_1.LoggedMessage(elapsed, message));
return;
}
try {
_log.call(this, message, ...args);
}
catch (consoleException) {
}
}
init() {
_featureSetupStore = [];
_scenarioSetupStore = [];
_stepStore = new Map();
_scenarioTeardownStore = [];
_featureTeardownStore = [];
_targetStore = null;
}
mark(executionMark, stepId) {
switch (executionMark) {
case execution_marks_1.ExecutionMarks.FeatureSetup:
this.init();
_targetStore = _featureSetupStore;
break;
case execution_marks_1.ExecutionMarks.ScenarioSetup:
_targetStore = _scenarioSetupStore;
break;
case execution_marks_1.ExecutionMarks.StepStart:
this._stepStack.push(stepId);
_stepStore.set(stepId, []);
_targetStore = _stepStore.get(stepId);
break;
case execution_marks_1.ExecutionMarks.StepEnd:
this._stepStack.pop();
if (this._stepStack) {
let lastStepTarget = this._stepStack[this._stepStack.length - 1];
_targetStore = _stepStore.get(lastStepTarget);
}
break;
case execution_marks_1.ExecutionMarks.ScenarioTeardown:
_targetStore = _scenarioTeardownStore;
break;
case execution_marks_1.ExecutionMarks.FeatureTeardown:
_targetStore = _featureTeardownStore;
break;
}
_contextStopWatch = new stop_watch_1.StopWatch();
_contextStopWatch.start();
}
getFeatureSetupLogs() {
return _featureSetupStore;
}
getScenarioSetupLogs() {
return _scenarioSetupStore;
}
getStepLogs(stepId) {
return _stepStore.get(stepId);
}
getScenarioTeardownLogs() {
return _scenarioTeardownStore;
}
getFeatureTeardownLogs() {
return _featureTeardownStore;
}
release() {
console.log = _log;
_log = undefined;
}
}
exports.ExecutionLogger = ExecutionLogger;