Skip to content

Commit bf6b8da

Browse files
committed
refactoring
1 parent c30e018 commit bf6b8da

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

jest.config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ module.exports = {
88
}],
99
},
1010
setupFilesAfterEnv:[
11-
"./jest.setupFilesAfterEnv.ts"
11+
//"./jest.setupFilesAfterEnv.ts"
12+
"jest-extended/all"
1213
],
1314
testTimeout: 30000,
14-
verbose: true
15-
};
15+
verbose: true,
16+
moduleNameMapper: {
17+
"^@/(.*)$": "<rootDir>/src/$1"
18+
}
19+
};

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Try-catch-finally-hooks
2+
3+
Try-catch-finally-hooks is a simple AOP-ish toolset that lets to wrap sync and async functions and class methods with hooks, that let:
4+
5+
- override:
6+
- input parameters
7+
- result
8+
- this arg
9+
- function itself (hook can conditionally do some extra wrapping)
10+
- handle and override error
11+
12+
It supports using as decorator, function wrapper or scope of anonymous function

src/specs/combine-hooks.spec.ts renamed to specs/combine-hooks.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { callStack } from "../callStack";
2-
import { measureDuration } from "../measureDuration";
3-
import { TryCatchFinallyHooksBuilder, ITryCatchFinallyHook } from "../TryCatchFinallyHooks";
1+
import { callStack } from "@/callStack";
2+
import { measureDuration } from "@/measureDuration";
3+
import { TryCatchFinallyHooksBuilder, ITryCatchFinallyHook } from "@/TryCatchFinallyHooks";
44

55

66
export const logOnFinally: ITryCatchFinallyHook<{ args: { name?: string; }; name:string }> = {

src/specs/hooks.decorator.spec.ts renamed to specs/hooks.decorator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TryCatchFinallyHooksBuilder } from '../TryCatchFinallyHooks';
1+
import { TryCatchFinallyHooksBuilder } from '@/TryCatchFinallyHooks';
22

33
test("log try finally asMethodDecorator", () => {
44
const log = jest.fn();

src/specs/hooks.function.spec.ts renamed to specs/hooks.function.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TryCatchFinallyHooksBuilder } from '../TryCatchFinallyHooks';
1+
import { TryCatchFinallyHooksBuilder } from '@/TryCatchFinallyHooks';
22

33
test("log try finally asFunction", () => {
44
const log = jest.fn();

src/specs/hooks.scope.spec.ts renamed to specs/hooks.scope.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { TryCatchFinallyHooksBuilder } from '../TryCatchFinallyHooks';
1+
import 'jest-extended'
2+
import { TryCatchFinallyHooksBuilder } from '@/TryCatchFinallyHooks'
23

34
test("log onTry asScope", () => {
45
const log = jest.fn();
@@ -82,7 +83,5 @@ test("async log onTry asScope",async ()=>{
8283
expect(logFinally).toHaveBeenCalledTimes(1)
8384
expect(logFinally).toHaveBeenCalledWith("onFinally", "MyAction")
8485

85-
expect(logFinally).toHaveBeenCalledAfter(myFunc);
86-
87-
86+
expect(logFinally).toHaveBeenCalledAfter(myFunc)
8887
})

tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,10 @@
105105
/* Completeness */
106106
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107107
"skipLibCheck": true /* Skip type checking all .d.ts files. */
108+
,"baseUrl": ".",
109+
"paths": {
110+
"@/*": ["src/*"]
111+
}
112+
108113
}
109114
}

0 commit comments

Comments
 (0)