logger.ts 551 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { onTestFailed } from 'vitest'
  3. const logs: unknown[][] = []
  4. afterEach(() => {
  5. logs.length = 0
  6. })
  7. const logger = {
  8. log(...mesages: unknown[]) {
  9. if (process.env.VITEST_LOG_GQL_FACTORY) {
  10. console.log(...mesages)
  11. } else {
  12. logs.push(mesages)
  13. }
  14. },
  15. printMockerLog() {
  16. logs.forEach((log) => {
  17. console.log(...log)
  18. })
  19. },
  20. }
  21. beforeEach(() => {
  22. onTestFailed(() => {
  23. logger.printMockerLog()
  24. })
  25. })
  26. export default logger