mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 00:14:23 +00:00
fix: keep the errors endpoint out of the Bulwark Lite bundle
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('@/lib/lite', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/lib/lite')>()),
|
||||
IS_LITE: true,
|
||||
}));
|
||||
|
||||
import { captureException, configureErrorReporting, resetErrorReportingForTests } from '../client';
|
||||
|
||||
const DSN = 'https://6f0b9c79ed3a4315b76595bc2536ac40@bugsink.example.org/3';
|
||||
let fetchSpy: ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
resetErrorReportingForTests();
|
||||
sessionStorage.clear();
|
||||
fetchSpy = vi.fn().mockResolvedValue(new Response(null, { status: 200 }));
|
||||
vi.stubGlobal('fetch', fetchSpy);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
// Bulwark Lite has no server, so it never posts to /api/errors, whatever
|
||||
// the settings say; reports go to the DSN only.
|
||||
describe('error reporting in Lite', () => {
|
||||
it('sends to the DSN and never to /api/errors', () => {
|
||||
configureErrorReporting({ dsn: DSN, sampleRate: 1, environment: 'lite', collect: true });
|
||||
const error = new TypeError('boom');
|
||||
error.stack = 'TypeError: boom\n at a (https://lite.example.org/_next/static/chunks/1.js:2:30)';
|
||||
captureException(error);
|
||||
const urls = fetchSpy.mock.calls.map(([url]) => String(url));
|
||||
expect(urls).toHaveLength(1);
|
||||
expect(urls[0]).toContain('/api/3/envelope/');
|
||||
expect(urls.some((url) => url.includes('/api/errors'))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { apiFetch, getPathPrefix } from '@/lib/browser-navigation';
|
||||
import { IS_LITE } from '@/lib/lite';
|
||||
import { scrubRoutePath } from '@/lib/route-groups';
|
||||
import { debugIdsByPath } from './debug-ids';
|
||||
import {
|
||||
@@ -200,7 +201,9 @@ function deliver(report: ErrorReport): void {
|
||||
mode: 'cors',
|
||||
});
|
||||
}
|
||||
if (settings.collect) {
|
||||
// Lite has no server: the bundler drops this branch, and the endpoint
|
||||
// with it (scripts/lite/verify.mjs fails on undocumented /api strings).
|
||||
if (!IS_LITE && settings.collect) {
|
||||
send('/api/errors', JSON.stringify({
|
||||
name: report.name,
|
||||
message: report.message,
|
||||
|
||||
Reference in New Issue
Block a user