Skip to content

[WIP] Add Tests #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bufflog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {BuffLog}from './bufflog';

it('Testing jest', () => {
expect(1).toBe(1)
});


it('Test Bufflog', () => {
var logger = new BuffLog();
logger.info("test");
});
25 changes: 17 additions & 8 deletions bufflog.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,12 @@ import formats from "dd-trace/ext/formats";
export class BuffLog {
pinoLogger: any;
defaultLevel = 'notice';
dest: any;

constructor() {
this.dest = require('pino').destination('/tmp/test.log')
this.dest[Symbol.for('pino.metadata')] = true

this.pinoLogger = require('pino')({
level: this.defaultLevel,

@@ -16,6 +20,10 @@ export class BuffLog {
// soon: remove the `v` field https://github.com/pinojs/pino/issues/620
base: {},

// notice doesn't exist in pino, let's add it
customLevels: {
notice: 35
},
mixin () {
// Check here if a current trace exist to inject it in the log
// `tracer` is a singleton, will no-op if no tracer was initialized
@@ -27,14 +35,9 @@ export class BuffLog {
} else {
return {}
}
},

// notice doesn't exist in pino, let's add it
customLevels: {
notice: 35
}
});
}
}
}, this.dest)
};

debug(message: string) {
this.pinoLogger.debug(message);
@@ -46,6 +49,11 @@ export class BuffLog {

notice(message: string) {
this.pinoLogger.notice(message);
const { lastMsg, lastLevel, lastObj, lastTime} = this.dest
console.log(
'Logged message "%s" at level %d with object %o at time %s',
lastMsg, lastLevel, lastObj, lastTime
);
}

warning(message: string) {
@@ -60,5 +68,6 @@ export class BuffLog {
critical(message: string) {
this.pinoLogger.fatal(message);
}


}
9 changes: 4 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -7,11 +7,10 @@ tracer.init({
logInjection: false
});

let logger = new BuffLog();
var logger = new BuffLog();

logger.info('hello info');
logger.debug('hello debug');
logger.notice('hello notice');
logger.debug('hello info');
logger.notice('hello notice');
logger.warning('hello warning');
logger.error('hello error');
logger.critical('hello critical');
@@ -31,4 +30,4 @@ app.get('/', (req, res) => {
logger.warning('hello warning');
logger.error('hello error');
logger.critical('hello critical');
});
});
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
preset: 'ts-jest',
testEnvironment: "node",
};
5,345 changes: 4,995 additions & 350 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "./node_modules/typescript/bin/tsc && node ./out/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"repository": {
"type": "git",
@@ -18,8 +18,12 @@
},
"homepage": "https://github.com/bufferapp/js-bufflog#readme",
"devDependencies": {
"@types/jest": "^25.1.3",
"@types/express": "^4.17.2",
"express": "^4.17.1",
"jest": "^25.1.0",
"supertest": "^4.0.2",
"ts-jest": "^25.2.1",
"typescript": "^3.8.2"
},
"dependencies": {
Empty file added tracer.ts
Empty file.