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

View File

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

View File

@ -45,5 +45,8 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "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', zone: 'gitzone',
company: 'Lossless GmbH', company: 'Lossless GmbH',
companyunit: 'Lossless Cloud', companyunit: 'Lossless Cloud',
containerName: 'testing' containerName: 'testing',
} },
}); });
}); });
tap.test('should enable console logging', async () => { tap.test('should enable console logging', async () => {
testSmartLog.enableConsole({ testSmartLog.enableConsole({
captureAll: true captureAll: true,
}); });
console.log('this is a normal log that should be captured'); console.log('this is a normal log that should be captured');
console.log(new Error('hi there')); console.log(new Error('hi there'));

View File

@ -21,7 +21,7 @@ export class LogGroup {
type: 'none', type: 'none',
group: this.groupId, group: this.groupId,
instance: this.smartlogRef.uniInstanceId, 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 * enables console logging
*/ */
public enableConsole(optionsArg?: { captureAll: boolean }) { 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; this.consoleEnabled = true;
} }
@ -88,9 +58,9 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
...{ ...{
id: plugins.isounique.uni(), id: plugins.isounique.uni(),
type: 'none', type: 'none',
instance: this.uniInstanceId instance: this.uniInstanceId,
}, },
...correlationArg ...correlationArg,
}; };
if (this.consoleEnabled) { if (this.consoleEnabled) {
@ -103,7 +73,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
context: this.logContext, context: this.logContext,
level: logLevelArg, level: logLevelArg,
correlation: correlationArg, correlation: correlationArg,
message: logMessageArg message: logMessageArg,
}; };
if (logDataArg) { if (logDataArg) {
logPackage.data = logDataArg; logPackage.data = logDataArg;
@ -117,7 +87,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
logDataArg?: any, logDataArg?: any,
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = { correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
id: plugins.isounique.uni(), id: plugins.isounique.uni(),
type: 'none' type: 'none',
} }
) { ) {
if (this.consoleEnabled) { if (this.consoleEnabled) {
@ -129,7 +99,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
context: this.logContext, context: this.logContext,
level: logLevelArg, level: logLevelArg,
message: logMessageArg, message: logMessageArg,
correlation: correlationArg correlation: correlationArg,
}); });
} }