Skip to content

Commit

Permalink
fix parse result and update deps (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
SharonGrossman authored Oct 18, 2023
1 parent d7ba715 commit a54e200
Show file tree
Hide file tree
Showing 9 changed files with 1,493 additions and 1,004 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": ["@osskit"],
"root": true,
"ignorePatterns": [
"examples/**",
"dist/**"
Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@osskit/monitor",
"version": "8.0.0",
"version": "8.0.1",
"repository": {
"url": "https://github.com/osskit/monitor"
},
Expand Down Expand Up @@ -32,32 +32,32 @@
"prom-client": ">=14.0.1"
},
"dependencies": {
"@sindresorhus/is": "^5.3.0",
"pino": "^8.5.0"
"@sindresorhus/is": "^6.0.1",
"pino": "^8.16.0"
},
"devDependencies": {
"@osskit/eslint-config": "^1.0.10",
"@osskit/eslint-config": "^1.0.20",
"@osskit/prettier-config": "^0.0.1",
"@osskit/tsconfig": "^0.0.6",
"@types/express": "^4.17.14",
"@types/jest": "^29.0.2",
"@types/node": "^18.7.18",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.23.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.0.4",
"eslint-plugin-unicorn": "^43.0.2",
"express": "^4.18.1",
"express-prom-bundle": "^6.5.0",
"husky": "^8.0.1",
"jest": "^29.0.3",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"prom-client": "^14.1.0",
"ts-jest": "^29.0.1",
"@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": "^4.8.3"
"typescript": "^5.2.2"
},
"lint-staged": {
"*.ts": "eslint --fix",
Expand Down
4 changes: 2 additions & 2 deletions src/globalOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const setGlobalOptions = ({
prometheusBuckets = optionalPrometheusBuckets;
}

if (typeof optionalLogExecutionStart !== 'undefined') {
if (optionalLogExecutionStart !== undefined) {
logExecutionStart = optionalLogExecutionStart;
}

if (typeof optionalLogResult !== 'undefined') {
if (optionalLogResult !== undefined) {
logResult = optionalLogResult;
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface MonitorOptionsBase {
}

export interface MonitorOptions<Result> extends MonitorOptionsBase {
parseResult?: <T>(result: Awaited<Result>) => T;
parseResult?: (result: Awaited<Result>) => any;
}

export interface Monitor<Result> {
Expand Down
6 changes: 5 additions & 1 deletion tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "@osskit/eslint-config/test"
"extends": "@osskit/eslint-config/test",
"root": false,
"parserOptions": {
"project": "./tests/tsconfig.json"
}
}
8 changes: 6 additions & 2 deletions tests/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { InitialOptionsTsJest } from 'ts-jest';
import type { JestConfigWithTsJest } from 'ts-jest';

const config: InitialOptionsTsJest = {
const config: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
Expand All @@ -10,6 +10,10 @@ const config: InitialOptionsTsJest = {
'ts-jest',
{
useESM: true,
isolatedModules: true,
diagnostics: {
exclude: ['!**/*.spec.ts'],
},
},
],
},
Expand Down
25 changes: 25 additions & 0 deletions tests/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,30 @@ describe('monitor', () => {
value: 1,
});
});

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(),
} satisfies BaseLogger;

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

const scoped = createMonitor({ scope: 'scope' });

scoped('logs', () => ({ a: 5 }), { logResult: true, parseResult: ({ a }) => a });

expect(logger.info).toHaveBeenCalled();

const [call] = logger.info.mock.calls;
expect(call?.[0]).toHaveProperty('extra.executionResult.value', 5);
expect(call?.[1]).toBe('scope.logs.success');
});
});
});
3 changes: 2 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "../tsconfig.json"
"extends": "../tsconfig.json",
"include": ["*.ts"]
}
Loading

0 comments on commit a54e200

Please sign in to comment.