Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keturiosakys committed Jul 12, 2023
1 parent 08e9af2 commit 9f8a781
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/lib/tests/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { autometrics, init } from "../src";
import { Autometrics, autometrics, init } from "../src";
import { describe, test, expect, beforeAll, afterEach } from "vitest";
import {
AggregationTemporality,
Expand Down Expand Up @@ -57,4 +57,39 @@ describe("Autometrics integration test", () => {

expect(serialized).toMatch(errorCountMetric);
});

test("class method", async () => {
const callCountMetric =
/function_calls_count_total\{\S*function="helloWorld"\S*module="\/packages\/lib\/tests\/integration.test.ts"\S*\} 2/gm;
const durationMetric =
/function_calls_duration_bucket\{\S*function="helloWorld"\S*module="\/packages\/lib\/tests\/integration.test.ts"\S*\}/gm;

// @Autometrics decorator is likely to be used along-side other decorators
// this tests for any conflicts
function Bar() {
return function Bar(
target: Object,
propertyKey: string,
descriptor: PropertyDescriptor,
) {
const originalMethod = descriptor.value;
descriptor.value = originalMethod;
};
}

@Autometrics()
class Foo {
@Bar()
helloWorld() {}
}

const foo = new Foo();
foo.helloWorld();
foo.helloWorld();

const serialized = await collectAndSerialize(exporter);

expect(serialized).toMatch(callCountMetric);
expect(serialized).toMatch(durationMetric);
});
});

0 comments on commit 9f8a781

Please sign in to comment.