|
| 1 | +// <reference lib="deno.ns" /> |
| 2 | + |
| 3 | +import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; |
| 4 | +import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; |
| 5 | +import type { DenoClient } from '../build/esm/index.js'; |
| 6 | +import { getCurrentScope, getGlobalScope, getIsolationScope, init } from '../build/esm/index.js'; |
| 7 | + |
| 8 | +function resetGlobals(): void { |
| 9 | + getCurrentScope().clear(); |
| 10 | + getCurrentScope().setClient(undefined); |
| 11 | + getIsolationScope().clear(); |
| 12 | + getGlobalScope().clear(); |
| 13 | +} |
| 14 | + |
| 15 | +Deno.test('denoMysqlIntegration: included in default integrations (Deno 2.8.0+)', () => { |
| 16 | + resetGlobals(); |
| 17 | + const client = init({ dsn: 'https://username@domain/123' }) as DenoClient; |
| 18 | + const names = client.getOptions().integrations.map(i => i.name); |
| 19 | + assert(names.includes('DenoMysql'), `DenoMysql should be in defaults, got ${names.join(', ')}`); |
| 20 | +}); |
| 21 | + |
| 22 | +// The orchestrion runtime hook (`@sentry/deno/import`) only works as a FIRST |
| 23 | +// import inside the entry graph in Deno 2.8.0 through 2.8.2. |
| 24 | +// TODO: revisit a `--import` or `--preload` approach once Deno 2.8.3 ships. |
| 25 | +Deno.test('@sentry/deno/import: transforms mysql so it publishes the orchestrion channel', async () => { |
| 26 | + const scenario = new URL('./orchestrion-mysql/scenario.mjs', import.meta.url); |
| 27 | + |
| 28 | + // packages/deno — where node_modules resolves |
| 29 | + const cwd = new URL('../', import.meta.url); |
| 30 | + |
| 31 | + const command = new Deno.Command('deno', { |
| 32 | + args: ['run', '--allow-all', scenario.pathname], |
| 33 | + cwd: cwd.pathname, |
| 34 | + stdout: 'piped', |
| 35 | + stderr: 'piped', |
| 36 | + }); |
| 37 | + |
| 38 | + const { code, stdout, stderr } = await command.output(); |
| 39 | + const out = new TextDecoder().decode(stdout); |
| 40 | + const err = new TextDecoder().decode(stderr); |
| 41 | + |
| 42 | + assertEquals(code, 0, `scenario exited ${code}\nstdout:\n${out}\nstderr:\n${err}`); |
| 43 | + |
| 44 | + const line = out.split('\n').find(l => l.startsWith('SCENARIO')) ?? ''; |
| 45 | + assert(line, `no SCENARIO line in output:\n${out}\nstderr:\n${err}`); |
| 46 | + // The injected channel fired on `connection.query()` |
| 47 | + // proves mysql was transformed... |
| 48 | + assert(line.includes('events=start'), `expected channel 'start' event, got: ${line}`); |
| 49 | + // ...with the real SQL forwarded through the channel context. |
| 50 | + assert(line.includes('statement=SELECT 1 AS solution'), `expected forwarded SQL, got: ${line}`); |
| 51 | + // The runtime hook set its detection marker at boot. |
| 52 | + assert(line.includes('"runtime":true'), `expected runtime marker, got: ${line}`); |
| 53 | +}); |
0 commit comments