fix(core): update

This commit is contained in:
Philipp Kunz 2020-09-07 21:30:02 +00:00
parent 3066503a70
commit f8a49e033d
7 changed files with 80 additions and 49 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
audit:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

View File

@ -45,5 +45,8 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

48
test/test.browser.ts Normal file
View File

@ -0,0 +1,48 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartlog from '../ts/index';
let testConsoleLog: smartlog.ConsoleLog;
let testSmartLog: smartlog.Smartlog;
tap.test('should produce a valid ConsoleLog instance', async () => {
testConsoleLog = new smartlog.ConsoleLog();
testConsoleLog.log('ok', 'this is ok');
});
tap.test('should produce instance of Smartlog', async () => {
testSmartLog = new smartlog.Smartlog({
logContext: {
environment: 'test',
runtime: 'node',
zone: 'gitzone',
company: 'Lossless GmbH',
companyunit: 'Lossless Cloud',
containerName: 'testing',
},
});
});
tap.test('should enable console logging', async () => {
testSmartLog.enableConsole({
captureAll: true,
});
console.log('this is a normal log that should be captured');
console.log(new Error('hi there'));
testSmartLog.log('info', 'this should only be printed once');
});
tap.test('should be able to log things', async () => {
testSmartLog.log('silly', 'hi');
});
tap.test('should create a log group', async () => {
const logGroup = testSmartLog.createLogGroup('some cool transaction');
logGroup.log('info', 'this is logged from a log group');
});
tap.test('should catch error', async () => {
console.error(new Error('hey'));
// throw new Error('hey');
});
tap.start();

View File

@ -17,14 +17,14 @@ tap.test('should produce instance of Smartlog', async () => {
zone: 'gitzone',
company: 'Lossless GmbH',
companyunit: 'Lossless Cloud',
containerName: 'testing'
}
containerName: 'testing',
},
});
});
tap.test('should enable console logging', async () => {
testSmartLog.enableConsole({
captureAll: true
captureAll: true,
});
console.log('this is a normal log that should be captured');
console.log(new Error('hi there'));

View File

@ -21,7 +21,7 @@ export class LogGroup {
type: 'none',
group: this.groupId,
instance: this.smartlogRef.uniInstanceId,
transaction: this.transactionId
transaction: this.transactionId,
});
}
}

View File

@ -35,36 +35,6 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
* enables console logging
*/
public enableConsole(optionsArg?: { captureAll: boolean }) {
if (process && optionsArg && optionsArg.captureAll) {
const write = process.stdout.write;
process.stdout.write = (...args) => {
const logString: string = args[0];
if (!logString.startsWith('LOG') && typeof logString === 'string') {
switch(true) {
case logString.substr(0, 20).includes('Error:'):
this.log('error', logString);
break;
default:
this.log('info', logString);
}
return;
}
// fileStream.write(args[0]);
write.apply(process.stdout, args);
return true;
};
process.stderr.write = (...args) => {
if (!args[0].startsWith('LOG')) {
this.log('error', args[0]);
return;
}
// fileStream.write(args[0]);
write.apply(process.stderr, args);
return true;
};
}
this.consoleEnabled = true;
}
@ -88,9 +58,9 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
...{
id: plugins.isounique.uni(),
type: 'none',
instance: this.uniInstanceId
instance: this.uniInstanceId,
},
...correlationArg
...correlationArg,
};
if (this.consoleEnabled) {
@ -103,7 +73,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
context: this.logContext,
level: logLevelArg,
correlation: correlationArg,
message: logMessageArg
message: logMessageArg,
};
if (logDataArg) {
logPackage.data = logDataArg;
@ -117,7 +87,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
logDataArg?: any,
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
id: plugins.isounique.uni(),
type: 'none'
type: 'none',
}
) {
if (this.consoleEnabled) {
@ -129,7 +99,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
context: this.logContext,
level: logLevelArg,
message: logMessageArg,
correlation: correlationArg
correlation: correlationArg,
});
}