feat: migrate from npm to Bun
Test / unit-tests (push) Failing after 1m54s
Pull Request / unit-tests (pull_request) Failing after 1m41s
Pull Request / acceptance-tests (pull_request) Has been skipped
Pull Request / analyze-bump-type (pull_request) Has been skipped

- 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:
2026-04-01 00:11:49 -07:00
parent 1c9f70c3ed
commit 24db43eb7f
18 changed files with 1690 additions and 250 deletions
+23 -23
View File
@@ -3,23 +3,23 @@
* Tests the allowTies field is properly saved when updating tournaments
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { describe, it, expect, mock, beforeEach } from 'bun:test';
import { prisma } from '@/lib/prisma';
// Mock the prisma client
vi.mock('@/lib/prisma', () => ({
mock.module('@/lib/prisma', () => ({
prisma: {
event: {
findUnique: vi.fn(),
update: vi.fn(),
findUnique: mock(() => {}),
update: mock(() => {}),
},
},
}));
// Mock the permissions module
vi.mock('@/lib/permissions', () => ({
canManageTournament: vi.fn().mockResolvedValue({ allowed: true }),
canDeleteTournament: vi.fn().mockResolvedValue({ allowed: true }),
mock.module('@/lib/permissions', () => ({
canManageTournament: mock(() => {}).mockResolvedValue({ allowed: true }),
canDeleteTournament: mock(() => {}).mockResolvedValue({ allowed: true }),
}));
// Import the route handler after mocking
@@ -27,12 +27,12 @@ import { PUT } from '@/app/api/tournaments/[id]/route';
describe('Tournament Update API', () => {
beforeEach(() => {
vi.clearAllMocks();
mock.clearAllMocks();
});
it('should update allowTies field when provided', async () => {
// Mock existing tournament
vi.mocked(prisma.event.findUnique).mockResolvedValue({
prisma.event.findUnique.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: false,
@@ -46,10 +46,10 @@ describe('Tournament Update API', () => {
ownerId: null,
createdAt: new Date(),
updatedAt: new Date(),
} as any);
} as any));
// Mock successful update
vi.mocked(prisma.event.update).mockResolvedValue({
prisma.event.update.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: true,
@@ -63,7 +63,7 @@ describe('Tournament Update API', () => {
ownerId: null,
createdAt: new Date(),
updatedAt: new Date(),
} as any);
} as any));
const request = new Request('http://localhost/api/tournaments/1', {
method: 'PUT',
@@ -78,7 +78,7 @@ describe('Tournament Update API', () => {
const response = await PUT(request, { params });
expect(response.status).toBe(200);
expect(vi.mocked(prisma.event.update)).toHaveBeenCalledWith(
expect(prisma.event.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
allowTies: true,
@@ -89,7 +89,7 @@ describe('Tournament Update API', () => {
it('should default allowTies to false when not provided', async () => {
// Mock existing tournament
vi.mocked(prisma.event.findUnique).mockResolvedValue({
prisma.event.findUnique.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: true,
@@ -103,10 +103,10 @@ describe('Tournament Update API', () => {
ownerId: null,
createdAt: new Date(),
updatedAt: new Date(),
} as any);
} as any));
// Mock successful update
vi.mocked(prisma.event.update).mockResolvedValue({
prisma.event.update.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: false,
@@ -120,7 +120,7 @@ describe('Tournament Update API', () => {
ownerId: null,
createdAt: new Date(),
updatedAt: new Date(),
} as any);
} as any));
const request = new Request('http://localhost/api/tournaments/1', {
method: 'PUT',
@@ -135,7 +135,7 @@ describe('Tournament Update API', () => {
const response = await PUT(request, { params });
expect(response.status).toBe(200);
expect(vi.mocked(prisma.event.update)).toHaveBeenCalledWith(
expect(prisma.event.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
allowTies: false, // Should default to false
@@ -146,7 +146,7 @@ describe('Tournament Update API', () => {
it('should preserve allowTies value when updating other fields', async () => {
// Mock existing tournament with allowTies = true
vi.mocked(prisma.event.findUnique).mockResolvedValue({
prisma.event.findUnique.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: true,
@@ -160,10 +160,10 @@ describe('Tournament Update API', () => {
ownerId: null,
createdAt: new Date(),
updatedAt: new Date(),
} as any);
} as any));
// Mock successful update
vi.mocked(prisma.event.update).mockResolvedValue({
prisma.event.update.mockImplementation(async () => ({
id: 1,
name: 'Updated Tournament Name',
allowTies: true,
@@ -177,7 +177,7 @@ describe('Tournament Update API', () => {
ownerId: null,
createdAt: new Date(),
updatedAt: new Date(),
} as any);
} as any));
const request = new Request('http://localhost/api/tournaments/1', {
method: 'PUT',
@@ -192,7 +192,7 @@ describe('Tournament Update API', () => {
const response = await PUT(request, { params });
expect(response.status).toBe(200);
const updateCall = vi.mocked(prisma.event.update).mock.calls[0][0];
const updateCall = prisma.event.update.mock.calls[0][0];
expect(updateCall.data.allowTies).toBe(true);
expect(updateCall.data.name).toBe('Updated Tournament Name');
expect(updateCall.data.targetScore).toBe(10);