Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/**
* Test-environment setup for @suaveplan/license.
*
* Wires a real in-memory OpenTelemetry `MeterProvider` BEFORE any
* source module is imported, so the meter resolved by `instruments.ts`
* at module load is the real provider's meter — not the noop fallback.
* Tests that inspect emitted metrics can read them out of
* `testInMemoryMetricExporter`.
*
* Node ≥18 already exposes `crypto.subtle` and `crypto.getRandomValues`
* globally, so no crypto polyfill is required.
*/
import { metrics } from "@opentelemetry/api";
import {
AggregationTemporality,
InMemoryMetricExporter,
MeterProvider,
PeriodicExportingMetricReader,
} from "@opentelemetry/sdk-metrics";
export const testInMemoryMetricExporter = new InMemoryMetricExporter(
AggregationTemporality.CUMULATIVE
);
const reader = new PeriodicExportingMetricReader({
exporter: testInMemoryMetricExporter,
exportIntervalMillis: 60_000, // tests flush manually via `flushTestMetrics`
});
export const testMeterProvider = new MeterProvider({ readers: [reader] });
metrics.setGlobalMeterProvider(testMeterProvider);
/**
* Force a flush of the test meter provider, returning the collected
* `ResourceMetrics` snapshots captured by the in-memory exporter so
* far. Resets the exporter's buffer.
*/
export async function flushTestMetrics() {
await testMeterProvider.forceFlush();
const collected = testInMemoryMetricExporter.getMetrics();
testInMemoryMetricExporter.reset();
return collected;
}