From f8a49e033d6ab825e7def6efe5c5768d2bbdf832 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 7 Sep 2020 21:30:02 +0000 Subject: [PATCH] fix(core): update --- .gitlab-ci.yml | 26 ++++++++++++------ .vscode/settings.json | 2 +- package.json | 5 +++- test/test.browser.ts | 48 +++++++++++++++++++++++++++++++++ test/test.ts | 6 ++--- ts/smartlog.classes.loggroup.ts | 2 +- ts/smartlog.classes.smartlog.ts | 40 ++++----------------------- 7 files changed, 80 insertions(+), 49 deletions(-) create mode 100644 test/test.browser.ts diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8ebc8b5..9a4467e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 01d2b8d..3648eaa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,7 @@ "properties": { "projectType": { "type": "string", - "enum": ["website", "element", "service", "npm"] + "enum": ["website", "element", "service", "npm", "wcc"] } } } diff --git a/package.json b/package.json index ae3e824..ae32382 100644 --- a/package.json +++ b/package.json @@ -45,5 +45,8 @@ "cli.js", "npmextra.json", "readme.md" + ], + "browserslist": [ + "last 1 chrome versions" ] -} +} \ No newline at end of file diff --git a/test/test.browser.ts b/test/test.browser.ts new file mode 100644 index 0000000..e8598b5 --- /dev/null +++ b/test/test.browser.ts @@ -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(); diff --git a/test/test.ts b/test/test.ts index f058907..e8598b5 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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')); diff --git a/ts/smartlog.classes.loggroup.ts b/ts/smartlog.classes.loggroup.ts index 4862737..31d92c4 100644 --- a/ts/smartlog.classes.loggroup.ts +++ b/ts/smartlog.classes.loggroup.ts @@ -21,7 +21,7 @@ export class LogGroup { type: 'none', group: this.groupId, instance: this.smartlogRef.uniInstanceId, - transaction: this.transactionId + transaction: this.transactionId, }); } } diff --git a/ts/smartlog.classes.smartlog.ts b/ts/smartlog.classes.smartlog.ts index fedc2c3..e3f9ae0 100644 --- a/ts/smartlog.classes.smartlog.ts +++ b/ts/smartlog.classes.smartlog.ts @@ -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, }); }