Skip to content
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

test: silence unnecessary logging for tests #916

Merged
merged 5 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"start:log-rpc": "yarn run build && NODE_ENV=test yarn run main ",
"dev": "tsc-watch --onSuccess \"yarn run main\"",
"test": "NODE_ENV=test substrate-exec-jest --detectOpenHandles",
"test:watch": "substrate-exec-jest --watch",
"test:watch": "NODE_ENV=test substrate-exec-jest --watch",
"test:cov": "NODE_ENV=test substrate-exec-jest --detectOpenHandles --coverage",
"lint:e2e-tests": "cd e2e-tests && substrate-dev-run-lint",
"build:e2e-tests": "(cd e2e-tests && substrate-exec-tsc)",
Expand Down
2 changes: 1 addition & 1 deletion src/logging/transports/consoleTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ export function consoleTransport(): transports.ConsoleTransportInstance {
handleExceptions: true,
format: format.combine(...transformers),
// Silence using `jest --silent`
silent: process.argv.indexOf('--silent') >= 0,
silent: process.env.NODE_ENV === 'test',
});
}
5 changes: 5 additions & 0 deletions src/middleware/error/errorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const errorMiddlewareCatchesErrWithStatus =
catchesErrWithStatus(errorMiddleware);

describe('errorMiddleware', () => {
// Necessary since the consolveOverride is called after the getter for the logger is launced
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => ({}));
});

errorMiddlewareCallsNextWithErr('ILegacyError', {
error: 'legacy error',
statusCode: 500,
Expand Down
5 changes: 5 additions & 0 deletions src/middleware/error/httpErrorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const httpErrorMiddlewareCatchesErrWithStatus =
catchesErrWithStatus(httpErrorMiddleware);

describe('httpErrorMiddleware', () => {
// Necessary since the consolveOverride is called after the getter for the logger is launced
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => ({}));
});

httpErrorMiddlewareCallsNextWithErr('Error', new Error('This is an error'));

httpErrorMiddlewareCallsNextWithErr('IBasicError', {
Expand Down
5 changes: 5 additions & 0 deletions src/middleware/error/internalErrorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const internalErrorMiddlewareCatchesErrWithResponse = catchesErrWithResponse(
);

describe('internalErrorMiddleware', () => {
// Necessary since the consolveOverride is called after the getter for the logger is launced
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => ({}));
});

internalErrorMiddlewareCatchesErrWithResponse(
'ITxLegacyError',
{
Expand Down
5 changes: 5 additions & 0 deletions src/middleware/error/legacyErrorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const legacyErrorMiddlewareCatchesErrWithResponse = catchesErrWithResponse(
);

describe('legacyErrorMiddleware', () => {
// Necessary since the consolveOverride is called after the getter for the logger is launced
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => ({}));
});

legacyErrorMiddlewareCallsNextWithErr('Error', new Error('This is an error'));

legacyErrorMiddlewareCallsNextWithErr(
Expand Down
5 changes: 5 additions & 0 deletions src/middleware/error/txErrorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const txErrorMiddlewareCatchesErrWithResponse =
catchesErrWithResponse(txErrorMiddleware);

describe('txErrorMiddleware', () => {
// Necessary since the consolveOverride is called after the getter for the logger is launced
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => ({}));
});

txErrorMiddlewareCallsNextWithErr('Error', new Error('This is an error'));

txErrorMiddlewareCallsNextWithErr(
Expand Down