From 4229a6ede463a159f97be82f50ba6cfda04c3106 Mon Sep 17 00:00:00 2001 From: Philip Nwabuwa Date: Fri, 9 Oct 2026 11:26:03 +0000 Subject: [PATCH] test(deno): Type-check Deno unit tests `deno test` runs with `--no-check`, and `lint:types` only covers `src`, so type errors in `packages/deno/test` never failed CI. Simply dropping `--no-check` doesn't work in the monorepo: workspace packages (`@sentry/core`, `@sentry/server-utils`, ...) are symlinked into `node_modules`, so Deno treats their emitted `.d.ts` files as local modules and can't resolve their extensionless relative imports. Running with `--unstable-sloppy-imports` resolves those and also picks up `build/esm/*.d.ts` for the tests' `../build/esm/index.js` imports, so the tests are checked against the SDK's real types. The check runs as a separate `test:types` step so the test run itself keeps Deno's strict runtime resolution and still catches a broken specifier in the build output. Fixes getsentry/sentry-javascript#23899 --- packages/deno/package.json | 3 ++- packages/deno/test/deno-runtime-metrics.test.ts | 2 +- packages/deno/test/opentelemetry.test.ts | 5 +++-- packages/deno/test/sdk.test.ts | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/deno/package.json b/packages/deno/package.json index b1e3996e8dfd..99dcec12e7c6 100644 --- a/packages/deno/package.json +++ b/packages/deno/package.json @@ -49,7 +49,8 @@ "lint:fix": "oxlint . --fix --type-aware", "lint:es-compatibility": "es-check es2022 ./build/esm/*.js --module", "install:deno": "node ./scripts/install-deno.mjs", - "test": "run-s install:deno deno-types test:unit", + "test": "run-s install:deno deno-types test:types test:unit", + "test:types": "deno check --unstable-sloppy-imports test", "test:unit": "deno test --allow-net --allow-read --allow-run --allow-env --no-check", "test:unit:update": "deno test --allow-net --allow-read --allow-run --allow-env --no-check --allow-write -- --update", "yalc:publish": "yalc publish --push --sig" diff --git a/packages/deno/test/deno-runtime-metrics.test.ts b/packages/deno/test/deno-runtime-metrics.test.ts index 0dfdc5d35d6a..947cc1777e0f 100644 --- a/packages/deno/test/deno-runtime-metrics.test.ts +++ b/packages/deno/test/deno-runtime-metrics.test.ts @@ -45,7 +45,7 @@ async function collectMetrics( await client.flush(2000); // Stop the collection interval so Deno's leak detector doesn't flag it. - metricsIntegration.teardown?.(); + (metricsIntegration as { teardown?: () => void }).teardown?.(); const items: MetricItem[] = []; for (const envelope of envelopes) { diff --git a/packages/deno/test/opentelemetry.test.ts b/packages/deno/test/opentelemetry.test.ts index 12349ea6a78a..c8847ad3c468 100644 --- a/packages/deno/test/opentelemetry.test.ts +++ b/packages/deno/test/opentelemetry.test.ts @@ -1,5 +1,6 @@ import { getMainCarrier } from '@sentry/core'; import { assertEquals, assertNotEquals } from 'https://deno.land/std@0.212.0/assert/mod.ts'; +import type { TracerProvider } from 'npm:@opentelemetry/api@1'; import { context, propagation, trace } from 'npm:@opentelemetry/api@1'; import type { DenoClient } from '../build/esm/index.js'; import { init, startSpan } from '../build/esm/index.js'; @@ -149,8 +150,8 @@ Deno.test('should override pre-existing OTel provider with Sentry provider', asy resetSdk(); // Simulate a pre-existing OTel registration (e.g. from Supabase Edge Runtime) - const fakeProvider = { getTracer: () => ({}) }; - trace.setGlobalTracerProvider(fakeProvider as any); + const fakeProvider = { getTracer: () => ({}) } as unknown as TracerProvider; + trace.setGlobalTracerProvider(fakeProvider); const transactionEvents: any[] = []; diff --git a/packages/deno/test/sdk.test.ts b/packages/deno/test/sdk.test.ts index fe85e2ff9f45..032442ece005 100644 --- a/packages/deno/test/sdk.test.ts +++ b/packages/deno/test/sdk.test.ts @@ -6,10 +6,11 @@ import { init as initSdk, spanStreamingIntegration, } from '../build/esm/index.js'; +import type { DenoOptions } from '../build/esm/index.js'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; -function init(options) { +function init(options: DenoOptions) { getCurrentScope().setClient(undefined); return initSdk(options); } @@ -40,7 +41,7 @@ Deno.test("doesn't add spanStreamingIntegration if user added it manually", () = }); const integrations = client.getOptions().integrations.filter(i => i.name === 'SpanStreaming'); assertEquals(integrations.length, 1); - assert(!integrations[0].isDefaultInstance); + assert(!(integrations[0] as { isDefaultInstance?: true }).isDefaultInstance); }); Deno.test("doesn't add tracing integrations when tracing is disabled", () => { @@ -73,7 +74,7 @@ Deno.test('getDefaultIntegrations gates the tracing set on the options it is giv }); Deno.test("init doesn't write the computed default integrations back onto the options object", () => { - const options = { dsn: 'https://username@domain/123' }; + const options: DenoOptions = { dsn: 'https://username@domain/123' }; init(options); assertEquals('defaultIntegrations' in options, false); options.tracesSampleRate = 1;