Skip to content

Commit

Permalink
Add one happy case
Browse files Browse the repository at this point in the history
  • Loading branch information
chtushar committed Apr 26, 2024
1 parent 30532ee commit e811340
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/OpenAPM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const moduleNames = {
const packageJson = getPackageJson();

export class OpenAPM extends LevitateEvents {
readonly simpleCache: Record<string, any> = {};
public simpleCache: Record<string, any> = {};
private path: string;
private metricsServerPort: number;
private enabled: boolean;
Expand Down
38 changes: 29 additions & 9 deletions tests/prisma/prisma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import OpenAPM from '../../src/OpenAPM';
import { addRoutes, makeRequest } from '../utils';
import { Server } from 'http';

class OpenAPMExtended extends OpenAPM {
public simpleCache: Record<string, any>;

constructor() {
super({
enableMetricsServer: false
});
this.simpleCache = {};
}

clearSimpleCache() {
this.simpleCache = {};
}
}

async function mock(mockedUri, stub) {
const { Module } = await import('module');

Expand Down Expand Up @@ -33,10 +48,18 @@ describe('Prisma', () => {
let app: Express;
let server: Server;

beforeAll(async () => {
openapm = new OpenAPM({
enableMetricsServer: false
vi.hoisted(async () => {
await mock('@prisma/client', {
PrismaClient: class PrismaClient {
constructor() {
throw new Error('Cannot find module "@prisma/client"');
}
}
});
});

beforeAll(async () => {
openapm = new OpenAPMExtended();
openapm.instrument('express');

app = express();
Expand Down Expand Up @@ -67,11 +90,8 @@ describe('Prisma', () => {

test('metrics', async () => {
await unmock();
await openapm.shutdown();
openapm = new OpenAPM({
enableMetricsServer: false
});
const res = await makeRequest(app, '/metrics');
expect(res.text).toContain('prisma_pool_connections_busy');
(openapm as OpenAPMExtended).clearSimpleCache();
await makeRequest(app, '/metrics');
expect(openapm.simpleCache['prisma:installed']).toBe(true);
});
});

0 comments on commit e811340

Please sign in to comment.