@bitdiver/model
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.DIR_BASE_DATA = exports.LEVEL_FATAL = exports.LEVEL_ERROR = exports.LEVEL_WARNING = exports.LEVEL_INFO = exports.LEVEL_DEBUG = exports.STEP_TYPE_SERVER_ONLY = exports.STEP_TYPE_SINGLE = exports.STEP_TYPE_NORMAL = exports.STATUS_FATAL = exports.STATUS_ERROR = exports.STATUS_WARNING = exports.STATUS_UNKNOWN = exports.STATUS_OK = exports.StepRegistry = exports.StepBase = exports.getLogAdapterMemory = exports.getLogAdapter = exports.LogAdapterMemory = exports.LogAdapter = exports.EnvironmentTestcase = exports.EnvironmentRun = undefined; | ||
exports.generateLogs = exports.DIR_BASE_DATA = exports.LEVEL_FATAL = exports.LEVEL_ERROR = exports.LEVEL_WARNING = exports.LEVEL_INFO = exports.LEVEL_DEBUG = exports.STEP_TYPE_SERVER_ONLY = exports.STEP_TYPE_SINGLE = exports.STEP_TYPE_NORMAL = exports.STATUS_FATAL = exports.STATUS_ERROR = exports.STATUS_WARNING = exports.STATUS_UNKNOWN = exports.STATUS_OK = exports.StepRegistry = exports.StepBase = exports.getLogAdapterMemory = exports.getLogAdapter = exports.LogAdapterMemory = exports.LogAdapter = exports.EnvironmentTestcase = exports.EnvironmentRun = undefined; | ||
@@ -31,2 +31,4 @@ var _EnvironmentRun = require('./EnvironmentRun'); | ||
var _logHelper = require('./logHelper'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -55,2 +57,3 @@ | ||
exports.LEVEL_FATAL = _LogAdapter.LEVEL_FATAL; | ||
exports.DIR_BASE_DATA = _StepBase.DIR_BASE_DATA; | ||
exports.DIR_BASE_DATA = _StepBase.DIR_BASE_DATA; | ||
exports.generateLogs = _logHelper.generateLogs; |
@@ -43,3 +43,3 @@ 'use strict'; | ||
* start: <time>, | ||
* id: 'id' | ||
* id: 'id' // RunEnvironment ID | ||
* }, | ||
@@ -49,3 +49,3 @@ * tc:{ | ||
* tcCountAll: tcCountAll, | ||
* id: 'id', | ||
* id: 'id', // TestcaseEnvironment ID | ||
* name: 'great tc name' | ||
@@ -56,3 +56,3 @@ * }, | ||
* stepCountAll: stepCountAll, | ||
* id: 'id', | ||
* id: 'id', // testcase instance | ||
* name: 'great step name' | ||
@@ -59,0 +59,0 @@ * typ: ('singel'| ''|) |
@@ -14,2 +14,4 @@ 'use strict'; | ||
var _logHelper = require('./logHelper'); | ||
var _uuid = require('uuid'); | ||
@@ -40,3 +42,3 @@ | ||
constructor(opts = {}) { | ||
this.logger = opts.logAdapter ? opts.logAdapter : (0, _LogAdapter.getLogAdapter)(); | ||
this.logAdapter = opts.logAdapter ? opts.logAdapter : (0, _LogAdapter.getLogAdapter)(); | ||
@@ -62,5 +64,2 @@ this.type = opts.type ? opts.type : STEP_TYPE_NORMAL; | ||
// each step starts with this status | ||
this._status = _status.STATUS_OK; | ||
// Normaly a step will only be executed if there is data defined for the testcase. | ||
@@ -106,4 +105,2 @@ // but some steps do not need any data. Then this must be set to false. | ||
logWarning(options) { | ||
this.status = _status.STATUS_WARNING; | ||
this._setTestcaseStatus(_status.STATUS_WARNING); | ||
return this._log(options, _LogAdapter.LEVEL_WARNING); | ||
@@ -119,4 +116,2 @@ } | ||
logError(options) { | ||
this.status = _status.STATUS_ERROR; | ||
this._setTestcaseStatus(_status.STATUS_ERROR); | ||
return this._log(options, _LogAdapter.LEVEL_ERROR); | ||
@@ -132,24 +127,8 @@ } | ||
logFatal(options) { | ||
this.status = _status.STATUS_FATAL; | ||
// On a fatal error we would like to stop the whole test | ||
this.environmentRun.status = _status.STATUS_FATAL; | ||
this._setTestcaseStatus(_status.STATUS_FATAL); | ||
return this._log(options, _LogAdapter.LEVEL_FATAL); | ||
} | ||
_setTestcaseStatus(status) { | ||
if (this.type === STEP_TYPE_NORMAL) { | ||
this.environmentTestcase.status = status; | ||
} else { | ||
for (const tcEnv of this.environmentTestcase) { | ||
tcEnv.status = status; | ||
} | ||
this.environmentRun.status = status; | ||
} | ||
} | ||
/** | ||
* Calls the logger with the given messageObj | ||
* Calls the logger with the given messageObj. | ||
* If this is a single step the log will be written for each testcase environment | ||
* @param messageObj {object|string} Either a message or a json object to be logged | ||
@@ -160,75 +139,6 @@ * @param logLevel {string} The loglevel to be used | ||
_log(messageObj, logLevel = _LogAdapter.LEVEL_INFO) { | ||
let data = {}; | ||
if (messageObj instanceof Error) { | ||
data = { | ||
message: messageObj.message, | ||
stack: messageObj.stack | ||
}; | ||
} else if (typeof messageObj === 'string') { | ||
data = { message: messageObj }; | ||
} else { | ||
data = messageObj; | ||
} | ||
const meta = { | ||
run: { | ||
start: this.environmentRun.startTime, | ||
id: this.environmentRun.id | ||
}, | ||
step: { | ||
countCurrent: this.countCurrent, | ||
countAll: this.countAll, | ||
id: this.stepInstanceId, | ||
name: this.name, | ||
type: this.type, | ||
status: this.status | ||
}, | ||
time: Date.now() | ||
}; | ||
if (this.type === STEP_TYPE_NORMAL) { | ||
meta.tc = { | ||
countAll: this.environmentTestcase.countAll, | ||
countCurrent: this.environmentTestcase.countCurrent, | ||
id: this.environmentTestcase.id, | ||
name: this.environmentTestcase.name | ||
}; | ||
return this.logger.log({ | ||
data, | ||
meta, | ||
logLevel | ||
}); | ||
} | ||
// Single steps | ||
const promises = []; | ||
for (const tcEnv of this.environmentTestcase) { | ||
meta.tc = { | ||
countAll: tcEnv.countAll, | ||
countCurrent: tcEnv.countCurrent, | ||
id: tcEnv.id, | ||
name: tcEnv.name | ||
}; | ||
promises.push(this.logger.log({ | ||
data, | ||
meta, | ||
logLevel | ||
})); | ||
} | ||
return _promise2.default.all(promises); | ||
return (0, _logHelper.generateLogs)(this.environmentRun, this.environmentTestcase, this.logAdapter, messageObj, logLevel, this); | ||
} | ||
/** | ||
* Set the status of the step | ||
* @param newStatus {number} The new status for the testcase | ||
*/ | ||
set status(newStatus) { | ||
if (newStatus > this._status) { | ||
this._status = newStatus; | ||
} | ||
} | ||
get status() { | ||
return this._status; | ||
} | ||
/** | ||
* First the start method will be called for all the step instances of the step | ||
@@ -235,0 +145,0 @@ * @return promise {promise} A promise to signal that the method is finished |
@@ -1,1 +0,1 @@ | ||
{"name":"@bitdiver/model","version":"1.0.6","description":"","main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/bitdiver/model.git"},"bugs":{"url":"https://github.com/bitdiver/model/issues"},"homepage":"https://github.com/bitdiver/model#readme","scripts":{"build":"npm run src_format && npm run src_lint && babel src -d lib","src_lint":"eslint src tests","src_format":"prettier --no-semi --single-quote --trailing-comma es5 --write \"{src,tests}/**/*.js\"","test_only":"jest","test":"npm run src_format && npm run src_lint && npm run build && jest -c jest.config.json","semantic-release":"semantic-release pre && npm publish --access public && semantic-release post","debug":"npm run build && node --inspect-brk ./node_modules/.bin/jest -i --config=./jest.config.json","prepublish":"npm run build"},"contributors":[{"name":"Torsten Link","email":"torstenlink@gmx.de"},{"name":"Markus Felten","email":"markus.felten@gmx.de"}],"license":"ISC","devDependencies":{"assert":"^1.4.1","babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-eslint":"^8.0.2","babel-jest":"^21.2.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-plugin-transform-runtime":"^6.23.0","babel-polyfill":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-flow":"^6.23.0","babel-register":"^6.26.0","cz-conventional-changelog":"^2.1.0","eslint":"^4.12.1","eslint-config-prettier":"^2.9.0","eslint-plugin-babel":"^4.0.0","jest":"^21.2.1","jest-cli":"^21.2.1","jest-environment-node-debug":"^2.0.0","prettier":"^1.8.2","regenerator-runtime":"^0.11.0","semantic-release":"^8.2.3"},"dependencies":{"uuid":"^3.1.0"}} | ||
{"name":"@bitdiver/model","version":"1.1.0","description":"","main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/bitdiver/model.git"},"bugs":{"url":"https://github.com/bitdiver/model/issues"},"homepage":"https://github.com/bitdiver/model#readme","scripts":{"build":"npm run src_format && npm run src_lint && babel src -d lib","src_lint":"eslint src tests","src_format":"prettier --no-semi --single-quote --trailing-comma es5 --write \"{src,tests}/**/*.js\"","test_only":"jest","test":"npm run src_format && npm run src_lint && npm run build && jest -c jest.config.json","semantic-release":"semantic-release pre && npm publish --access public && semantic-release post","debug":"npm run build && node --inspect-brk ./node_modules/.bin/jest -i --config=./jest.config.json","prepublish":"npm run build"},"contributors":[{"name":"Torsten Link","email":"torstenlink@gmx.de"},{"name":"Markus Felten","email":"markus.felten@gmx.de"}],"license":"ISC","devDependencies":{"assert":"^1.4.1","babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-eslint":"^8.0.2","babel-jest":"^21.2.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-plugin-transform-runtime":"^6.23.0","babel-polyfill":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-flow":"^6.23.0","babel-register":"^6.26.0","cz-conventional-changelog":"^2.1.0","eslint":"^4.12.1","eslint-config-prettier":"^2.9.0","eslint-plugin-babel":"^4.0.0","jest":"^21.2.1","jest-cli":"^21.2.1","jest-environment-node-debug":"^2.0.0","prettier":"^1.8.2","regenerator-runtime":"^0.11.0","semantic-release":"^8.2.3"},"dependencies":{"uuid":"^3.1.0"}} |
import { | ||
StepBase, | ||
STATUS_OK, | ||
STATUS_WARNING, | ||
STATUS_ERROR, | ||
STATUS_FATAL, | ||
getLogAdapterMemory, | ||
@@ -14,25 +10,5 @@ EnvironmentRun, | ||
test('Status: default status', () => { | ||
const step = new StepBase() | ||
expect(step.status).toEqual(STATUS_OK) | ||
}) | ||
test('Status: set status', () => { | ||
const step = new StepBase() | ||
step.status = STATUS_WARNING | ||
expect(step.status).toEqual(STATUS_WARNING) | ||
}) | ||
test('Status: can not set status to better value as before.', () => { | ||
const step = new StepBase() | ||
step.status = STATUS_WARNING | ||
expect(step.status).toEqual(STATUS_WARNING) | ||
step.status = STATUS_OK | ||
expect(step.status).toEqual(STATUS_WARNING) | ||
}) | ||
test('Logging: info', () => { | ||
const step = getStep() | ||
step.logInfo('myInfo') | ||
expect(step.status).toEqual(STATUS_OK) | ||
expect(logAdapterMemory.logs).toEqual({ | ||
@@ -67,4 +43,2 @@ myRunId: { | ||
step.logWarning('myError') | ||
expect(step.status).toEqual(STATUS_WARNING) | ||
expect(step.environmentTestcase.status).toEqual(STATUS_WARNING) | ||
expect(logAdapterMemory.logs).toEqual({ | ||
@@ -99,4 +73,2 @@ myRunId: { | ||
step.logError('myError') | ||
expect(step.status).toEqual(STATUS_ERROR) | ||
expect(step.environmentTestcase.status).toEqual(STATUS_ERROR) | ||
expect(logAdapterMemory.logs).toEqual({ | ||
@@ -131,4 +103,2 @@ myRunId: { | ||
step.logFatal('myError') | ||
expect(step.status).toEqual(STATUS_FATAL) | ||
expect(step.environmentTestcase.status).toEqual(STATUS_FATAL) | ||
expect(logAdapterMemory.logs).toEqual({ | ||
@@ -135,0 +105,0 @@ myRunId: { |
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
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
44632
25
857