Monitoring settings (Sentry, Umami) and the CSP origins come from the build environment
One build per environment: PROD_* variables for the production artifact, TEST_* for the test build and the CSP check. The build fails when a variable is empty. Tests use the production values from config/monitoringTestEnv.ts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import UmamiAnalytics from './UmamiAnalytics';
|
||||
|
||||
const umamiScripts = () =>
|
||||
@@ -8,6 +8,7 @@ const umamiScripts = () =>
|
||||
);
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
umamiScripts().forEach((script) => script.remove());
|
||||
});
|
||||
|
||||
@@ -18,18 +19,28 @@ describe('UmamiAnalytics', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
['andreaslop.nl', '3edbb7d1-4388-4f2d-9cef-11ade88ace96'],
|
||||
['test.andreaslop.nl', '7fb301ab-6ecc-4aea-beee-71bcb6009bfe'],
|
||||
])('telt op %s met de juiste website', (hostname, websiteId) => {
|
||||
render(<UmamiAnalytics hostname={hostname} />);
|
||||
['production', 'andreaslop.nl', '3edbb7d1-4388-4f2d-9cef-11ade88ace96'],
|
||||
['test', 'test.andreaslop.nl', 'test-website'],
|
||||
])(
|
||||
'telt in de %s-build op %s met de juiste website',
|
||||
(environment, hostname, websiteId) => {
|
||||
vi.stubEnv('VITE_APP_ENV', environment);
|
||||
vi.stubEnv('VITE_UMAMI_WEBSITE_ID', websiteId);
|
||||
render(<UmamiAnalytics hostname={hostname} />);
|
||||
|
||||
const [script] = umamiScripts();
|
||||
expect(script.defer).toBe(true);
|
||||
expect(script.dataset).toMatchObject({
|
||||
websiteId,
|
||||
domains: hostname,
|
||||
doNotTrack: 'true',
|
||||
});
|
||||
const [script] = umamiScripts();
|
||||
expect(script.defer).toBe(true);
|
||||
expect(script.dataset).toMatchObject({
|
||||
websiteId,
|
||||
domains: hostname,
|
||||
doNotTrack: 'true',
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it('voegt geen script toe op de host van de andere omgeving', () => {
|
||||
render(<UmamiAnalytics hostname="test.andreaslop.nl" />);
|
||||
expect(umamiScripts()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('voegt het script maar één keer toe', () => {
|
||||
|
||||
Reference in New Issue
Block a user