Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bitdiver/runner-server

Package Overview
Dependencies
Maintainers
2
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bitdiver/runner-server - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

tests/LogAdapterFileTest.js

103

lib/LogAdapterFile.js

@@ -58,8 +58,39 @@ 'use strict';

constructor(opts) {
const param = (0, _extends3.default)({ targetDir: 'log' }, opts);
const param = (0, _extends3.default)({ targetDir: 'log', logLevel: 'warn' }, opts);
this.targetDir = param.targetDir;
this.logAdapterLogLevel = param.logLevel;
// eslint-disable-next-line no-console
console.log('LogAdapterFile configured log level: ' + this.logAdapterLogLevel);
}
/**
* Gets a numeric loglevel by loglevel symbol
* @param loglevel {string} the loglevel to calc the numeric value for
* @param logLevel {number} the numeric value
*/
_getLogLevel(logLevel) {
if (LEVEL_DEBUG === logLevel) {
return 1;
} else if (LEVEL_INFO === logLevel) {
return 2;
} else if (LEVEL_WARNING === logLevel) {
return 3;
} else if (LEVEL_ERROR === logLevel) {
return 4;
} else if (LEVEL_FATAL === logLevel) {
return 5;
}
}
/**
* Function which determines if a log message should be logged
* @param messageLogLevel {string} the message loglevel
*/
_messageShouldBeLogged(messageLogLevel) {
return this._getLogLevel(messageLogLevel) >= this._getLogLevel(this.logAdapterLogLevel);
}
/**
* @param data {object} The object with the data to be logged and the needed meta data

@@ -97,43 +128,47 @@ * const logMessage = {

const data = logMessage.data;
const logLevel = logMessage.logLevel;
// const logLevel = logMessage.logLevel
const time = logMessage.meta.time ? logMessage.meta.time : Date.now();
const messageLogLevel = meta.logLevel;
const targetPath = [this.targetDir, `Run_${String(meta.run.start)}`];
if (meta.tc !== undefined && meta.tc.name !== undefined) {
const tcCountAllLength = String(meta.tc.countAll).length;
const tcNumberStr = (0, _sprintfJs.sprintf)(`%0${tcCountAllLength}d`, meta.tc.countCurrent);
const messageShouldBeLogged = this._messageShouldBeLogged(messageLogLevel, this.logAdapterLogLevel);
targetPath.push(`TC_${tcNumberStr}_${meta.tc.name}`);
if (meta.step !== undefined && meta.step.name !== undefined) {
const stringCountLength = String(meta.step.countCurrent).length;
const stepNumber = (0, _sprintfJs.sprintf)(`%0${stringCountLength}d`, meta.step.countCurrent);
targetPath.push(`Step_${stepNumber}_${meta.step.name}`);
if (messageShouldBeLogged) {
const time = logMessage.meta.time ? logMessage.meta.time : Date.now();
const targetPath = [this.targetDir, `Run_${String(meta.run.start)}`];
if (meta.tc !== undefined && meta.tc.name !== undefined) {
const tcCountAllLength = String(meta.tc.countAll).length;
const tcNumberStr = (0, _sprintfJs.sprintf)(`%0${tcCountAllLength}d`, meta.tc.countCurrent);
targetPath.push(`TC_${tcNumberStr}_${meta.tc.name}`);
if (meta.step !== undefined && meta.step.name !== undefined) {
const stringCountLength = String(meta.step.countCurrent).length;
const stepNumber = (0, _sprintfJs.sprintf)(`%0${stringCountLength}d`, meta.step.countCurrent);
targetPath.push(`Step_${stepNumber}_${meta.step.name}`);
}
}
}
const dir = _path2.default.join(...targetPath);
const dir = _path2.default.join(...targetPath);
return new _promise2.default(async (resolve, reject) => {
(0, _mkdirp2.default)(dir, async err => {
if (err) {
reject(err);
} else {
const timeStamp = (0, _moment2.default)(Date.now()).format('YYYY-MM-DD_HH:mm:ss.SSS');
// const fileName = `${timeStamp}_${logLevel}.json`
// targetPath.push(fileName)
//
// const file = path.join(...targetPath)
return new _promise2.default(async (resolve, reject) => {
(0, _mkdirp2.default)(dir, async err => {
if (err) {
reject(err);
} else {
const timeStamp = (0, _moment2.default)(Date.now()).format('YYYY-MM-DD_HH:mm:ss.SSS');
// const fileName = `${timeStamp}_${logLevel}.json`
// targetPath.push(fileName)
//
// const file = path.join(...targetPath)
const file = await this.getFileName(targetPath, timeStamp, logLevel);
const file = await this.getFileName(targetPath, timeStamp, messageLogLevel);
_jsonfile2.default.writeFile(file, { meta: { time }, data, logLevel }, { spaces: 2 }, err1 => {
if (err1) {
reject(err1);
}
resolve();
});
}
_jsonfile2.default.writeFile(file, { meta: { time }, data, messageLogLevel }, { spaces: 2 }, err1 => {
if (err1) {
reject(err1);
}
resolve();
});
}
});
});
});
}
}

@@ -140,0 +175,0 @@

{
"name": "@bitdiver/runner-server",
"version": "1.3.1",
"version": "1.4.0",
"description": "",

@@ -61,3 +61,3 @@ "main": "lib/index.js",

"@bitdiver/definition": "1.0.2",
"@bitdiver/model": "1.3.2",
"@bitdiver/model": "1.3.3",
"jsonfile": "4.0.0",

@@ -64,0 +64,0 @@ "mkdirp": "0.5.1",

@@ -9,4 +9,4 @@ import { StepBase } from '@bitdiver/model'

async doRun() {
return this.logger.info('Yeah, it runs')
return this.logAdapter.logInfo('Yeah, it runs')
}
}

@@ -14,4 +14,4 @@ import { StepBase, STEP_TYPE_SINGLE } from '@bitdiver/model'

async doRun() {
return this.logger.info('Yeah, it runs')
return this.logAdapter.logInfo('Yeah, it runs')
}
}

@@ -328,3 +328,3 @@ import { createSuite, createRegistry } from './helper/helper'

class: 'runOnError',
name: `Step single wich runs after Error`,
name: `Step which runs after Error`,
description: `Desc for step`,

@@ -358,6 +358,74 @@ })

})
const logs = runner.logAdapter.logs[runner.environmentRun.id].testcases
expect(logs['TC 1'].steps['Step which runs after Error'].logs[2]).toEqual({
countAll: 6,
countCurrent: 6,
data: { message: 'Step run' },
logLevel: 'info',
})
done()
},
TIMEOUT
)
test(
'Run test case with step singleRunOnError=true (Linear Execution)',
async done => {
const options = {
parallelExecution: false,
extendedRes: true,
posTc: 1, // The tc where to store the action
posStep: 1, // The step where to store the action
action: 'logError', // The action of the testcase data
value: 'ERROR Single', // The value for the action
}
logAdapter.clear()
const suiteDefiniton = createSuite()
const data = {
run: {
action: options.action,
value: options.value,
},
}
suiteDefiniton.testcases[options.posTc].data[options.posStep] = data
const runOnErrorStep = new StepDefinition({
class: 'singleRunOnError',
name: `Step single which runs after Error`,
description: `Desc for step`,
})
suiteDefiniton.steps[runOnErrorStep.id] = runOnErrorStep
for (const tc of suiteDefiniton.testcases) {
tc.data.push(undefined)
}
// The helper has added the same array to all the testcases,
// so only push this additional once
suiteDefiniton.testcases[0].steps.push(runOnErrorStep.id)
const runner = new Runner({
stepRegistry: registry,
logAdapter,
parallelExecution: options.parallelExecution,
})
await runner.run(suiteDefiniton)
// no check the log status
const res = checkTcStatus(options.extendedRes)
expect(res).toEqual({
'TC 1': { logCount: 2, status: 4, stepCount: 3 },
'TC 2': { logCount: 2, status: 4, stepCount: 3 },
'TC 3': { logCount: 2, status: 4, stepCount: 3 },
})
const logs = runner.logAdapter.logs[runner.environmentRun.id].testcases
debugger
const logs = runner.logAdapter.logs[runner.environmentRun.id].testcases
expect(
logs['TC 1'].steps['Step single wich runs after Error'].logs[2]
logs['TC 1'].steps['Step single which runs after Error'].logs[2]
).toEqual({

@@ -364,0 +432,0 @@ countAll: 6,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc