fix(tests): add missing Sentry mock event fields across 14 spec files; fix test:coverage semicolon
`@sentry/sveltekit` wraps load functions and reads `event.request.method` and `event.url.pathname`. Mock events that omitted `request` or `url` threw `TypeError: Cannot read properties of undefined` on every invocation, silently masking 86 test failures on main. Two root causes fixed: - Added `request: new Request(...)` (and `url: new URL(...)` where absent) to all mock event objects in 14 `*.server.spec.ts` files - Changed `;` to `&&` in the `test:coverage` npm script so a failing server run propagates its exit code instead of being swallowed by the client run All 576 server-project tests now pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,7 +32,13 @@ describe('person detail load — happy path', () => {
|
||||
.mockResolvedValueOnce({ response: { ok: true }, data: [] })
|
||||
} as ReturnType<typeof createApiClient>);
|
||||
|
||||
const result = await load({ params: { id: 'p1' }, fetch: mockFetch, locals: mockLocals });
|
||||
const result = await load({
|
||||
params: { id: 'p1' },
|
||||
fetch: mockFetch,
|
||||
request: new Request('http://localhost/persons/p1'),
|
||||
url: new URL('http://localhost/persons/p1'),
|
||||
locals: mockLocals
|
||||
});
|
||||
|
||||
expect(result.person.firstName).toBe('Hans');
|
||||
expect(result.sentDocuments).toHaveLength(1);
|
||||
@@ -55,7 +61,13 @@ describe('person detail load — happy path', () => {
|
||||
.mockResolvedValueOnce({ response: { ok: true }, data: [] })
|
||||
} as ReturnType<typeof createApiClient>);
|
||||
|
||||
const result = await load({ params: { id: 'p1' }, fetch: mockFetch, locals: mockLocalsWriter });
|
||||
const result = await load({
|
||||
params: { id: 'p1' },
|
||||
fetch: mockFetch,
|
||||
request: new Request('http://localhost/persons/p1'),
|
||||
url: new URL('http://localhost/persons/p1'),
|
||||
locals: mockLocalsWriter
|
||||
});
|
||||
|
||||
expect(result.canWrite).toBe(true);
|
||||
});
|
||||
@@ -76,7 +88,13 @@ describe('person detail load — happy path', () => {
|
||||
.mockResolvedValueOnce({ response: { ok: true }, data: [] })
|
||||
} as ReturnType<typeof createApiClient>);
|
||||
|
||||
const result = await load({ params: { id: 'p1' }, fetch: mockFetch, locals: mockLocals });
|
||||
const result = await load({
|
||||
params: { id: 'p1' },
|
||||
fetch: mockFetch,
|
||||
request: new Request('http://localhost/persons/p1'),
|
||||
url: new URL('http://localhost/persons/p1'),
|
||||
locals: mockLocals
|
||||
});
|
||||
|
||||
expect(result.sentDocuments).toEqual([]);
|
||||
expect(result.receivedDocuments).toEqual([]);
|
||||
@@ -100,7 +118,13 @@ describe('person detail load — error paths', () => {
|
||||
} as ReturnType<typeof createApiClient>);
|
||||
|
||||
await expect(
|
||||
load({ params: { id: 'missing' }, fetch: mockFetch, locals: mockLocals })
|
||||
load({
|
||||
params: { id: 'missing' },
|
||||
fetch: mockFetch,
|
||||
request: new Request('http://localhost/persons/p1'),
|
||||
url: new URL('http://localhost/persons/p1'),
|
||||
locals: mockLocals
|
||||
})
|
||||
).rejects.toMatchObject({
|
||||
status: 404
|
||||
});
|
||||
@@ -120,7 +144,13 @@ describe('person detail load — error paths', () => {
|
||||
} as ReturnType<typeof createApiClient>);
|
||||
|
||||
await expect(
|
||||
load({ params: { id: 'forbidden' }, fetch: mockFetch, locals: mockLocals })
|
||||
load({
|
||||
params: { id: 'forbidden' },
|
||||
fetch: mockFetch,
|
||||
request: new Request('http://localhost/persons/p1'),
|
||||
url: new URL('http://localhost/persons/p1'),
|
||||
locals: mockLocals
|
||||
})
|
||||
).rejects.toMatchObject({
|
||||
status: 403
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user