improve tests to meet 70% coverage treshold

This commit is contained in:
Philipp Kunz 2018-03-02 00:13:09 +01:00
parent f60e582e48
commit bfa8b8d605
5 changed files with 164 additions and 12 deletions

4
dist/index.js vendored
View File

@ -8,7 +8,7 @@ class BeautyBrowser {
this.parseLog = (stringToParseArg) => {
const parseLogRegex = /^(success|ok|info|warn|error):\s(.*)/;
const regexResult = parseLogRegex.exec(stringToParseArg);
if (regexResult.length === 3) {
if (regexResult && regexResult.length === 3) {
return {
logType: regexResult[1],
logString: regexResult[2]
@ -53,4 +53,4 @@ class BeautyBrowser {
}
}
exports.BeautyBrowser = BeautyBrowser;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQVFBO0lBQUE7UUFLRTs7V0FFRztRQUNLLGFBQVEsR0FBRyxDQUFDLGdCQUF3QixFQUFvQixFQUFFO1lBQ2hFLE1BQU0sYUFBYSxHQUFHLHNDQUFzQyxDQUFDO1lBQzdELE1BQU0sV0FBVyxHQUFHLGFBQWEsQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztZQUN6RCxFQUFFLENBQUEsQ0FBQyxXQUFXLENBQUMsTUFBTSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQzVCLE1BQU0sQ0FBQztvQkFDTCxPQUFPLEVBQUUsV0FBVyxDQUFDLENBQUMsQ0FBQztvQkFDdkIsU0FBUyxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUM7aUJBQzFCLENBQUE7WUFDSCxDQUFDO1lBQUMsSUFBSSxDQUFDLENBQUM7Z0JBQ04sTUFBTSxDQUFDO29CQUNMLE9BQU8sRUFBRSxLQUFLO29CQUNkLFNBQVMsRUFBRSxnQkFBZ0I7aUJBQzVCLENBQUE7WUFDSCxDQUFDO1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LFNBQVMsRUFDMUIsbUNBQW1DLEVBQ25DLGdCQUFnQixDQUNqQixDQUFDO2dCQUNGLEtBQUssQ0FBQztZQUNSLEtBQUssS0FBSztnQkFDUixPQUFPLENBQUMsR0FBRyxDQUFDLGFBQWEsR0FBRyxTQUFTLEVBQUUsa0NBQWtDLEVBQUUsZ0JBQWdCLENBQUMsQ0FBQztnQkFDN0YsS0FBSyxDQUFDO1lBQ1I7Z0JBQ0UsT0FBTyxDQUFDLEdBQUcsQ0FBQyx1QkFBdUIsR0FBRyxTQUFTLEdBQUcsR0FBRyxDQUFDLENBQUM7Z0JBQ3ZELEtBQUssQ0FBQztRQUNWLENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUFsRUQsc0NBa0VDIn0=

View File

@ -11,6 +11,7 @@
"format": "(gitzone format)"
},
"devDependencies": {
"smartlog": "^1.0.3",
"tapbundle": "^2.0.0"
},
"dependencies": {

View File

@ -1,4 +1,20 @@
import { expect, tap } from 'tapbundle';
// preparation
import { ILogContext } from 'smartlog-interfaces';
import * as smartlog from 'smartlog'
const logger = smartlog.getDefaultLogger();
const logContext: ILogContext = {
company: 'Lossless GmbH',
companyunit: 'Lossless.Cloud',
containerName: 'testContainer',
environment: 'staging',
runtime: 'browser',
zone: 'serve.zone'
}
// import the module to test
import * as beautybrowser from '../ts/index';
let testBeautyBrowser: beautybrowser.BeautyBrowser;
@ -7,19 +23,36 @@ tap.test('first test', async () => {
testBeautyBrowser = new beautybrowser.BeautyBrowser()
});
tap.test('should log a message', async () => {
tap.test('should log a normal message', async () => {
testBeautyBrowser.handleLog({
logContext: {
company: 'Lossless GmbH',
companyunit: 'Lossless.Cloud',
containerName: 'testContainer',
environment: 'test',
runtime: 'browser',
zone: 'serve.zone'
},
logContext: logContext,
logLevel: 'info',
message: 'wait, what? Hi, this is a message!'
})
})
tap.test('should log a success message', async () => {
testBeautyBrowser.handleLog({
logContext: logContext,
logLevel: 'info',
message: 'success: Hi, this is a message!'
})
})
tap.test('should log a ok message', async () => {
testBeautyBrowser.handleLog({
logContext: logContext,
logLevel: 'info',
message: 'ok: Hi, this is a message!'
})
})
tap.test('should log a error message', async () => {
testBeautyBrowser.handleLog({
logContext: logContext,
logLevel: 'info',
message: 'error: Hi, this is a message!'
})
})
tap.start();

View File

@ -17,7 +17,7 @@ export class BeautyBrowser implements ILogDestination {
private parseLog = (stringToParseArg: string): IBeautyLogObject => {
const parseLogRegex = /^(success|ok|info|warn|error):\s(.*)/;
const regexResult = parseLogRegex.exec(stringToParseArg);
if(regexResult.length === 3) {
if(regexResult && regexResult.length === 3) {
return {
logType: regexResult[1],
logString: regexResult[2]

118
yarn.lock
View File

@ -26,6 +26,10 @@ assertion-error@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
async@^1.0.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
beautycolor@^1.0.7:
version "1.0.11"
resolved "https://registry.yarnpkg.com/beautycolor/-/beautycolor-1.0.11.tgz#71c5568d5a7ed5c144d3a54f753ad1b08862aea5"
@ -62,6 +66,42 @@ check-error@^1.0.1, check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
color-convert@^0.5.0:
version "0.5.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-0.5.3.tgz#bdb6c69ce660fadffe0b0007cc447e1b9f7282bd"
color-name@^1.0.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
color-string@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-0.3.0.tgz#27d46fb67025c5c2fa25993bfbf579e47841b991"
dependencies:
color-name "^1.0.0"
color@0.8.x:
version "0.8.0"
resolved "https://registry.yarnpkg.com/color/-/color-0.8.0.tgz#890c07c3fd4e649537638911cf691e5458b6fca5"
dependencies:
color-convert "^0.5.0"
color-string "^0.3.0"
colornames@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/colornames/-/colornames-0.0.2.tgz#d811fd6c84f59029499a8ac4436202935b92be31"
colors@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
colorspace@1.0.x:
version "1.0.1"
resolved "https://registry.yarnpkg.com/colorspace/-/colorspace-1.0.1.tgz#c99c796ed31128b9876a52e1ee5ee03a4a719749"
dependencies:
color "0.8.x"
text-hex "0.0.x"
deep-eql@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
@ -75,6 +115,14 @@ define-properties@^1.1.2:
foreach "^2.0.5"
object-keys "^1.0.8"
diagnostics@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/diagnostics/-/diagnostics-1.1.0.tgz#e1090900b49523e8527be20f081275205f2ae36a"
dependencies:
colorspace "1.0.x"
enabled "1.0.x"
kuler "0.0.x"
early@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/early/-/early-2.1.1.tgz#841e23254ea5dc54d8afaeee82f5ab65c00ee23c"
@ -83,6 +131,16 @@ early@^2.1.1:
smartq "^1.1.1"
typings-global "^1.0.16"
enabled@1.0.x:
version "1.0.2"
resolved "https://registry.yarnpkg.com/enabled/-/enabled-1.0.2.tgz#965f6513d2c2d1c5f4652b64a2e3396467fc2f93"
dependencies:
env-variable "0.0.x"
env-variable@0.0.x:
version "0.0.4"
resolved "https://registry.yarnpkg.com/env-variable/-/env-variable-0.0.4.tgz#0d6280cf507d84242befe35a512b5ae4be77c54e"
es-abstract@^1.5.1:
version "1.10.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864"
@ -105,6 +163,10 @@ es6-error@^4.0.2:
version "4.1.1"
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d"
fecha@^2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fecha/-/fecha-2.3.3.tgz#948e74157df1a32fd1b12c3a3c3cdcb6ec9d96cd"
foreach@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
@ -141,6 +203,16 @@ is-symbol@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572"
isstream@0.1.x:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
kuler@0.0.x:
version "0.0.0"
resolved "https://registry.yarnpkg.com/kuler/-/kuler-0.0.0.tgz#b66bb46b934e550f59d818848e0abba4f7f5553c"
dependencies:
colornames "0.0.2"
leakage@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.3.0.tgz#15d698abdc76bbc6439601f4f3020e77e2d50c39"
@ -155,6 +227,13 @@ left-pad@^1.1.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee"
logform@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/logform/-/logform-1.2.2.tgz#7be8847684de07185029ed09c65b11d06191ef93"
dependencies:
colors "^1.1.2"
fecha "^2.3.2"
memwatch-next@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/memwatch-next/-/memwatch-next-0.3.0.tgz#2111050f9a906e0aa2d72a4ec0f0089c78726f8f"
@ -181,6 +260,10 @@ object.getownpropertydescriptors@^2.0.3:
define-properties "^1.1.2"
es-abstract "^1.5.1"
one-time@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/one-time/-/one-time-0.0.4.tgz#f8cdf77884826fe4dff93e3a9cc37b1e4480742e"
pathval@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
@ -211,6 +294,12 @@ smartlog-interfaces@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/smartlog-interfaces/-/smartlog-interfaces-1.0.8.tgz#633d889d498c4c13cd525d24adeb6cad6fe1aee1"
smartlog@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/smartlog/-/smartlog-1.0.3.tgz#ad30cd6189bf0558b4e31d87599fb019a2249352"
dependencies:
winston "^3.0.0-rc1"
smartq@^1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.6.tgz#0c1ff4336d95e95b4f1fdd8ccd7e2c5a323b8412"
@ -218,6 +307,10 @@ smartq@^1.1.1:
typings-global "^1.0.19"
util.promisify "^1.0.0"
stack-trace@0.0.x:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
tapbundle@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-2.0.0.tgz#79fce68ff185c786fabaf6eb589a4afc7d2714b7"
@ -228,6 +321,14 @@ tapbundle@^2.0.0:
smartdelay "^1.0.3"
smartq "^1.1.1"
text-hex@0.0.x:
version "0.0.0"
resolved "https://registry.yarnpkg.com/text-hex/-/text-hex-0.0.0.tgz#578fbc85a6a92636e42dd17b41d0218cce9eb2b3"
triple-beam@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.1.0.tgz#2ac387c8c4bd04bd26c61df891a6079f8592fe10"
type-detect@^4.0.0:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
@ -242,3 +343,20 @@ util.promisify@^1.0.0:
dependencies:
define-properties "^1.1.2"
object.getownpropertydescriptors "^2.0.3"
winston-transport@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-3.0.1.tgz#8008b15eef5660c4fb3fa094d58ccbd08528c58d"
winston@^3.0.0-rc1:
version "3.0.0-rc1"
resolved "https://registry.yarnpkg.com/winston/-/winston-3.0.0-rc1.tgz#982bc0ad4ef5c53000ca68036d78a3deaa28cac5"
dependencies:
async "^1.0.0"
diagnostics "^1.0.1"
isstream "0.1.x"
logform "^1.2.1"
one-time "0.0.4"
stack-trace "0.0.x"
triple-beam "^1.0.1"
winston-transport "^3.0.1"