Initial Commit
This commit is contained in:
14
packages/api-stack/api/api-plugin-audit/tests/setup/hono-shim.d.ts
vendored
Normal file
14
packages/api-stack/api/api-plugin-audit/tests/setup/hono-shim.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// Test-only Hono ContextVariableMap shim — adds the slots normally
|
||||
// contributed by sibling plugins (`@suaveplan/api-plugin-auth`,
|
||||
// `@suaveplan/api-tenant`, `@suaveplan/api`) so test files can call
|
||||
// `c.set("user", ...)`, `c.set("tenant", ...)`, `c.set("requestId", ...)`
|
||||
// without ts2769 errors when the sibling packages are not direct deps.
|
||||
import "hono";
|
||||
|
||||
declare module "hono" {
|
||||
interface ContextVariableMap {
|
||||
user: { id?: string } | null | undefined;
|
||||
tenant: { id?: string } | null | undefined;
|
||||
requestId: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Test setup for @suaveplan/api-plugin-audit.
|
||||
*
|
||||
* Installs a real in-memory OpenTelemetry MeterProvider BEFORE any source
|
||||
* module imports so the meter resolved on first call binds to it.
|
||||
*/
|
||||
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,
|
||||
});
|
||||
|
||||
export const testMeterProvider = new MeterProvider({ readers: [reader] });
|
||||
metrics.setGlobalMeterProvider(testMeterProvider);
|
||||
|
||||
export async function flushTestMetrics() {
|
||||
await testMeterProvider.forceFlush();
|
||||
const collected = testInMemoryMetricExporter.getMetrics();
|
||||
testInMemoryMetricExporter.reset();
|
||||
return collected;
|
||||
}
|
||||
Reference in New Issue
Block a user