From 40866716a7cddca8349c246cae585fc287132f2d Mon Sep 17 00:00:00 2001 From: Pedro Gallardo Date: Mon, 28 Aug 2023 19:39:33 -0300 Subject: [PATCH] fix: agrega opcion de stacktracelimit al contructor --- src/index.ts | 1 - src/lib/constructor.spec.ts | 7 +++---- src/lib/constructor.ts | 14 ++++++-------- src/types/Exotic.ts | 1 + src/utils/constants.ts | 8 ++++++++ src/utils/index.ts | 2 ++ 6 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 src/utils/constants.ts diff --git a/src/index.ts b/src/index.ts index 1156e98..1bd8b60 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1 @@ -Error.stackTraceLimit = 3; export { default } from "./Emulator.js"; diff --git a/src/lib/constructor.spec.ts b/src/lib/constructor.spec.ts index 964b93f..cb4cf20 100644 --- a/src/lib/constructor.spec.ts +++ b/src/lib/constructor.spec.ts @@ -1,12 +1,10 @@ import Emulator from "../Emulator"; import Exotic from "../types/Exotic"; -import { map } from "../utils"; +import { map, constants } from "../utils"; describe("(constructor)", () => { it("Creates a new emulator", () => { - const config: Exotic.emulator.options = { - traceErrors: false, - }; + const config: Exotic.emulator.options = constants.CONFIG; const emulator = new Emulator(config); const data: Record = map.emulators.get(emulator) || {}; const dataProps = ["options", "refs", "links", "counter", "proxySet"]; @@ -17,6 +15,7 @@ describe("(constructor)", () => { expect(options).toEqual(config); expect(Object.keys(refs).length).toBe(0); expect(Object.keys(links).length).toBe(0); + expect(Error.stackTraceLimit).toBe(config.stackTraceLimit); expect(counter).toBe(0); }); }); diff --git a/src/lib/constructor.ts b/src/lib/constructor.ts index 93467ba..024c1b5 100644 --- a/src/lib/constructor.ts +++ b/src/lib/constructor.ts @@ -1,17 +1,15 @@ import Exotic from "../types/Exotic.js"; -import { map } from "../utils/index.js"; +import { map, constants } from "../utils/index.js"; export default function constructor( scope: Exotic.Emulator, - options?: Exotic.emulator.options, + options: Exotic.emulator.options = {}, ): void { // set config defaults - const config: Exotic.emulator.options = { - traceErrors: false, - }; - if (options) { - Object.assign(config, options); - } + const config: Exotic.emulator.options = constants.CONFIG; + Object.assign(config, options); + Error.stackTraceLimit = config.stackTraceLimit; + const data: Exotic.emulator.data = { options: config, refs: Object.create(null), diff --git a/src/types/Exotic.ts b/src/types/Exotic.ts index 7c8126f..bd038ff 100644 --- a/src/types/Exotic.ts +++ b/src/types/Exotic.ts @@ -28,6 +28,7 @@ declare namespace Exotic { namespace emulator { interface options { traceErrors?: boolean; + stackTraceLimit?: number; } interface data { diff --git a/src/utils/constants.ts b/src/utils/constants.ts new file mode 100644 index 0000000..9ada88f --- /dev/null +++ b/src/utils/constants.ts @@ -0,0 +1,8 @@ +import Exotic from "../types/Exotic.js"; + +const CONFIG: Exotic.emulator.options = { + traceErrors: false, + stackTraceLimit: 3, +}; + +export default { CONFIG }; diff --git a/src/utils/index.ts b/src/utils/index.ts index cab7119..8371d23 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -9,6 +9,7 @@ import encode from "./encode.js"; import decode from "./decode.js"; import isPayload from "./isPayload.js"; import findProxyById from "./findProxyById.js"; +import constants from "./constants.js"; export { isTraceable, @@ -22,4 +23,5 @@ export { isPayload, decode, findProxyById, + constants, };