import { afterEach } from 'vitest'; // It's awkward to read `npm test` output if it is littered with console logs. // This makes a test fail if it writes anything to the console. (Feel free to // set $ALLOW_CONSOLE if you are logging while developing and want to see if // your tests pass.) // // Typically you can turn off the info/debug in tests by passing a loglevel // logger with level WARN to the logger option to `new ApolloServer`. if (!process.env.ALLOW_CONSOLE) { let usedConsole = false; for (const key of ['log', 'error', 'warn', 'info', 'debug'] as const) { const originalFn = console[key]; console[key] = (...args: unknown[]) => { usedConsole = true; originalFn(...args); }; } afterEach(() => { if (usedConsole) { usedConsole = false; throw Error( 'To keep unit test output readable, tests should not write to the console. To test logging behavior, pass a logger to the class under test.', ); } }); }