Skip to content

Commit 9a205aa

Browse files
authored
Suppress console output during environment variable loading (#18)
1 parent 31bb057 commit 9a205aa

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

.changeset/nine-ends-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@commercetools/mcp-essentials": patch
3+
---
4+
5+
Suppress dotenv logs to avoid pushing messages to the stdio.

modelcontextprotocol/jest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ const config: Config = {
44
preset: 'ts-jest',
55
testEnvironment: 'node',
66
roots: ['<rootDir>/src'],
7-
testMatch: ['**/test/**/*.ts?(x)'],
7+
testMatch: ['**/test/**/*.test.ts?(x)'],
88
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
9+
setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
910
};
1011

1112
export default config;

modelcontextprotocol/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ function handleError(error: any) {
271271
}
272272

273273
export async function main() {
274-
require('dotenv').config();
274+
require('dotenv').config({
275+
quiet: true,
276+
});
275277
const {options, env} = parseArgs(process.argv.slice(2));
276278

277279
// Create the CommercetoolsAgentEssentials instance
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const originalConsole = {
2+
log: console.log,
3+
error: console.error,
4+
warn: console.warn,
5+
info: console.info,
6+
debug: console.debug,
7+
};
8+
9+
beforeEach(() => {
10+
jest.spyOn(console, 'log').mockImplementation(() => {});
11+
jest.spyOn(console, 'error').mockImplementation(() => {});
12+
jest.spyOn(console, 'warn').mockImplementation(() => {});
13+
jest.spyOn(console, 'info').mockImplementation(() => {});
14+
jest.spyOn(console, 'debug').mockImplementation(() => {});
15+
});
16+
17+
afterEach(() => {
18+
jest.restoreAllMocks();
19+
});
20+
21+
export const enableConsoleOutput = () => {
22+
jest.restoreAllMocks();
23+
};
24+
25+
export const disableConsoleOutput = () => {
26+
jest.spyOn(console, 'log').mockImplementation(() => {});
27+
jest.spyOn(console, 'error').mockImplementation(() => {});
28+
jest.spyOn(console, 'warn').mockImplementation(() => {});
29+
jest.spyOn(console, 'info').mockImplementation(() => {});
30+
jest.spyOn(console, 'debug').mockImplementation(() => {});
31+
};
32+
33+
export {originalConsole};

0 commit comments

Comments
 (0)