Skip to content

Commit

Permalink
bump dependecies and move tests to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
noamokman committed Jun 16, 2024
1 parent a54e200 commit 1b13827
Show file tree
Hide file tree
Showing 7 changed files with 1,689 additions and 2,925 deletions.
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
49 changes: 23 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@osskit/monitor",
"version": "8.0.1",
"version": "8.0.2",
"repository": {
"url": "https://github.com/osskit/monitor"
},
Expand All @@ -21,9 +21,9 @@
"examples_server": "ts-node examples/server.ts",
"lint:base": "eslint . --ext .ts",
"lint": "yarn lint:base --fix",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --config tests/jest.config.ts",
"test": "vitest",
"format": "prettier --write '**/*.{ts,js,json}'",
"prepare": "husky install"
"prepare": "husky"
},
"engines": {
"node": ">=18.0.0"
Expand All @@ -32,32 +32,29 @@
"prom-client": ">=14.0.1"
},
"dependencies": {
"@sindresorhus/is": "^6.0.1",
"pino": "^8.16.0"
"@sindresorhus/is": "^6.3.1",
"pino": "^9.2.0"
},
"devDependencies": {
"@osskit/eslint-config": "^1.0.20",
"@osskit/eslint-config": "^1.0.25",
"@osskit/prettier-config": "^0.0.1",
"@osskit/tsconfig": "^0.0.6",
"@types/express": "^4.17.20",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.6",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.51.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.4.2",
"eslint-plugin-unicorn": "^48.0.1",
"express": "^4.18.2",
"express-prom-bundle": "^6.6.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^15.0.1",
"prettier": "^3.0.3",
"prom-client": "^15.0.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"@osskit/tsconfig": "^0.0.7",
"@types/express": "^4.17.21",
"@types/node": "^20.14.2",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^54.0.0",
"express": "^4.19.2",
"express-prom-bundle": "^7.0.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"prom-client": "^15.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"lint-staged": {
"*.ts": "eslint --fix",
Expand Down
2 changes: 1 addition & 1 deletion tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@osskit/eslint-config/test",
"extends": "@osskit/eslint-config",
"root": false,
"parserOptions": {
"project": "./tests/tsconfig.json"
Expand Down
26 changes: 0 additions & 26 deletions tests/jest.config.ts

This file was deleted.

81 changes: 40 additions & 41 deletions tests/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { register } from 'prom-client';
import type { BaseLogger } from 'pino';
// eslint-disable-next-line import/no-extraneous-dependencies
import { jest } from '@jest/globals';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { monitor, createMonitor, setGlobalOptions } from '../src/index.js';

describe('monitor', () => {
Expand All @@ -27,7 +26,7 @@ describe('monitor', () => {
expect(metrics).toHaveLength(4);
expect(metrics[2]).toMatchObject({ name: 'name_count' });
expect(metrics[3]).toMatchObject({ name: 'name_execution_time' });
expect(metrics[2]).toHaveProperty('hashMap.id:5,method:name,result:success', {
expect(metrics[2]).toHaveProperty('hashMap.id:5,method:name,result:success,', {
// eslint-disable-next-line @typescript-eslint/naming-convention
labels: { method: 'name', id: '5', result: 'success' },
value: 1,
Expand Down Expand Up @@ -75,7 +74,7 @@ describe('monitor', () => {
expect(metrics[3]).toMatchObject({ name: 'name_execution_time' });
expect(metrics[4]).toMatchObject({ name: 'scope_count' });
expect(metrics[5]).toMatchObject({ name: 'scope_execution_time' });
expect(metrics[4]).toHaveProperty('hashMap.method:name,result:success.value', 1);
expect(metrics[4]).toHaveProperty('hashMap.method:name,result:success,.value', 1);
});

it('should sanitize metric names', async () => {
Expand All @@ -94,19 +93,19 @@ describe('monitor', () => {
expect(metrics[5]).toMatchObject({ name: 'scope_execution_time' });
expect(metrics[6]).toMatchObject({ name: 'outer_scope_count' });
expect(metrics[7]).toMatchObject({ name: 'outer_scope_execution_time' });
expect(metrics[6]).toHaveProperty('hashMap.method:metric_name,result:success.value', 1);
expect(metrics[6]).toHaveProperty('hashMap.method:metric_name,result:success,.value', 1);
});

it('should write logs', () => {
const logger: BaseLogger = {
level: 'info',
info: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
silent: jest.fn(),
trace: jest.fn(),
warn: jest.fn(),
info: vi.fn<unknown[]>(),
debug: vi.fn<unknown[]>(),
error: vi.fn<unknown[]>(),
fatal: vi.fn<unknown[]>(),
silent: vi.fn<unknown[]>(),
trace: vi.fn<unknown[]>(),
warn: vi.fn<unknown[]>(),
};

setGlobalOptions({ logger });
Expand All @@ -124,13 +123,13 @@ describe('monitor', () => {
it('should write logs with context', () => {
const logger: BaseLogger = {
level: 'info',
info: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
silent: jest.fn(),
trace: jest.fn(),
warn: jest.fn(),
info: vi.fn<unknown[]>(),
debug: vi.fn<unknown[]>(),
error: vi.fn<unknown[]>(),
fatal: vi.fn<unknown[]>(),
silent: vi.fn<unknown[]>(),
trace: vi.fn<unknown[]>(),
warn: vi.fn<unknown[]>(),
};

setGlobalOptions({ logger });
Expand All @@ -148,13 +147,13 @@ describe('monitor', () => {
it('should write error log at error level', () => {
const logger: BaseLogger = {
level: 'info',
info: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
silent: jest.fn(),
trace: jest.fn(),
warn: jest.fn(),
info: vi.fn<unknown[]>(),
debug: vi.fn<unknown[]>(),
error: vi.fn<unknown[]>(),
fatal: vi.fn<unknown[]>(),
silent: vi.fn<unknown[]>(),
trace: vi.fn<unknown[]>(),
warn: vi.fn<unknown[]>(),
};

setGlobalOptions({ logger, parseError: (error) => error.message });
Expand All @@ -173,13 +172,13 @@ describe('monitor', () => {
it('should write error log at trace level', () => {
const logger: BaseLogger = {
level: 'info',
info: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
silent: jest.fn(),
trace: jest.fn(),
warn: jest.fn(),
info: vi.fn<unknown[]>(),
debug: vi.fn<unknown[]>(),
error: vi.fn<unknown[]>(),
fatal: vi.fn<unknown[]>(),
silent: vi.fn<unknown[]>(),
trace: vi.fn<unknown[]>(),
warn: vi.fn<unknown[]>(),
};

setGlobalOptions({ logger, errorLogLevel: 'trace', parseError: (error) => error.message });
Expand Down Expand Up @@ -219,7 +218,7 @@ describe('monitor', () => {
expect(metrics).toHaveLength(10);
expect(metrics[8]).toMatchObject({ name: 'customScope_count' });
expect(metrics[9]).toMatchObject({ name: 'customScope_execution_time' });
expect(metrics[8]).toHaveProperty('hashMap.method:custom,my_entity_id:5,result:success', {
expect(metrics[8]).toHaveProperty('hashMap.method:custom,my_entity_id:5,result:success,', {
// eslint-disable-next-line @typescript-eslint/naming-convention
labels: { method: 'custom', my_entity_id: '5', result: 'success' },
value: 1,
Expand All @@ -229,13 +228,13 @@ describe('monitor', () => {
it('should parse result', () => {
const logger = {
level: 'info',
info: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
silent: jest.fn(),
trace: jest.fn(),
warn: jest.fn(),
info: vi.fn<unknown[]>(),
debug: vi.fn<unknown[]>(),
error: vi.fn<unknown[]>(),
fatal: vi.fn<unknown[]>(),
silent: vi.fn<unknown[]>(),
trace: vi.fn<unknown[]>(),
warn: vi.fn<unknown[]>(),
} satisfies BaseLogger;

setGlobalOptions({ logger, errorLogLevel: 'trace', parseError: (error) => error.message });
Expand Down
Loading

0 comments on commit 1b13827

Please sign in to comment.