feat: migrate from npm to Bun
- Install Bun via mise - Update package.json scripts to use Bun - Migrate unit tests from Vitest to Bun test runner - Migrate component tests from Vitest to Bun test runner - Configure Bun with DOM environment for React Testing Library - Keep Playwright for E2E tests (as planned) - 93/100 tests passing (7 flaky tests when running all together, pass individually)
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import { describe, it, expect, vi, beforeEach, MockedFunction } from 'vitest'
|
||||
import { describe, it, expect, mock, beforeEach, MockedFunction } from 'bun:test'
|
||||
import { getSession } from '@/lib/auth-simple'
|
||||
|
||||
// Mock next/headers
|
||||
vi.mock('next/headers', () => ({
|
||||
cookies: vi.fn().mockResolvedValue({
|
||||
get: vi.fn().mockReturnValue({ name: 'better-auth.session_token', value: 'test-token' }),
|
||||
cookies: mock(() => {}).mockResolvedValue({
|
||||
get: mock(() => {}).mockReturnValue({ name: 'better-auth.session_token', value: 'test-token' }),
|
||||
}),
|
||||
headers: vi.fn().mockResolvedValue({
|
||||
get: vi.fn().mockReturnValue(null),
|
||||
headers: mock(() => {}).mockResolvedValue({
|
||||
get: mock(() => {}).mockReturnValue(null),
|
||||
}),
|
||||
}))
|
||||
|
||||
// Mock fetch
|
||||
const mockFetch = vi.fn()
|
||||
const mockFetch = mock(() => {})
|
||||
global.fetch = mockFetch as MockedFunction<typeof global.fetch>
|
||||
|
||||
describe('getSession', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mock.clearAllMocks()
|
||||
})
|
||||
|
||||
it('returns session data when auth API returns 200', async () => {
|
||||
@@ -26,7 +26,7 @@ describe('getSession', () => {
|
||||
user: { id: 'user-123', email: 'test@example.com' },
|
||||
}
|
||||
|
||||
mockFetch.mockResolvedValue(
|
||||
mockFetch.mockImplementation(async () =>
|
||||
new Response(JSON.stringify(mockSession), { status: 200 })
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('getSession', () => {
|
||||
})
|
||||
|
||||
it('returns null when auth API returns non-200 status', async () => {
|
||||
mockFetch.mockResolvedValue(
|
||||
mockFetch.mockImplementation(async () =>
|
||||
new Response(null, { status: 401 })
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user