vitest.setup.ts 874 B

123456789101112131415161718192021222324252627282930313233
  1. import nock from "nock"
  2. import "./utils/path" // Import to enable String.prototype.toPosix().
  3. // Disable network requests by default for all tests.
  4. nock.disableNetConnect()
  5. export function allowNetConnect(host?: string | RegExp) {
  6. if (host) {
  7. nock.enableNetConnect(host)
  8. } else {
  9. nock.enableNetConnect()
  10. }
  11. }
  12. // Global mocks that many tests expect.
  13. global.structuredClone = global.structuredClone || ((obj: any) => JSON.parse(JSON.stringify(obj)))
  14. // Suppress console.log during tests to reduce noise.
  15. // Keep console.error for actual errors.
  16. const originalConsoleLog = console.log
  17. const originalConsoleWarn = console.warn
  18. const originalConsoleInfo = console.info
  19. console.log = () => {}
  20. console.warn = () => {}
  21. console.info = () => {}
  22. afterAll(() => {
  23. console.log = originalConsoleLog
  24. console.warn = originalConsoleWarn
  25. console.info = originalConsoleInfo
  26. })