Add log class and add some functins
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Add jest for test units Updated the package and lib
This commit is contained in:
parent
df0b744058
commit
9e9cbe1162
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest Current File",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["${relativeFile}"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
6
jest.config.js
Normal file
6
jest.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
transform: { '^.+\\.ts?$': 'ts-jest' },
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
|
||||||
|
};
|
51
package.json
51
package.json
@ -1,25 +1,30 @@
|
|||||||
{
|
{
|
||||||
"name": "cubetiq-ts-utils",
|
"name": "cubetiq-ts-utils",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "CUBETIQ TypeScript Utils",
|
"description": "CUBETIQ TypeScript Utils",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"repository": "https://github.com/CUBETIQ/cubetiq-ts-utils.git",
|
"repository": "https://github.com/CUBETIQ/cubetiq-ts-utils.git",
|
||||||
"author": "Sambo Chea",
|
"author": "Sambo Chea",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": false,
|
"private": false,
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^4.17.0",
|
"@types/jest": "^26.0.20",
|
||||||
"@typescript-eslint/parser": "^4.17.0",
|
"@typescript-eslint/eslint-plugin": "^4.17.0",
|
||||||
"eslint": "^7.21.0",
|
"@typescript-eslint/parser": "^4.17.0",
|
||||||
"eslint-config-prettier": "^8.1.0",
|
"eslint": "^7.21.0",
|
||||||
"eslint-plugin-prettier": "^3.3.1",
|
"eslint-config-prettier": "^8.1.0",
|
||||||
"prettier": "^2.2.1",
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
"typescript": "^4.2.3"
|
"jest": "^26.6.3",
|
||||||
},
|
"prettier": "^2.2.1",
|
||||||
"scripts": {
|
"ts-jest": "^26.5.3",
|
||||||
"build": "tsc -p tsconfig.json",
|
"typescript": "^4.2.3"
|
||||||
"lint": "eslint . --ext .ts",
|
},
|
||||||
"prettier": "prettier --config .prettierrc 'src/**/*.ts' --write"
|
"scripts": {
|
||||||
}
|
"build": "tsc -p tsconfig.json",
|
||||||
|
"lint": "eslint . --ext .ts",
|
||||||
|
"prettier": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
||||||
|
"test": "jest",
|
||||||
|
"coverage": "jest --coverage"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
31
src/log/Log.ts
Normal file
31
src/log/Log.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { Loggable } from "./interfaces";
|
||||||
|
|
||||||
|
class Log {
|
||||||
|
static log(loggable: Loggable): void {
|
||||||
|
switch (loggable.type) {
|
||||||
|
case 'error':
|
||||||
|
this.error(loggable.from, loggable.data)
|
||||||
|
break;
|
||||||
|
case 'warn':
|
||||||
|
this.warn(loggable.from, loggable.data)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.info(loggable.from, loggable.data)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static info(...data: any[]): void {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static error(...data: any[]): void {
|
||||||
|
console.error(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
static warn(...data: any[]): void {
|
||||||
|
console.warn(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Log;
|
7
src/log/interfaces.ts
Normal file
7
src/log/interfaces.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
type LogType = 'info' | 'error' | 'warn'
|
||||||
|
|
||||||
|
export interface Loggable {
|
||||||
|
type: LogType;
|
||||||
|
from?: string;
|
||||||
|
data?: any;
|
||||||
|
}
|
23
tests/log.test.ts
Normal file
23
tests/log.test.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import Log from '../src/log/Log';
|
||||||
|
|
||||||
|
describe('loggin into console', function () {
|
||||||
|
it('info', function () {
|
||||||
|
Log.info('I am an info!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('warn', function () {
|
||||||
|
Log.info('I am a warn!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('error', function () {
|
||||||
|
Log.info('I am an error!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('loggable', function () {
|
||||||
|
Log.log({
|
||||||
|
type: 'info',
|
||||||
|
from: 'log.test.ts',
|
||||||
|
data: 'I am loggable called'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -11,11 +11,11 @@
|
|||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"rootDir": "src"
|
"rootDir": "src",
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"]
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user