"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const prom_client_1 = require("prom-client");
const _1 = require(".");
const supertest_1 = __importDefault(require("supertest"));
const logging_1 = require("../logging");
describe('Metrics', () => {
    test('Create metrics', () => {
        const metrics = _1.createMetrics();
        expect(metrics.client).toBeDefined();
        expect(metrics.registry).toBeInstanceOf(prom_client_1.Registry);
        metrics.registry.clear();
    });
    test('Serve metrics', () => __awaiter(void 0, void 0, void 0, function* () {
        const { client, registry } = _1.createMetrics();
        const logger = logging_1.createLogger({ name: 'test' });
        const server = _1.createMetricsServer({ logger, registry, port: 51235 });
        try {
            // Create two metrics for testing
            const counter = new client.Counter({
                name: 'counter',
                help: 'counter help',
                registers: [registry],
            });
            const gauge = new client.Gauge({
                name: 'gauge',
                help: 'gauge help',
                registers: [registry],
            });
            counter.inc();
            counter.inc();
            gauge.set(100);
            // Verify that the registered metrics are served at `/`
            const response = yield supertest_1.default(server).get('/metrics').send();
            expect(response.status).toEqual(200);
            expect(response.text).toMatch(/counter 2/);
            expect(response.text).toMatch(/gauge 100/);
        }
        finally {
            server.close();
            registry.clear();
        }
    }));
});
//# sourceMappingURL=index.test.js.map