Skip to content

Commit

Permalink
Fix / Access bridge tests (#623)
Browse files Browse the repository at this point in the history
* chore: override console in logger test
  • Loading branch information
kiremitrov123 authored Sep 26, 2024
1 parent 3dea0fc commit 0e5af77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const config: KnipConfig = {
'i18next-parser',
'luxon', // Used in tests
'playwright', // Used in test configs
'sharp', // Requirement for @vite-pwa/assets-generator
'tsconfig-paths', // Used for e2e test setup
'virtual:pwa-register', // Service Worker code is injected at build time
'virtual:polyfills', // Polyfills are conditionally injected
Expand Down
17 changes: 17 additions & 0 deletions platforms/access-bridge/test/unit/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@ import * as Sentry from '@sentry/node';
import logger from '../../src/pipeline/logger.js';

describe('Logger Tests', () => {
// Preserve the original console methods
const originalConsole = { ...console };

beforeEach(() => {
// Reset all mocks to ensure a clean slate for each test
vi.resetAllMocks();

// Mock console methods to suppress log outputs during tests
// Suppressing info output to avoid clutter
global.console = {
log: () => {},
error: () => {},
warn: () => {},
info: () => {},
} as unknown as Console;
});

afterEach(() => {
// Restore the original console methods after each test
global.console = originalConsole;
});

describe('when Sentry is configured', () => {
Expand Down
2 changes: 1 addition & 1 deletion platforms/access-bridge/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default ({ mode, command }: ConfigEnv): UserConfigExport => {
},
test: {
globals: true,
include: ['**/*.test.ts'],
environment: 'node',
setupFiles: 'test/vitest.setup.ts',
chaiConfig: {
truncateThreshold: 1000,
Expand Down

0 comments on commit 0e5af77

Please sign in to comment.