|
| 1 | +// @ts-check |
| 2 | +import * as Sentry from '@sentry/effect'; |
| 3 | +import { Cause, Effect, Layer, Logger, LogLevel, Runtime } from 'effect'; |
| 4 | + |
| 5 | +const LogLevelLive = Logger.minimumLogLevel(LogLevel.Debug); |
| 6 | +const AppLayer = Layer.mergeAll( |
| 7 | + Sentry.effectLayer({ |
| 8 | + dsn: process.env.E2E_TEST_DSN, |
| 9 | + integrations: [ |
| 10 | + Sentry.browserTracingIntegration({ |
| 11 | + _experiments: { enableInteractions: true }, |
| 12 | + }), |
| 13 | + ], |
| 14 | + tracesSampleRate: 1.0, |
| 15 | + release: 'e2e-test', |
| 16 | + environment: 'qa', |
| 17 | + tunnel: 'http://localhost:3031', |
| 18 | + enableLogs: true, |
| 19 | + enableEffectLogs: true, |
| 20 | + }), |
| 21 | + LogLevelLive, |
| 22 | +); |
| 23 | + |
| 24 | +const runtime = Layer.toRuntime(AppLayer).pipe(Effect.scoped, Effect.runSync); |
| 25 | + |
| 26 | +const runEffect = fn => Runtime.runPromise(runtime)(fn()); |
| 27 | + |
| 28 | +document.getElementById('exception-button')?.addEventListener('click', () => { |
| 29 | + throw new Error('I am an error!'); |
| 30 | +}); |
| 31 | + |
| 32 | +document.getElementById('effect-span-button')?.addEventListener('click', async () => { |
| 33 | + await runEffect(() => |
| 34 | + Effect.gen(function* () { |
| 35 | + yield* Effect.sleep('50 millis'); |
| 36 | + yield* Effect.sleep('25 millis').pipe(Effect.withSpan('nested-span')); |
| 37 | + }).pipe(Effect.withSpan('custom-effect-span', { kind: 'internal' })), |
| 38 | + ); |
| 39 | + const el = document.getElementById('effect-span-result'); |
| 40 | + if (el) el.textContent = 'Span sent!'; |
| 41 | +}); |
| 42 | + |
| 43 | +document.getElementById('effect-fail-button')?.addEventListener('click', async () => { |
| 44 | + try { |
| 45 | + await runEffect(() => Effect.fail(new Error('Effect failure'))); |
| 46 | + } catch { |
| 47 | + const el = document.getElementById('effect-fail-result'); |
| 48 | + if (el) el.textContent = 'Effect failed (expected)'; |
| 49 | + } |
| 50 | +}); |
| 51 | + |
| 52 | +document.getElementById('effect-die-button')?.addEventListener('click', async () => { |
| 53 | + try { |
| 54 | + await runEffect(() => Effect.die('Effect defect')); |
| 55 | + } catch { |
| 56 | + const el = document.getElementById('effect-die-result'); |
| 57 | + if (el) el.textContent = 'Effect died (expected)'; |
| 58 | + } |
| 59 | +}); |
| 60 | + |
| 61 | +document.getElementById('log-button')?.addEventListener('click', async () => { |
| 62 | + await runEffect(() => |
| 63 | + Effect.gen(function* () { |
| 64 | + yield* Effect.logDebug('Debug log from Effect'); |
| 65 | + yield* Effect.logInfo('Info log from Effect'); |
| 66 | + yield* Effect.logWarning('Warning log from Effect'); |
| 67 | + yield* Effect.logError('Error log from Effect'); |
| 68 | + }), |
| 69 | + ); |
| 70 | + const el = document.getElementById('log-result'); |
| 71 | + if (el) el.textContent = 'Logs sent!'; |
| 72 | +}); |
| 73 | + |
| 74 | +document.getElementById('log-context-button')?.addEventListener('click', async () => { |
| 75 | + await runEffect(() => |
| 76 | + Effect.logInfo('Log with context').pipe( |
| 77 | + Effect.annotateLogs('userId', '12345'), |
| 78 | + Effect.annotateLogs('action', 'test'), |
| 79 | + ), |
| 80 | + ); |
| 81 | + const el = document.getElementById('log-context-result'); |
| 82 | + if (el) el.textContent = 'Log with context sent!'; |
| 83 | +}); |
| 84 | + |
| 85 | +document.getElementById('navigation-link')?.addEventListener('click', () => { |
| 86 | + document.getElementById('navigation-target')?.scrollIntoView({ behavior: 'smooth' }); |
| 87 | +}); |
0 commit comments