Skip to content

Commit 848ac3c

Browse files
Fix TypeScript errors in test files caught by tsc during Docker build
Add tsc --noEmit typecheck step to pre-commit hook so type errors in test files are caught locally before CI, matching what the Dockerfile build does.
1 parent bc8ca59 commit 848ac3c

8 files changed

Lines changed: 14 additions & 10 deletions

File tree

.githooks/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ cargo fmt --check
77
echo "→ cargo clippy -p proxy"
88
cargo clippy -p proxy -- -D warnings
99

10+
echo "→ admin-ui typecheck"
11+
(cd admin-ui && npm run typecheck)
12+
1013
echo "→ admin-ui tests"
1114
(cd admin-ui && npm run test:run)

admin-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "tsc -b && vite build",
99
"preview": "vite preview",
1010
"test": "vitest",
11-
"test:run": "vitest run"
11+
"test:run": "vitest run",
12+
"typecheck": "tsc --noEmit"
1213
},
1314
"dependencies": {
1415
"@microsoft/fetch-event-source": "^2.0.1",

admin-ui/src/api/catalog.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { client } from './client'
1818
import { fetchEventSource } from '@microsoft/fetch-event-source'
1919
import { submitAndStream, cancelDiscovery, getDiscoveryStatus, getCatalog } from './catalog'
2020

21-
const mockClient = client as {
21+
const mockClient = client as unknown as {
2222
post: ReturnType<typeof vi.fn>
2323
get: ReturnType<typeof vi.fn>
2424
delete: ReturnType<typeof vi.fn>

admin-ui/src/api/client.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('api/client – request interceptor', () => {
1313
it('attaches Bearer token when localStorage has one', async () => {
1414
localStorage.setItem('token', 'my-jwt')
1515
// Re-import to run the module with the token already set
16-
const { client } = await import('./client')
16+
await import('./client')
1717
// Inspect the interceptor by checking what an outgoing request config looks like
1818
// via axios adapter mock
1919
const mockAdapter = vi.fn().mockResolvedValue({ data: {}, status: 200, headers: {}, config: {} })
@@ -24,7 +24,7 @@ describe('api/client – request interceptor', () => {
2424
testClient.interceptors.request.use((config) => {
2525
const token = localStorage.getItem('token')
2626
if (token) config.headers.Authorization = `Bearer ${token}`
27-
capturedConfig = config as Record<string, unknown>
27+
capturedConfig = config as unknown as Record<string, unknown>
2828
return config
2929
})
3030
testClient.defaults.adapter = mockAdapter
@@ -34,13 +34,13 @@ describe('api/client – request interceptor', () => {
3434

3535
it('omits Authorization header when no token', async () => {
3636
// No token in localStorage
37-
let capturedConfig: { headers: Record<string, unknown> } | null = null
37+
let capturedConfig: { headers: { Authorization?: string } } | null = null
3838
const testClient = axios.create({ baseURL: '/api/v1' })
3939
const mockAdapter = vi.fn().mockResolvedValue({ data: {}, status: 200, headers: {}, config: {} })
4040
testClient.interceptors.request.use((config) => {
4141
const token = localStorage.getItem('token')
4242
if (token) config.headers.Authorization = `Bearer ${token}`
43-
capturedConfig = config as { headers: Record<string, unknown> }
43+
capturedConfig = config as unknown as { headers: { Authorization?: string } }
4444
return config
4545
})
4646
testClient.defaults.adapter = mockAdapter

admin-ui/src/api/datasources.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
setDataSourceUsers,
2424
} from './datasources'
2525

26-
const mockClient = client as {
26+
const mockClient = client as unknown as {
2727
post: ReturnType<typeof vi.fn>
2828
get: ReturnType<typeof vi.fn>
2929
put: ReturnType<typeof vi.fn>

admin-ui/src/api/users.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ vi.mock('./client', () => ({
1414
import { client } from './client'
1515
import { login, getMe, listUsers, getUser, createUser, updateUser, changePassword, deleteUser } from './users'
1616

17-
const mockClient = client as {
17+
const mockClient = client as unknown as {
1818
post: ReturnType<typeof vi.fn>
1919
get: ReturnType<typeof vi.fn>
2020
put: ReturnType<typeof vi.fn>

admin-ui/src/auth/AuthContext.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest'
2-
import { render, renderHook, act } from '@testing-library/react'
2+
import { renderHook, act } from '@testing-library/react'
33
import { AuthProvider, useAuth } from './AuthContext'
44
import { makeUser } from '../test/factories'
55

admin-ui/src/components/UserForm.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, vi } from 'vitest'
2-
import { screen, fireEvent } from '@testing-library/react'
2+
import { screen } from '@testing-library/react'
33
import userEvent from '@testing-library/user-event'
44
import { renderWithProviders } from '../test/test-utils'
55
import { UserForm } from './UserForm'

0 commit comments

Comments
 (0)