Skip to content

Commit 47eec43

Browse files
test: enhance test setup by mocking consola and suppressing console errors
1 parent 7d10ce7 commit 47eec43

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
runs-on: ${{ matrix.os }}
2727

2828
permissions:
29-
# Required to checkout the code
30-
contents: read
29+
# Required to checkout the code and push coverage badge updates
30+
contents: write
3131
# Required to put a comment into the pull-request
3232
pull-requests: write
3333

tests/setup.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
* Runs before all tests to configure the testing environment
44
*/
55

6-
import { beforeAll } from 'vitest'
6+
import { beforeEach, vi } from 'vitest'
77

8-
beforeAll(() => {
9-
// Setup global test environment
10-
// Note: nitro-graphql/* imports are aliased in vitest.config.ts
8+
// Mock consola globally to suppress expected error logs during tests
9+
vi.mock('consola', async (importOriginal) => {
10+
const actual = await importOriginal<typeof import('consola')>()
11+
const mockLogger = {
12+
...actual.default,
13+
error: vi.fn(),
14+
warn: vi.fn(),
15+
info: vi.fn(),
16+
success: vi.fn(),
17+
debug: vi.fn(),
18+
log: vi.fn(),
19+
withTag: vi.fn(() => mockLogger),
20+
}
21+
return {
22+
...actual,
23+
default: mockLogger,
24+
consola: mockLogger,
25+
}
26+
})
27+
28+
// Also suppress console.error for expected errors during tests
29+
beforeEach(() => {
30+
vi.spyOn(console, 'error').mockImplementation(() => {})
1131
})

0 commit comments

Comments
 (0)