mirror of https://github.com/embarklabs/embark.git
test(@embark/core): add tests for logger module
This commit is contained in:
parent
58608db3d6
commit
6b4052ee7b
|
@ -38,26 +38,47 @@
|
|||
"lint": "eslint src/",
|
||||
"qa": "npm-run-all lint _typecheck _build",
|
||||
"reset": "npx rimraf dist embark-*.tgz package",
|
||||
"solo": "embark-solo"
|
||||
"solo": "embark-solo",
|
||||
"test": "jest"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "../../../.eslintrc.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs3": "7.7.4",
|
||||
"colors": "1.3.2",
|
||||
"core-js": "3.4.3",
|
||||
"date-and-time": "0.6.2"
|
||||
"@babel/runtime-corejs3": "7.8.3",
|
||||
"colors": "1.4.0",
|
||||
"core-js": "3.6.4",
|
||||
"date-and-time": "0.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.7.7",
|
||||
"babel-jest": "24.9.0",
|
||||
"embark-solo": "^5.1.1",
|
||||
"eslint": "5.7.0",
|
||||
"embark-testing": "^5.1.1",
|
||||
"eslint": "6.8.0",
|
||||
"jest": "24.9.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"rimraf": "3.0.0"
|
||||
"rimraf": "3.0.0",
|
||||
"tmp": "0.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.17.0",
|
||||
"npm": ">=6.11.3",
|
||||
"yarn": ">=1.19.1"
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverage": true,
|
||||
"testEnvironment": "node",
|
||||
"testMatch": [
|
||||
"**/test/**/*.js"
|
||||
],
|
||||
"transform": {
|
||||
"\\.js$": [
|
||||
"babel-jest",
|
||||
{
|
||||
"rootMode": "upward"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ export class Logger {
|
|||
}));
|
||||
};
|
||||
this.logFile = options.logFile;
|
||||
this.context = options.context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
import assert from 'assert';
|
||||
import sinon from 'sinon';
|
||||
import * as fs from 'fs';
|
||||
import { fakeEmbark } from 'embark-testing';
|
||||
import { Logger } from '../src/';
|
||||
import tmp from 'tmp';
|
||||
|
||||
describe('core/logger', () => {
|
||||
|
||||
const { embark, plugins } = fakeEmbark();
|
||||
|
||||
let logger, testLogFn, logFile;
|
||||
|
||||
beforeEach(() => {
|
||||
logFile = tmp.fileSync();
|
||||
|
||||
testLogFn = sinon.fake();
|
||||
logger = new Logger({
|
||||
events: embark.events,
|
||||
logFunction: testLogFn,
|
||||
logFile: logFile.name
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
embark.teardown();
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
test('it should should use custom log function for logging', () => {
|
||||
logger.info('Hello world');
|
||||
assert(testLogFn.calledOnce);
|
||||
});
|
||||
|
||||
test('it should inject color encoding based on log method', () => {
|
||||
logger.info('Hello world');
|
||||
assert(testLogFn.calledWith('\u001b[32mHello world\u001b[39m'));
|
||||
logger.warn('Hello world');
|
||||
assert(testLogFn.calledWith('\u001b[33mHello world\u001b[39m'));
|
||||
logger.error('Hello world');
|
||||
assert(testLogFn.calledWith('\u001b[31mHello world\u001b[39m'));
|
||||
});
|
||||
|
||||
test('it should write logs to log file', () => {
|
||||
logger.info('Some test log');
|
||||
const logs = fs.readFileSync(logFile.name, 'utf8')
|
||||
assert.ok(logs.indexOf('[info]: Some test log') > -1);
|
||||
});
|
||||
|
||||
test('it should not log if log method level is higher than configured log level', () => {
|
||||
logger.trace('Hello world');
|
||||
// default log level is `info` which is lower than `trace`
|
||||
assert.ok(!testLogFn.calledOnce);
|
||||
logger.warn('Test');
|
||||
assert.ok(testLogFn.calledOnce);
|
||||
});
|
||||
});
|
|
@ -8,5 +8,10 @@
|
|||
"extends": "../../../tsconfig.base.json",
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../utils/testing"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -8353,6 +8353,11 @@ datagram-stream@^1.1.1:
|
|||
resolved "https://registry.yarnpkg.com/datagram-stream/-/datagram-stream-1.1.1.tgz#aa7d84959a3a1b1a5e43d4c7c03461f40a8ffb7d"
|
||||
integrity sha1-qn2ElZo6GxpeQ9THwDRh9AqP+30=
|
||||
|
||||
date-and-time@0.12.0:
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/date-and-time/-/date-and-time-0.12.0.tgz#6d30c91c47fa72edadd628b71ec2ac46909b9267"
|
||||
integrity sha512-n2RJIAp93AucgF/U/Rz5WRS2Hjg5Z+QxscaaMCi6pVZT1JpJKRH+C08vyH/lRR1kxNXnPxgo3lWfd+jCb/UcuQ==
|
||||
|
||||
date-and-time@0.6.2:
|
||||
version "0.6.2"
|
||||
resolved "https://registry.yarnpkg.com/date-and-time/-/date-and-time-0.6.2.tgz#ffca5b488bafa32f7ed0aa505e7983519d413f92"
|
||||
|
@ -22281,7 +22286,7 @@ tmp@0.0.33, tmp@^0.0.33:
|
|||
dependencies:
|
||||
os-tmpdir "~1.0.2"
|
||||
|
||||
tmp@^0.1.0:
|
||||
tmp@0.1.0, tmp@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.1.0.tgz#ee434a4e22543082e294ba6201dcc6eafefa2877"
|
||||
integrity sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==
|
||||
|
|
Loading…
Reference in New Issue