From 864bf40da3a4a4341aad1aa5f1fa93d279b248da Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sun, 27 Sep 2020 00:31:22 +0200 Subject: [PATCH] Prevented all tests to log to console, except for one DebugController test. --- assets/quests/defaults/default_ep_1.qst | Bin 3344 -> 3344 bytes assets_generation/update_drops_ephinea.ts | 2 +- assets_generation/update_ephinea_data.ts | 2 +- assets_generation/update_generic_data.ts | 2 +- src/application/index.test.ts | 37 ++-- src/core/DisposablePromise.ts | 5 +- src/core/Result.ts | 4 +- .../get_map_designations.ts | 2 +- .../data_flow_analysis/get_register_value.ts | 2 +- .../asm/data_flow_analysis/get_stack_value.ts | 2 +- .../compression/prs/decompress.ts | 2 +- src/core/data_formats/parsing/afs.ts | 2 +- src/core/data_formats/parsing/iff.ts | 2 +- src/core/data_formats/parsing/ninja/njcm.ts | 2 +- .../data_formats/parsing/ninja/texture.ts | 2 +- src/core/data_formats/parsing/ninja/xj.ts | 2 +- src/core/data_formats/parsing/prc.ts | 2 +- .../data_formats/parsing/quest/bin.test.ts | 49 +++-- src/core/data_formats/parsing/quest/bin.ts | 2 +- .../data_formats/parsing/quest/dat.test.ts | 91 ++++---- src/core/data_formats/parsing/quest/dat.ts | 2 +- .../data_formats/parsing/quest/index.test.ts | 203 +++++++++--------- src/core/data_formats/parsing/quest/index.ts | 2 +- .../data_formats/parsing/quest/object_code.ts | 2 +- src/core/data_formats/parsing/quest/qst.ts | 2 +- src/core/data_formats/parsing/rlc.ts | 2 +- src/core/gui/Table.ts | 2 +- src/core/gui/Widget.ts | 2 +- src/core/gui/dom.ts | 2 +- src/core/{Logger.ts => logging.ts} | 45 ++-- src/core/observable/Disposer.ts | 2 +- src/core/observable/SimpleEmitter.ts | 2 +- .../property/AbstractMinimalProperty.ts | 2 +- .../property/FlatMappedProperty.test.ts | 34 +-- .../property/list/AbstractListProperty.ts | 2 +- src/core/persistence/Persister.ts | 2 +- src/core/stores/Store.ts | 4 + src/core/undo/UndoStack.ts | 2 +- src/core/util.ts | 38 +++- .../gui/MethodsForEpisodeView.ts | 2 +- .../gui/OptimizationResultView.ts | 2 +- src/hunt_optimizer/gui/WantedItemsView.ts | 2 +- src/hunt_optimizer/stores/HuntMethodStore.ts | 2 +- src/hunt_optimizer/stores/ItemDropStore.ts | 2 +- src/quest_editor/QuestRunner.ts | 4 +- .../controllers/DebugController.test.ts | 19 +- .../controllers/DebugController.ts | 2 +- .../controllers/EntityInfoController.test.ts | 11 +- .../QuestEditorToolBarController.test.ts | 10 +- .../QuestEditorToolBarController.ts | 2 +- .../controllers/QuestInfoController.test.ts | 11 +- src/quest_editor/gui/DebugView.ts | 2 +- src/quest_editor/gui/EntityInfoView.test.ts | 30 +-- src/quest_editor/gui/EventSubGraphView.ts | 2 +- src/quest_editor/gui/NpcCountsView.test.ts | 19 +- .../gui/QuestEditorToolBarView.test.ts | 10 +- src/quest_editor/gui/QuestEditorView.ts | 2 +- src/quest_editor/gui/QuestInfoView.test.ts | 27 ++- .../__snapshots__/QuestInfoView.test.ts.snap | 109 ---------- src/quest_editor/loading/EntityAssetLoader.ts | 2 +- src/quest_editor/model/QuestModel.ts | 2 +- .../rendering/Quest3DModelManager.ts | 2 +- src/quest_editor/scripting/assembly.ts | 2 +- src/quest_editor/scripting/disassembly.ts | 2 +- .../scripting/vm/VirtualMachine.ts | 2 +- src/quest_editor/scripting/vm/io.ts | 2 +- src/quest_editor/stores/LogStore.ts | 8 +- src/quest_editor/stores/QuestEditorStore.ts | 2 +- src/quest_editor/stores/model_conversion.ts | 2 +- .../model/ModelToolBarController.ts | 2 +- .../controllers/texture/TextureController.ts | 2 +- src/viewer/gui/model/ModelView.test.ts | 10 +- src/viewer/gui/texture/TextureView.test.ts | 10 +- src/viewer/rendering/ModelRenderer.ts | 2 +- src/viewer/rendering/TextureRenderer.ts | 2 +- src/viewer/stores/ModelStore.ts | 2 +- src/viewer/util/texture_parsing.ts | 2 +- .../core/observables/disposable_helpers.ts | 29 --- test/src/utils.ts | 33 +++ 79 files changed, 458 insertions(+), 498 deletions(-) rename src/core/{Logger.ts => logging.ts} (80%) delete mode 100644 test/src/core/observables/disposable_helpers.ts diff --git a/assets/quests/defaults/default_ep_1.qst b/assets/quests/defaults/default_ep_1.qst index 8e30b59333ff9062a205e1fc1e9ea5dc5a351fed..16af68e954414115b1bf681804cd6404e338069d 100644 GIT binary patch literal 3344 zcmeHJYfx186+g=^toz_CVd+@dL?)qa#_k83W+ptAhhnq_A2EyalBbV~Xu-e))EmW2 zGeZ(SG@3?(+r&&KQR6nX<3+CJmc4A9WJZ`8#7ByEa4)R7!0vKkA9v6GdkIrJlj(=_ zV`n&X@BiNa`JLzQ!Xt>1HPHZzx~jeZ(Jo@8|9jk;J^L4Z zMfvk2?i1}IwnCNs-Ou-H$y3PcKunE9Tui_WQD?||W&myQJ=3vcf15pP9^ezWa!-J0 zsJsc{V=QEY)K$c|Q6XUE+ngQpz?g4sDhXW<5S;?FaMgjbvGG?<{O0v20l%ExC@@(m z=Qj@U7|TkU)uEOP0Bo&*N>Mo^;0tM^jOBpa&Ps7SYJ9^HvU8(!u9!=K-w2eom@zT!=)09RJrY)L8}m$`|7okTv*x z0AiVP9VcBq7b$YOe#v8^xx|U;c~LE(_0ic5raRnP=EN`0MU-!PK9y_eoFlw}DSQyH z^pzIpI`Iam3M940}?CPVG zKL3N4{$Ss7l5%O}LUIPY7P3|98eFXx^_A9O+-mAlr+)(yb-p{$uYqqlpsX$}c~$Dl zhbV}>EyfDi*50PK`&9?OKE$J*m2{hkZqv3}C&r0!GTVdm%b3xr17kcI%(J?LcV2U1 zyqFU&;BQ}?t>Vu126&8XG>>bj3Ei-O2|k;Ep5I4xw51uQkd+MPab34X>U!D0B({r* z0#Xr8(@O8oJl2UkvX2t2LEWZOscWr)N$L}m1l&c9-}~atiKFpO6lPzLlWtedB+rY< z0`55Zrw;CSr=K6;@9C{B-Ng|n?kJYJipTr*PA(U)B`PyA+5>KUG`3r+<3VYQ*Vo@0`jwOpI`!2 zhdN}Xkx%Wekf|_;2APUZ<}JpeXnj}in7yO9!lTYq>BO{}sU86@|Kh_@=B0DiU@YZN z9p25igiRjC)PT#AbCFT|VT%And0t z*{Tj11b=L+IjEbnMcq=DPtz3+yq#Xz;=88Qb9m~+!)V}K5>3e#AyYbhK!fVP&W9({ zBjfob04^_VOaUO%1RzYdLB@V)fj#}$el%c&*4oRv=MS6- zRYUH_)zA!$>7jkF>H*($V;@|qgH;e9cKQ80K**Elhh1)N4KSgXL(+zm@P073`H@1C zeQ+wM$$4W|leRgSCKIw+JZBD+TBx8F(e>g z3eWKF^{i4wdOu&e_uo~Nq@?CgEz+@cE-|pgfXu+cPO%^h`@_Pj@csRvqMfdEpc0as zl%9_t5OHQtANZ5ZEb1b*f^VADm2{Onp9)ABeWekuv%Ee=hOU7;zh;ys<#cZqy;mM^ z#renS$M-gKoVZE$rgC9gJ5$H55a?>Urf3EE``E2jZRRF((bHQyC1Wd#iLj6%!8Td* zwYr9`jW`gNeUaPHQ1z_2=fG$DU*h_*cwM`kB*k>x*IP^1IWR-t@$-WEA^Mrq@6(To zi^gP1(xusM3~=f?I;Y-&$GB7XY4_kyIUKnP(+g<2NqM!mo^EiU-?WS>oMpf5-+#Q9 z46XIp4x2q%>Y;Y#8C%9zbOYVKD=U|r?8$8!5Iuwc0Dqc!XaRlBMECBZcgy}+WSjlr mi@}?fAn2o^TLvw113$A}566E;@6xfv!2cx!YZiurEdK%%e4wKM literal 3344 zcmd6p3v5%@8OJ|Al3*MjaR8HvW(kFrZiqQkH?=DycI*HtW4vkz0YV;jAQj=!Wxz;6 zZeD0qRt43{N|7MEv@!;SzOs&n_!ZP`5~E>h<{JDW34Z(9xz{Jbkh61dAaqnn)wD?* z**@Pr-~aoa@7#Ot=Tih4_^wT-uPpoZwweXHvKl^QUkZSBdrei%HofjiM$v!4Ew9?n zW6DKO=gtzR^O`4f!2&WooD6_Dx0f@NAmpVOlmHWni4{#vCIF=pn_W|_{0J}LTmV!a z_vHf8IOs9a(~D<~4C+eJM)+b9~}269%xC zu}LN-NzW=1Q5rDh>T_bHY?^XK!q9P;g_K4*Wo{I;`A>XF101s7-=kwcv_?dKY@{J7X<=hwr;A9{ zjp21pvc-y)h$Gh{AXW=cMwU{aw7BV`p=oDA4}=hzaf7;NDEQPJl&FG|N;UyHK?LCb z3HyEPM}fU9fuvfCIs!P`h#&{V4}q@fC&khqmC%{znJfbh};|v`&_F( zwfdz3uk@@JUp*GFq)@4kmyb-I=8C-@CUn)q=#k{;p&1mG;X%xFcPu zO&F?GD$nGT?#Yn?Pj`I6X*RTzb!di^p3JFh$uz2L*OW%*6vtfGZ(km&h@LqA+3=jG z(j%h=rOq2`30>fry01KzHLVTxCxiuv4QFM}@02 z&)6Sy-81^rTz2WoA~N@4lTDUwll67mwoo2><6wh!iq$_b)aI3T7;Vy(>#eqQL0@P3 z*}mcPIuFQs~= zba6+*u(a&vbW=~~bp6eC!Hv_Q^Jc8?ZzV~}?eqq#ZHB35M!1q)w8b)*y14g%#$&X} z2%fIqc&1P8{--?B+Uq*ldb)pjb8p=o*V(=-m;6xmrZasrN4}aFIosFr`GIDSV9$lO z#SUY#1H{~G1Mp;hcvMsHd>Me1d~w!v^24>U0CJ&)?N9?%fNNkI=t1`%Z{L{ev3NY{ z+lCt6B;jQohofWx-b1K0u$4>-J4r`e+)QQgE5OyH+Xf3b%?=W`4X}<}aqTg1*-mYaw;N6i`0dGVg zSs2RkNfwP3`y{!`Ns(=kkeZa(L}l9yo$6bgNTE+=9{B zA?~3+!)+BNHCk&!CUg!RM%v$?GE|6ikTwGekT3paT>Dx4Wc*-!S6sV3u8O}HPm60u zSU3Au_A;wI$~Ll9>?&6K3Y*PJ*eIj5u_pE$dzi)KIsJbZEeA+?wE3Rdo;y=;jjIo2 z@4%Di2cu209UM|ciPe_TSsv=Pef-n+D_k9~o;lEOH$vpO9XCo6hVtMcd%cr-#rd4a zvo_pgm#t?;;0*8jvMXN!g5CRZoS z>QtAz&*LTHU`hAgB%qrkn@_oA#(K>z)b)In3J2T2SLnHtQv9_?zQG*0YW94DtJT4~ zfl?DSAT9MtWngd6r@v@n~J(Z4cFrUg4isaB@1)t3ZTuZ5vP^=_su3EfjvXEwz)HOERK*BB9` zTLP! { - const logged_errors: string[] = []; - - const handler: LogHandler = ({ severity, message }) => { - if (severity >= Severity.Error) { - logged_errors.push(message); - } - }; - - return LogManager.with_default_handler(handler, async () => { + test( + `Initialization and shutdown ${with_path} should succeed without throwing or logging errors.`, + pw_test({ max_log_severity: Severity.Warning }, async disposer => { if (path != undefined) { window.location.hash = path; } - const app = initialize_application( - new FileSystemHttpClient(), - new Random(() => 0.27), - new StubClock(new Date("2020-01-01T15:40:20Z")), - () => STUB_RENDERER, + const app = disposer.add( + initialize_application( + new FileSystemHttpClient(), + new Random(() => 0.27), + new StubClock(new Date("2020-01-01T15:40:20Z")), + () => STUB_RENDERER, + ), ); expect(app).toBeDefined(); - expect(logged_errors).toEqual([]); await timeout(1000); - - app.dispose(); - - expect(logged_errors).toEqual([]); - }); - }); + }), + ); } diff --git a/src/core/DisposablePromise.ts b/src/core/DisposablePromise.ts index a67b32ac..d85c6204 100644 --- a/src/core/DisposablePromise.ts +++ b/src/core/DisposablePromise.ts @@ -1,4 +1,5 @@ import { Disposable } from "./observable/Disposable"; +import { is_promise_like } from "./util"; enum State { Pending, @@ -250,7 +251,3 @@ export class DisposablePromise implements Promise, Disposable { } } } - -function is_promise_like(value?: T | PromiseLike): value is PromiseLike { - return value != undefined && typeof (value as any).then === "function"; -} diff --git a/src/core/Result.ts b/src/core/Result.ts index b7868f60..eeac2abd 100644 --- a/src/core/Result.ts +++ b/src/core/Result.ts @@ -1,4 +1,4 @@ -import { Logger } from "./Logger"; +import { Logging } from "./logging"; import { Severity } from "./Severity"; export type Result = Success | Failure; @@ -60,7 +60,7 @@ export function unwrap(result: Result): T { export class ResultBuilder { private readonly problems: Problem[] = []; - constructor(private readonly logger: Logger) {} + constructor(private readonly logger: Logging) {} /** * Add a problem to the problems array and log it with {@link logger}. diff --git a/src/core/data_formats/asm/data_flow_analysis/get_map_designations.ts b/src/core/data_formats/asm/data_flow_analysis/get_map_designations.ts index e15c1e28..e5af5077 100644 --- a/src/core/data_formats/asm/data_flow_analysis/get_map_designations.ts +++ b/src/core/data_formats/asm/data_flow_analysis/get_map_designations.ts @@ -2,7 +2,7 @@ import { InstructionSegment } from "../instructions"; import { ControlFlowGraph } from "./ControlFlowGraph"; import { OP_BB_MAP_DESIGNATE, OP_MAP_DESIGNATE, OP_MAP_DESIGNATE_EX } from "../opcodes"; import { get_register_value } from "./get_register_value"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; const logger = LogManager.get("core/data_formats/asm/data_flow_analysis/map_designations"); diff --git a/src/core/data_formats/asm/data_flow_analysis/get_register_value.ts b/src/core/data_formats/asm/data_flow_analysis/get_register_value.ts index 5f74dfea..544333c6 100644 --- a/src/core/data_formats/asm/data_flow_analysis/get_register_value.ts +++ b/src/core/data_formats/asm/data_flow_analysis/get_register_value.ts @@ -25,7 +25,7 @@ import { } from "../opcodes"; import { BasicBlock, ControlFlowGraph } from "./ControlFlowGraph"; import { ValueSet } from "./ValueSet"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; const logger = LogManager.get("core/data_formats/asm/data_flow_analysis/register_value"); diff --git a/src/core/data_formats/asm/data_flow_analysis/get_stack_value.ts b/src/core/data_formats/asm/data_flow_analysis/get_stack_value.ts index f9e8d6ab..b2e150f6 100644 --- a/src/core/data_formats/asm/data_flow_analysis/get_stack_value.ts +++ b/src/core/data_formats/asm/data_flow_analysis/get_stack_value.ts @@ -14,7 +14,7 @@ import { import { BasicBlock, ControlFlowGraph } from "./ControlFlowGraph"; import { ValueSet } from "./ValueSet"; import { get_register_value } from "./get_register_value"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; const logger = LogManager.get("core/data_formats/asm/data_flow_analysis/stack_value"); diff --git a/src/core/data_formats/compression/prs/decompress.ts b/src/core/data_formats/compression/prs/decompress.ts index d2974acd..1f58f814 100644 --- a/src/core/data_formats/compression/prs/decompress.ts +++ b/src/core/data_formats/compression/prs/decompress.ts @@ -2,7 +2,7 @@ import { Cursor } from "../../block/cursor/Cursor"; import { ResizableBlockCursor } from "../../block/cursor/ResizableBlockCursor"; import { WritableCursor } from "../../block/cursor/WritableCursor"; import { ResizableBlock } from "../../block/ResizableBlock"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { browser_supports_webassembly } from "../../../util"; import { get_prs_wasm_module } from "./prs_wasm"; import { Result, ResultBuilder, success } from "../../../Result"; diff --git a/src/core/data_formats/parsing/afs.ts b/src/core/data_formats/parsing/afs.ts index 2eb7ab12..a6c614c0 100644 --- a/src/core/data_formats/parsing/afs.ts +++ b/src/core/data_formats/parsing/afs.ts @@ -1,5 +1,5 @@ import { Cursor } from "../block/cursor/Cursor"; -import { LogManager } from "../../Logger"; +import { LogManager } from "../../logging"; import { Result, ResultBuilder } from "../../Result"; import { Severity } from "../../Severity"; diff --git a/src/core/data_formats/parsing/iff.ts b/src/core/data_formats/parsing/iff.ts index 6ede1067..06107173 100644 --- a/src/core/data_formats/parsing/iff.ts +++ b/src/core/data_formats/parsing/iff.ts @@ -1,6 +1,6 @@ import { Cursor } from "../block/cursor/Cursor"; import { Result, ResultBuilder } from "../../Result"; -import { LogManager } from "../../Logger"; +import { LogManager } from "../../logging"; import { Severity } from "../../Severity"; const logger = LogManager.get("core/data_formats/parsing/iff"); diff --git a/src/core/data_formats/parsing/ninja/njcm.ts b/src/core/data_formats/parsing/ninja/njcm.ts index 20e1edf7..98732a28 100644 --- a/src/core/data_formats/parsing/ninja/njcm.ts +++ b/src/core/data_formats/parsing/ninja/njcm.ts @@ -1,6 +1,6 @@ import { Cursor } from "../../block/cursor/Cursor"; import { Vec2, Vec3 } from "../../vector"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; const logger = LogManager.get("core/data_formats/parsing/ninja/njcm"); diff --git a/src/core/data_formats/parsing/ninja/texture.ts b/src/core/data_formats/parsing/ninja/texture.ts index d5bebe76..8db15057 100644 --- a/src/core/data_formats/parsing/ninja/texture.ts +++ b/src/core/data_formats/parsing/ninja/texture.ts @@ -1,6 +1,6 @@ import { Cursor } from "../../block/cursor/Cursor"; import { parse_iff, parse_iff_headers } from "../iff"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { Result, ResultBuilder } from "../../../Result"; import { Severity } from "../../../Severity"; diff --git a/src/core/data_formats/parsing/ninja/xj.ts b/src/core/data_formats/parsing/ninja/xj.ts index 874141f6..7ae9c3d0 100644 --- a/src/core/data_formats/parsing/ninja/xj.ts +++ b/src/core/data_formats/parsing/ninja/xj.ts @@ -1,6 +1,6 @@ import { Cursor } from "../../block/cursor/Cursor"; import { Vec2, Vec3 } from "../../vector"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; const logger = LogManager.get("core/data_formats/parsing/ninja/xj"); diff --git a/src/core/data_formats/parsing/prc.ts b/src/core/data_formats/parsing/prc.ts index 5974da48..b2b7f34c 100644 --- a/src/core/data_formats/parsing/prc.ts +++ b/src/core/data_formats/parsing/prc.ts @@ -1,7 +1,7 @@ import { prs_decompress } from "../compression/prs/decompress"; import { Cursor } from "../block/cursor/Cursor"; import { prc_decrypt } from "../encryption/prc"; -import { LogManager } from "../../Logger"; +import { LogManager } from "../../logging"; import { Result, ResultBuilder } from "../../Result"; import { Severity } from "../../Severity"; diff --git a/src/core/data_formats/parsing/quest/bin.test.ts b/src/core/data_formats/parsing/quest/bin.test.ts index 42278ca1..5840aa65 100644 --- a/src/core/data_formats/parsing/quest/bin.test.ts +++ b/src/core/data_formats/parsing/quest/bin.test.ts @@ -6,41 +6,40 @@ import { BufferCursor } from "../../block/cursor/BufferCursor"; import { parse_bin, write_bin } from "./bin"; import { BinFormat } from "./BinFormat"; import { unwrap } from "../../../Result"; +import { pw_test } from "../../../../../test/src/utils"; /** * Parse a file, convert the resulting structure to BIN again and check whether the end result is equal to the original. */ -function test_quest(path: string): void { - const orig_buffer = readFileSync(path); - const orig_bin = unwrap(prs_decompress(new BufferCursor(orig_buffer, Endianness.Little))); - const test_buffer = write_bin(parse_bin(orig_bin).bin, BinFormat.BB); - const test_bin = new ArrayBufferCursor(test_buffer, Endianness.Little); +function test_quest(path: string): () => void { + return pw_test({}, () => { + const orig_buffer = readFileSync(path); + const orig_bin = unwrap(prs_decompress(new BufferCursor(orig_buffer, Endianness.Little))); + const test_buffer = write_bin(parse_bin(orig_bin).bin, BinFormat.BB); + const test_bin = new ArrayBufferCursor(test_buffer, Endianness.Little); - orig_bin.seek_start(0); - expect(test_bin.size).toBe(orig_bin.size); + orig_bin.seek_start(0); + expect(test_bin.size).toBe(orig_bin.size); - let matching_bytes = 0; + let matching_bytes = 0; - while (orig_bin.bytes_left) { - const test_byte = test_bin.u8(); - const orig_byte = orig_bin.u8(); + while (orig_bin.bytes_left) { + const test_byte = test_bin.u8(); + const orig_byte = orig_bin.u8(); - if (test_byte !== orig_byte) { - throw new Error( - `Byte ${matching_bytes} didn't match, expected ${orig_byte}, got ${test_byte}.`, - ); + if (test_byte !== orig_byte) { + throw new Error( + `Byte ${matching_bytes} didn't match, expected ${orig_byte}, got ${test_byte}.`, + ); + } + + matching_bytes++; } - matching_bytes++; - } - - expect(matching_bytes).toBe(orig_bin.size); + expect(matching_bytes).toBe(orig_bin.size); + }); } -test("parse_bin and write_bin with quest118_e.bin", () => { - test_quest("test/resources/quest118_e.bin"); -}); +test("parse_bin and write_bin with quest118_e.bin", test_quest("test/resources/quest118_e.bin")); -test("parse_bin and write_bin with quest27_e.bin", () => { - test_quest("test/resources/quest27_e.bin"); -}); +test("parse_bin and write_bin with quest27_e.bin", test_quest("test/resources/quest27_e.bin")); diff --git a/src/core/data_formats/parsing/quest/bin.ts b/src/core/data_formats/parsing/quest/bin.ts index 75766d08..2ebfed47 100644 --- a/src/core/data_formats/parsing/quest/bin.ts +++ b/src/core/data_formats/parsing/quest/bin.ts @@ -1,6 +1,6 @@ import { Endianness } from "../../block/Endianness"; import { Cursor } from "../../block/cursor/Cursor"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { ArrayBufferCursor } from "../../block/cursor/ArrayBufferCursor"; import { assert } from "../../../util"; import { BinFormat } from "./BinFormat"; diff --git a/src/core/data_formats/parsing/quest/dat.test.ts b/src/core/data_formats/parsing/quest/dat.test.ts index 3f932c57..bb330770 100644 --- a/src/core/data_formats/parsing/quest/dat.test.ts +++ b/src/core/data_formats/parsing/quest/dat.test.ts @@ -5,66 +5,73 @@ import { ResizableBlockCursor } from "../../block/cursor/ResizableBlockCursor"; import { parse_dat, write_dat } from "./dat"; import { readFileSync } from "fs"; import { unwrap } from "../../../Result"; +import { pw_test } from "../../../../../test/src/utils"; /** * Parse a file, convert the resulting structure to DAT again and check whether the end result is equal to the original. */ -test("parse_dat and write_dat", () => { - const orig_buffer = readFileSync("test/resources/quest118_e.dat"); - const orig_dat = unwrap(prs_decompress(new BufferCursor(orig_buffer, Endianness.Little))); - const test_dat = new ResizableBlockCursor(write_dat(parse_dat(orig_dat))); - orig_dat.seek_start(0); +test( + "parse_dat and write_dat", + pw_test({}, () => { + const orig_buffer = readFileSync("test/resources/quest118_e.dat"); + const orig_dat = unwrap(prs_decompress(new BufferCursor(orig_buffer, Endianness.Little))); + const test_dat = new ResizableBlockCursor(write_dat(parse_dat(orig_dat))); + orig_dat.seek_start(0); - expect(test_dat.size).toBe(orig_dat.size); + expect(test_dat.size).toBe(orig_dat.size); - let match = true; + let match = true; - while (orig_dat.bytes_left) { - if (test_dat.u8() !== orig_dat.u8()) { - match = false; - break; + while (orig_dat.bytes_left) { + if (test_dat.u8() !== orig_dat.u8()) { + match = false; + break; + } } - } - expect(match).toBe(true); -}); + expect(match).toBe(true); + }), +); /** * Parse a file, modify the resulting structure, convert it to DAT again and check whether the end result is equal to the original except for the bytes that should be changed. */ -test("parse, modify and write DAT", () => { - const orig_buffer = readFileSync("./test/resources/quest118_e.dat"); - const orig_dat = unwrap(prs_decompress(new BufferCursor(orig_buffer, Endianness.Little))); - const test_parsed = parse_dat(orig_dat); - orig_dat.seek_start(0); +test( + "parse, modify and write DAT", + pw_test({}, () => { + const orig_buffer = readFileSync("./test/resources/quest118_e.dat"); + const orig_dat = unwrap(prs_decompress(new BufferCursor(orig_buffer, Endianness.Little))); + const test_parsed = parse_dat(orig_dat); + orig_dat.seek_start(0); - const test_obj_array = new Float32Array(test_parsed.objs[9].data); - test_obj_array[4] = 13; - test_obj_array[5] = 17; - test_obj_array[6] = 19; + const test_obj_array = new Float32Array(test_parsed.objs[9].data); + test_obj_array[4] = 13; + test_obj_array[5] = 17; + test_obj_array[6] = 19; - const test_dat = new ResizableBlockCursor(write_dat(test_parsed)); + const test_dat = new ResizableBlockCursor(write_dat(test_parsed)); - expect(test_dat.size).toBe(orig_dat.size); + expect(test_dat.size).toBe(orig_dat.size); - while (orig_dat.bytes_left) { - if (orig_dat.position === 16 + 9 * 68 + 16) { - orig_dat.seek(12); + while (orig_dat.bytes_left) { + if (orig_dat.position === 16 + 9 * 68 + 16) { + orig_dat.seek(12); - expect(test_dat.f32()).toBe(13); - expect(test_dat.f32()).toBe(17); - expect(test_dat.f32()).toBe(19); - } else { - const test_byte = test_dat.u8(); - const orig_byte = orig_dat.u8(); + expect(test_dat.f32()).toBe(13); + expect(test_dat.f32()).toBe(17); + expect(test_dat.f32()).toBe(19); + } else { + const test_byte = test_dat.u8(); + const orig_byte = orig_dat.u8(); - if (test_byte !== orig_byte) { - throw new Error( - `Byte ${ - test_dat.position - 1 - } didn't match, expected ${orig_byte}, got ${test_byte}.`, - ); + if (test_byte !== orig_byte) { + throw new Error( + `Byte ${ + test_dat.position - 1 + } didn't match, expected ${orig_byte}, got ${test_byte}.`, + ); + } } } - } -}); + }), +); diff --git a/src/core/data_formats/parsing/quest/dat.ts b/src/core/data_formats/parsing/quest/dat.ts index 76cd89e4..965dbcd9 100644 --- a/src/core/data_formats/parsing/quest/dat.ts +++ b/src/core/data_formats/parsing/quest/dat.ts @@ -5,7 +5,7 @@ import { ResizableBlockCursor } from "../../block/cursor/ResizableBlockCursor"; import { ResizableBlock } from "../../block/ResizableBlock"; import { WritableCursor } from "../../block/cursor/WritableCursor"; import { assert } from "../../../util"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { ArrayBufferCursor } from "../../block/cursor/ArrayBufferCursor"; const logger = LogManager.get("core/data_formats/parsing/quest/dat"); diff --git a/src/core/data_formats/parsing/quest/index.test.ts b/src/core/data_formats/parsing/quest/index.test.ts index b8f886f4..9d3b21c6 100644 --- a/src/core/data_formats/parsing/quest/index.test.ts +++ b/src/core/data_formats/parsing/quest/index.test.ts @@ -1,6 +1,6 @@ import { readFileSync } from "fs"; import { Endianness } from "../../block/Endianness"; -import { walk_qst_files } from "../../../../../test/src/utils"; +import { pw_test, walk_qst_files } from "../../../../../test/src/utils"; import { ArrayBufferCursor } from "../../block/cursor/ArrayBufferCursor"; import { BufferCursor } from "../../block/cursor/BufferCursor"; import { parse_qst_to_quest, write_quest_qst } from "./index"; @@ -14,37 +14,41 @@ import { import { get_object_position, get_object_section_id, get_object_type } from "./QuestObject"; import { get_npc_position, get_npc_section_id, get_npc_type } from "./QuestNpc"; import { unwrap } from "../../../Result"; +import { Severity } from "../../../Severity"; -test("parse Towards the Future", () => { - const buffer = readFileSync("test/resources/quest118_e.qst"); - const cursor = new BufferCursor(buffer, Endianness.Little); - const { quest } = unwrap(parse_qst_to_quest(cursor)); +test( + "parse Towards the Future", + pw_test({ max_log_severity: Severity.Warning }, () => { + const buffer = readFileSync("test/resources/quest118_e.qst"); + const cursor = new BufferCursor(buffer, Endianness.Little); + const { quest } = unwrap(parse_qst_to_quest(cursor)); - expect(quest.name).toBe("Towards the Future"); - expect(quest.short_description).toBe("Challenge the\nnew simulator."); - expect(quest.long_description).toBe( - "Client: Principal\nQuest: Wishes to have\nhunters challenge the\nnew simulator\nReward: ??? Meseta", - ); - expect(quest.episode).toBe(1); - expect(quest.objects.length).toBe(277); - expect(get_object_type(quest.objects[0])).toBe(ObjectType.MenuActivation); - expect(get_object_type(quest.objects[4])).toBe(ObjectType.PlayerSet); - expect(quest.npcs.length).toBe(216); - expect(quest.map_designations).toEqual( - new Map([ - [0, 0], - [2, 0], - [11, 0], - [5, 4], - [12, 0], - [7, 4], - [13, 0], - [8, 4], - [10, 4], - [14, 0], - ]), - ); -}); + expect(quest.name).toBe("Towards the Future"); + expect(quest.short_description).toBe("Challenge the\nnew simulator."); + expect(quest.long_description).toBe( + "Client: Principal\nQuest: Wishes to have\nhunters challenge the\nnew simulator\nReward: ??? Meseta", + ); + expect(quest.episode).toBe(1); + expect(quest.objects.length).toBe(277); + expect(get_object_type(quest.objects[0])).toBe(ObjectType.MenuActivation); + expect(get_object_type(quest.objects[4])).toBe(ObjectType.PlayerSet); + expect(quest.npcs.length).toBe(216); + expect(quest.map_designations).toEqual( + new Map([ + [0, 0], + [2, 0], + [11, 0], + [5, 4], + [12, 0], + [7, 4], + [13, 0], + [8, 4], + [10, 4], + [14, 0], + ]), + ); + }), +); /** * Round-trip tests. @@ -73,76 +77,79 @@ round_trip_test( ); function round_trip_test(path: string, file_name: string, contents: Buffer): void { - test(`parse_quest and write_quest_qst ${path}`, () => { - const { quest: orig_quest, version, online } = unwrap( - parse_qst_to_quest(new BufferCursor(contents, Endianness.Little)), - ); - const test_qst = write_quest_qst(orig_quest, file_name, version, online); - const { quest: test_quest } = unwrap( - parse_qst_to_quest(new ArrayBufferCursor(test_qst, Endianness.Little)), - ); + test( + `parse_quest and write_quest_qst ${path}`, + pw_test({ max_log_severity: Severity.Warning }, () => { + const { quest: orig_quest, version, online } = unwrap( + parse_qst_to_quest(new BufferCursor(contents, Endianness.Little)), + ); + const test_qst = write_quest_qst(orig_quest, file_name, version, online); + const { quest: test_quest } = unwrap( + parse_qst_to_quest(new ArrayBufferCursor(test_qst, Endianness.Little)), + ); - expect(test_quest.name).toBe(orig_quest.name); - expect(test_quest.short_description).toBe(orig_quest.short_description); - expect(test_quest.long_description).toBe(orig_quest.long_description); - expect(test_quest.episode).toBe(orig_quest.episode); - expect(test_quest.objects.length).toBe(orig_quest.objects.length); + expect(test_quest.name).toBe(orig_quest.name); + expect(test_quest.short_description).toBe(orig_quest.short_description); + expect(test_quest.long_description).toBe(orig_quest.long_description); + expect(test_quest.episode).toBe(orig_quest.episode); + expect(test_quest.objects.length).toBe(orig_quest.objects.length); - for (let i = 0; i < orig_quest.objects.length; i++) { - const orig_obj = orig_quest.objects[i]; - const test_obj = test_quest.objects[i]; - expect(test_obj.area_id).toBe(orig_obj.area_id); - expect(get_object_section_id(test_obj)).toBe(get_object_section_id(orig_obj)); - expect(get_object_position(test_obj)).toEqual(get_object_position(orig_obj)); - expect(get_object_type(test_obj)).toBe(get_object_type(orig_obj)); - } - - expect(test_quest.npcs.length).toBe(orig_quest.npcs.length); - - for (let i = 0; i < orig_quest.npcs.length; i++) { - const orig_npc = orig_quest.npcs[i]; - const test_npc = test_quest.npcs[i]; - expect(test_npc.area_id).toBe(orig_npc.area_id); - expect(get_npc_section_id(test_npc)).toBe(get_npc_section_id(orig_npc)); - expect(get_npc_position(test_npc)).toEqual(get_npc_position(orig_npc)); - expect(get_npc_type(test_npc)).toBe(get_npc_type(orig_npc)); - } - - expect(test_quest.map_designations).toEqual(orig_quest.map_designations); - - expect(test_quest.object_code.length).toBe(orig_quest.object_code.length); - - for (let i = 0; i < orig_quest.object_code.length; i++) { - const orig_segment = orig_quest.object_code[i]; - const test_segment = test_quest.object_code[i]; - - expect(test_segment.type).toBe(orig_segment.type); - expect(test_segment.labels).toEqual(orig_segment.labels); - - switch (orig_segment.type) { - case SegmentType.Instructions: - expect((test_segment as InstructionSegment).instructions.length).toBe( - orig_segment.instructions.length, - ); - - for (let j = 0; j < orig_segment.instructions.length; j++) { - const orig_inst = orig_segment.instructions[j]; - const test_inst = (test_segment as InstructionSegment).instructions[j]; - - expect(test_inst.opcode.code).toBe(orig_inst.opcode.code); - expect(test_inst.args).toEqual(orig_inst.args); - } - - break; - case SegmentType.Data: - expect((test_segment as DataSegment).data).toEqual(orig_segment.data); - break; - case SegmentType.String: - expect((test_segment as StringSegment).value).toBe(orig_segment.value); - break; + for (let i = 0; i < orig_quest.objects.length; i++) { + const orig_obj = orig_quest.objects[i]; + const test_obj = test_quest.objects[i]; + expect(test_obj.area_id).toBe(orig_obj.area_id); + expect(get_object_section_id(test_obj)).toBe(get_object_section_id(orig_obj)); + expect(get_object_position(test_obj)).toEqual(get_object_position(orig_obj)); + expect(get_object_type(test_obj)).toBe(get_object_type(orig_obj)); } - expect(test_quest.object_code[i]).toEqual(orig_quest.object_code[i]); - } - }); + expect(test_quest.npcs.length).toBe(orig_quest.npcs.length); + + for (let i = 0; i < orig_quest.npcs.length; i++) { + const orig_npc = orig_quest.npcs[i]; + const test_npc = test_quest.npcs[i]; + expect(test_npc.area_id).toBe(orig_npc.area_id); + expect(get_npc_section_id(test_npc)).toBe(get_npc_section_id(orig_npc)); + expect(get_npc_position(test_npc)).toEqual(get_npc_position(orig_npc)); + expect(get_npc_type(test_npc)).toBe(get_npc_type(orig_npc)); + } + + expect(test_quest.map_designations).toEqual(orig_quest.map_designations); + + expect(test_quest.object_code.length).toBe(orig_quest.object_code.length); + + for (let i = 0; i < orig_quest.object_code.length; i++) { + const orig_segment = orig_quest.object_code[i]; + const test_segment = test_quest.object_code[i]; + + expect(test_segment.type).toBe(orig_segment.type); + expect(test_segment.labels).toEqual(orig_segment.labels); + + switch (orig_segment.type) { + case SegmentType.Instructions: + expect((test_segment as InstructionSegment).instructions.length).toBe( + orig_segment.instructions.length, + ); + + for (let j = 0; j < orig_segment.instructions.length; j++) { + const orig_inst = orig_segment.instructions[j]; + const test_inst = (test_segment as InstructionSegment).instructions[j]; + + expect(test_inst.opcode.code).toBe(orig_inst.opcode.code); + expect(test_inst.args).toEqual(orig_inst.args); + } + + break; + case SegmentType.Data: + expect((test_segment as DataSegment).data).toEqual(orig_segment.data); + break; + case SegmentType.String: + expect((test_segment as StringSegment).value).toBe(orig_segment.value); + break; + } + + expect(test_quest.object_code[i]).toEqual(orig_quest.object_code[i]); + } + }), + ); } diff --git a/src/core/data_formats/parsing/quest/index.ts b/src/core/data_formats/parsing/quest/index.ts index 4bf0e334..3c5e3161 100644 --- a/src/core/data_formats/parsing/quest/index.ts +++ b/src/core/data_formats/parsing/quest/index.ts @@ -11,7 +11,7 @@ import { DatEntity, parse_dat, write_dat } from "./dat"; import { Quest, QuestEntity } from "./Quest"; import { Episode } from "./Episode"; import { parse_qst, QstContainedFile, write_qst } from "./qst"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { parse_object_code, write_object_code } from "./object_code"; import { get_map_designations } from "../../asm/data_flow_analysis/get_map_designations"; import { basename } from "../../../util"; diff --git a/src/core/data_formats/parsing/quest/object_code.ts b/src/core/data_formats/parsing/quest/object_code.ts index 2489baf3..0af2a71e 100644 --- a/src/core/data_formats/parsing/quest/object_code.ts +++ b/src/core/data_formats/parsing/quest/object_code.ts @@ -17,7 +17,7 @@ import { get_register_value } from "../../asm/data_flow_analysis/get_register_va import { get_stack_value } from "../../asm/data_flow_analysis/get_stack_value"; import { ArrayBufferCursor } from "../../block/cursor/ArrayBufferCursor"; import { Endianness } from "../../block/Endianness"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { ResizableBlockCursor } from "../../block/cursor/ResizableBlockCursor"; import { ResizableBlock } from "../../block/ResizableBlock"; import { BinFormat } from "./BinFormat"; diff --git a/src/core/data_formats/parsing/quest/qst.ts b/src/core/data_formats/parsing/quest/qst.ts index b3084ead..80a56770 100644 --- a/src/core/data_formats/parsing/quest/qst.ts +++ b/src/core/data_formats/parsing/quest/qst.ts @@ -5,7 +5,7 @@ import { ResizableBlockCursor } from "../../block/cursor/ResizableBlockCursor"; import { WritableCursor } from "../../block/cursor/WritableCursor"; import { ResizableBlock } from "../../block/ResizableBlock"; import { assert, basename, defined } from "../../../util"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; import { Version } from "./Version"; import { Result, ResultBuilder } from "../../../Result"; import { Severity } from "../../../Severity"; diff --git a/src/core/data_formats/parsing/rlc.ts b/src/core/data_formats/parsing/rlc.ts index 98ef60d9..27000702 100644 --- a/src/core/data_formats/parsing/rlc.ts +++ b/src/core/data_formats/parsing/rlc.ts @@ -1,7 +1,7 @@ import { Endianness } from "../block/Endianness"; import { Cursor } from "../block/cursor/Cursor"; import { parse_prc } from "./prc"; -import { LogManager } from "../../Logger"; +import { LogManager } from "../../logging"; import { Result, ResultBuilder } from "../../Result"; import { Severity } from "../../Severity"; diff --git a/src/core/gui/Table.ts b/src/core/gui/Table.ts index 6519fe31..e2d6f21c 100644 --- a/src/core/gui/Table.ts +++ b/src/core/gui/Table.ts @@ -4,7 +4,7 @@ import { ListProperty } from "../observable/property/list/ListProperty"; import { Disposer } from "../observable/Disposer"; import "./Table.css"; import { Disposable } from "../observable/Disposable"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; const logger = LogManager.get("core/gui/Table"); diff --git a/src/core/gui/Widget.ts b/src/core/gui/Widget.ts index f58e77c3..fbffc0b1 100644 --- a/src/core/gui/Widget.ts +++ b/src/core/gui/Widget.ts @@ -3,7 +3,7 @@ import { Disposer } from "../observable/Disposer"; import { WritableProperty } from "../observable/property/WritableProperty"; import { WidgetProperty } from "../observable/property/WidgetProperty"; import { Property } from "../observable/property/Property"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; const logger = LogManager.get("core/gui/Widget"); diff --git a/src/core/gui/dom.ts b/src/core/gui/dom.ts index a8abe62b..d070cde9 100644 --- a/src/core/gui/dom.ts +++ b/src/core/gui/dom.ts @@ -9,7 +9,7 @@ import { ListProperty, } from "../observable/property/list/ListProperty"; import { Disposer } from "../observable/Disposer"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; const logger = LogManager.get("core/gui/dom"); diff --git a/src/core/Logger.ts b/src/core/logging.ts similarity index 80% rename from src/core/Logger.ts rename to src/core/logging.ts index 71413ffa..63062041 100644 --- a/src/core/Logger.ts +++ b/src/core/logging.ts @@ -1,11 +1,11 @@ import { Severity, severity_from_string } from "./Severity"; -import { basename } from "./util"; +import { basename, try_finally } from "./util"; export type LogEntry = { readonly time: Date; readonly message: string; readonly severity: Severity; - readonly logger: Logger; + readonly logger: Logging; readonly cause?: any; }; @@ -35,6 +35,7 @@ function default_log_handler({ time, message, severity, logger, cause }: LogEntr break; default: method = console.log; + break; } if (cause == undefined) { @@ -57,7 +58,7 @@ function time_part_to_string(value: number, n: number): string { return value.toString().padStart(n, "0"); } -export class Logger { +export class Logging { private _severity?: Severity; get severity(): Severity { @@ -108,42 +109,42 @@ export class Logger { } export class LogManager { - private static readonly loggers = new Map(); + private static readonly loggers = new Map(); static default_severity: Severity = severity_from_string(process.env["LOG_LEVEL"] ?? "Info"); static default_handler: LogHandler = default_log_handler; - static get(name: string): Logger { + static get(name: string): Logging { name = basename(name); let logger = this.loggers.get(name); if (!logger) { - logger = new Logger(name); + logger = new Logging(name); this.loggers.set(name, logger); } return logger; } - static with_default_handler(handler: LogHandler, f: () => T): T { + static with_defaults( + defaults: { severity?: Severity; handler?: LogHandler }, + f: () => T, + ): T { + const orig_severity = this.default_severity; const orig_handler = this.default_handler; - let is_promise = false; - try { - this.default_handler = handler; - const r = f(); - - if (r instanceof Promise) { - is_promise = true; - return (r.finally(() => (this.default_handler = orig_handler)) as unknown) as T; - } else { - return r; - } - } finally { - if (!is_promise) { - this.default_handler = orig_handler; - } + if (defaults.severity != undefined) { + this.default_severity = defaults.severity; } + + if (defaults.handler != undefined) { + this.default_handler = defaults.handler; + } + + return try_finally(f, () => { + this.default_severity = orig_severity; + this.default_handler = orig_handler; + }); } } diff --git a/src/core/observable/Disposer.ts b/src/core/observable/Disposer.ts index 07bb09d4..ab0df352 100644 --- a/src/core/observable/Disposer.ts +++ b/src/core/observable/Disposer.ts @@ -1,5 +1,5 @@ import { Disposable } from "./Disposable"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; import { array_remove } from "../util"; const logger = LogManager.get("core/observable/Disposer"); diff --git a/src/core/observable/SimpleEmitter.ts b/src/core/observable/SimpleEmitter.ts index 532a53f7..1547427b 100644 --- a/src/core/observable/SimpleEmitter.ts +++ b/src/core/observable/SimpleEmitter.ts @@ -1,7 +1,7 @@ import { Disposable } from "./Disposable"; import { Emitter } from "./Emitter"; import { ChangeEvent } from "./Observable"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; const logger = LogManager.get("core/observable/SimpleEmitter"); diff --git a/src/core/observable/property/AbstractMinimalProperty.ts b/src/core/observable/property/AbstractMinimalProperty.ts index deff0a32..c2e599c7 100644 --- a/src/core/observable/property/AbstractMinimalProperty.ts +++ b/src/core/observable/property/AbstractMinimalProperty.ts @@ -1,6 +1,6 @@ import { Disposable } from "../Disposable"; import { Property } from "./Property"; -import { LogManager } from "../../Logger"; +import { LogManager } from "../../logging"; import { ChangeEvent } from "../Observable"; const logger = LogManager.get("core/observable/property/AbstractMinimalProperty"); diff --git a/src/core/observable/property/FlatMappedProperty.test.ts b/src/core/observable/property/FlatMappedProperty.test.ts index dbab8c6a..ae5f1db3 100644 --- a/src/core/observable/property/FlatMappedProperty.test.ts +++ b/src/core/observable/property/FlatMappedProperty.test.ts @@ -1,26 +1,26 @@ import { FlatMappedProperty } from "./FlatMappedProperty"; import { SimpleProperty } from "./SimpleProperty"; -import { with_disposable } from "../../../../test/src/core/observables/disposable_helpers"; +import { pw_test } from "../../../../test/src/utils"; // This is a regression test, it's important that this exact sequence of statements stays the same. -test(`It should emit a change when its direct property dependency changes.`, () => { - // p is the direct property dependency. - const p = new SimpleProperty(new SimpleProperty(7)); - const fp = new FlatMappedProperty([p], () => p.val); - let v: number | undefined; +test( + `It should emit a change when its direct property dependency changes.`, + pw_test({}, disposer => { + // p is the direct property dependency. + const p = new SimpleProperty(new SimpleProperty(7)); + const fp = new FlatMappedProperty([p], () => p.val); + let v: number | undefined = undefined; - with_disposable( - fp.observe(({ value }) => (v = value)), - () => { - expect(v).toBeUndefined(); + disposer.add(fp.observe(({ value }) => (v = value))); - p.val.val = 99; + expect(v).toBeUndefined(); - expect(v).toBe(99); + p.val.val = 99; - p.val = new SimpleProperty(7); + expect(v).toBe(99); - expect(v).toBe(7); - }, - ); -}); + p.val = new SimpleProperty(7); + + expect(v).toBe(7); + }), +); diff --git a/src/core/observable/property/list/AbstractListProperty.ts b/src/core/observable/property/list/AbstractListProperty.ts index 621f396b..b3f8b77d 100644 --- a/src/core/observable/property/list/AbstractListProperty.ts +++ b/src/core/observable/property/list/AbstractListProperty.ts @@ -3,7 +3,7 @@ import { AbstractProperty } from "../AbstractProperty"; import { Disposable } from "../../Disposable"; import { Observable } from "../../Observable"; import { Property } from "../Property"; -import { LogManager } from "../../../Logger"; +import { LogManager } from "../../../logging"; const logger = LogManager.get("core/observable/property/list/AbstractListProperty"); diff --git a/src/core/persistence/Persister.ts b/src/core/persistence/Persister.ts index c00186bf..f2790002 100644 --- a/src/core/persistence/Persister.ts +++ b/src/core/persistence/Persister.ts @@ -1,5 +1,5 @@ import { Server } from "../model"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; const logger = LogManager.get("core/persistence/Persister"); diff --git a/src/core/stores/Store.ts b/src/core/stores/Store.ts index bea9eff8..d67e5721 100644 --- a/src/core/stores/Store.ts +++ b/src/core/stores/Store.ts @@ -4,6 +4,10 @@ import { Disposer } from "../observable/Disposer"; export abstract class Store implements Disposable { private readonly disposer = new Disposer(); + protected get disposed(): boolean { + return this.disposer.disposed; + } + dispose(): void { this.disposer.dispose(); } diff --git a/src/core/undo/UndoStack.ts b/src/core/undo/UndoStack.ts index f08019f2..6de42524 100644 --- a/src/core/undo/UndoStack.ts +++ b/src/core/undo/UndoStack.ts @@ -3,7 +3,7 @@ import { WritableListProperty } from "../observable/property/list/WritableListPr import { Action } from "./Action"; import { list_property, map, property } from "../observable"; import { undo_manager } from "./UndoManager"; -import { LogManager } from "../Logger"; +import { LogManager } from "../logging"; const logger = LogManager.get("core/undo/UndoStack"); diff --git a/src/core/util.ts b/src/core/util.ts index c78d3b18..baa4c31b 100644 --- a/src/core/util.ts +++ b/src/core/util.ts @@ -138,6 +138,40 @@ export function browser_supports_webassembly(): boolean { return typeof window === "object" && typeof window.WebAssembly === "object"; } -export function is_promise(value: unknown): value is Promise { - return value && typeof value === "object" && "then" in value && "finally" in value; +/** + * @returns true iff the given value implements PromiseLike. + */ +export function is_promise_like(value?: T | PromiseLike): value is PromiseLike { + return value != undefined && typeof (value as any).then === "function"; +} + +/** + * @returns true iff the given value implements Promise. + */ +export function is_promise(value?: T | Promise): value is Promise { + return ( + value != undefined && + typeof (value as any).then === "function" && + typeof (value as any).catch === "function" && + typeof (value as any).finally === "function" + ); +} + +export function try_finally(f: () => T, after: () => void): T { + let return_promise = false; + + try { + const r = f(); + + if (is_promise(r)) { + return_promise = true; + return (r.finally(() => after()) as unknown) as T; + } else { + return r; + } + } finally { + if (!return_promise) { + after(); + } + } } diff --git a/src/hunt_optimizer/gui/MethodsForEpisodeView.ts b/src/hunt_optimizer/gui/MethodsForEpisodeView.ts index b7596682..3d572af2 100644 --- a/src/hunt_optimizer/gui/MethodsForEpisodeView.ts +++ b/src/hunt_optimizer/gui/MethodsForEpisodeView.ts @@ -13,7 +13,7 @@ import { SortDirection, Table } from "../../core/gui/Table"; import { list_property } from "../../core/observable"; import { ServerMap } from "../../core/stores/ServerMap"; import { HuntMethodStore } from "../stores/HuntMethodStore"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; import { div } from "../../core/gui/dom"; import { ResizableView } from "../../core/gui/ResizableView"; diff --git a/src/hunt_optimizer/gui/OptimizationResultView.ts b/src/hunt_optimizer/gui/OptimizationResultView.ts index d281097a..9d9f1e1c 100644 --- a/src/hunt_optimizer/gui/OptimizationResultView.ts +++ b/src/hunt_optimizer/gui/OptimizationResultView.ts @@ -9,7 +9,7 @@ import "./OptimizationResultView.css"; import { Duration } from "luxon"; import { ServerMap } from "../../core/stores/ServerMap"; import { HuntOptimizerStore } from "../stores/HuntOptimizerStore"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; import { View } from "../../core/gui/View"; const logger = LogManager.get("hunt_optimizer/gui/OptimizationResultView"); diff --git a/src/hunt_optimizer/gui/WantedItemsView.ts b/src/hunt_optimizer/gui/WantedItemsView.ts index 8c8c9a2a..3c38a54c 100644 --- a/src/hunt_optimizer/gui/WantedItemsView.ts +++ b/src/hunt_optimizer/gui/WantedItemsView.ts @@ -10,7 +10,7 @@ import { ItemType } from "../../core/model/items"; import { Disposable } from "../../core/observable/Disposable"; import { ServerMap } from "../../core/stores/ServerMap"; import { HuntOptimizerStore } from "../stores/HuntOptimizerStore"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; import { View } from "../../core/gui/View"; const logger = LogManager.get("hunt_optimizer/gui/WantedItemsView"); diff --git a/src/hunt_optimizer/stores/HuntMethodStore.ts b/src/hunt_optimizer/stores/HuntMethodStore.ts index 7e37b223..52016266 100644 --- a/src/hunt_optimizer/stores/HuntMethodStore.ts +++ b/src/hunt_optimizer/stores/HuntMethodStore.ts @@ -11,7 +11,7 @@ import { GuiStore } from "../../core/stores/GuiStore"; import { HttpClient } from "../../core/HttpClient"; import { Store } from "../../core/stores/Store"; import { DisposableServerMap } from "../../core/stores/DisposableServerMap"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; const logger = LogManager.get("hunt_optimizer/stores/HuntMethodStore"); diff --git a/src/hunt_optimizer/stores/ItemDropStore.ts b/src/hunt_optimizer/stores/ItemDropStore.ts index 1b195025..c10effb4 100644 --- a/src/hunt_optimizer/stores/ItemDropStore.ts +++ b/src/hunt_optimizer/stores/ItemDropStore.ts @@ -8,7 +8,7 @@ import { ItemTypeStore } from "../../core/stores/ItemTypeStore"; import { HttpClient } from "../../core/HttpClient"; import { DisposableServerMap } from "../../core/stores/DisposableServerMap"; import { Store } from "../../core/stores/Store"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; const logger = LogManager.get("stores/ItemDropStore"); diff --git a/src/quest_editor/QuestRunner.ts b/src/quest_editor/QuestRunner.ts index b7d1f4f9..2ec58cfc 100644 --- a/src/quest_editor/QuestRunner.ts +++ b/src/quest_editor/QuestRunner.ts @@ -14,7 +14,7 @@ import { QuestObjectModel } from "./model/QuestObjectModel"; import { AreaStore } from "./stores/AreaStore"; import { InstructionPointer } from "./scripting/vm/InstructionPointer"; import { clone_segment } from "../core/data_formats/asm/instructions"; -import { Logger } from "../core/Logger"; +import { Logging } from "../core/logging"; import { LogStore } from "./stores/LogStore"; import { Severity } from "../core/Severity"; @@ -56,7 +56,7 @@ export type GameState = Readonly; * delegates to {@link Debugger}. */ export class QuestRunner { - private logger: Logger; + private logger: Logging; private animation_frame?: number; private startup = true; private readonly _state: WritableProperty = property( diff --git a/src/quest_editor/controllers/DebugController.test.ts b/src/quest_editor/controllers/DebugController.test.ts index e03597d5..93c9f1eb 100644 --- a/src/quest_editor/controllers/DebugController.test.ts +++ b/src/quest_editor/controllers/DebugController.test.ts @@ -1,15 +1,15 @@ -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; import { GuiStore } from "../../core/stores/GuiStore"; import { create_area_store } from "../../../test/src/quest_editor/stores/store_creation"; import { QuestEditorStore } from "../stores/QuestEditorStore"; import { DebugController } from "./DebugController"; import { LogStore } from "../stores/LogStore"; -import { load_default_quest_model, next_animation_frame } from "../../../test/src/utils"; +import { load_default_quest_model, next_animation_frame, pw_test } from "../../../test/src/utils"; import { disassemble } from "../scripting/disassembly"; import { assemble } from "../scripting/assembly"; -test("Some widgets should only be enabled when a quest is loaded.", async () => - with_disposer(async disposer => { +test( + "Some widgets should only be enabled when a quest is loaded.", + pw_test({}, async disposer => { const gui_store = disposer.add(new GuiStore()); const area_store = create_area_store(disposer); const log_store = disposer.add(new LogStore()); @@ -25,10 +25,12 @@ test("Some widgets should only be enabled when a quest is loaded.", async () => expect(ctrl.can_debug.val).toBe(true); expect(ctrl.can_step.val).toBe(false); - })); + }), +); -test("Debugging controls should be enabled and disabled at the right times.", async () => - with_disposer(async disposer => { +test( + "Debugging controls should be enabled and disabled at the right times.", + pw_test({}, async disposer => { const gui_store = disposer.add(new GuiStore()); const area_store = create_area_store(disposer); const log_store = disposer.add(new LogStore()); @@ -74,4 +76,5 @@ test("Debugging controls should be enabled and disabled at the right times.", as expect(ctrl.can_step.val).toBe(true); expect(ctrl.can_stop.val).toBe(true); - })); + }), +); diff --git a/src/quest_editor/controllers/DebugController.ts b/src/quest_editor/controllers/DebugController.ts index e9e2268a..9d0e5fbb 100644 --- a/src/quest_editor/controllers/DebugController.ts +++ b/src/quest_editor/controllers/DebugController.ts @@ -3,7 +3,7 @@ import { Property } from "../../core/observable/property/Property"; import { ListProperty } from "../../core/observable/property/list/ListProperty"; import { QuestEditorStore } from "../stores/QuestEditorStore"; import { GuiStore, GuiTool } from "../../core/stores/GuiStore"; -import { LogEntry } from "../../core/Logger"; +import { LogEntry } from "../../core/logging"; import { LogStore } from "../stores/LogStore"; import { Severity } from "../../core/Severity"; import { map } from "../../core/observable"; diff --git a/src/quest_editor/controllers/EntityInfoController.test.ts b/src/quest_editor/controllers/EntityInfoController.test.ts index 8c9db79f..d1ba55cc 100644 --- a/src/quest_editor/controllers/EntityInfoController.test.ts +++ b/src/quest_editor/controllers/EntityInfoController.test.ts @@ -3,14 +3,14 @@ import { create_area_store, create_quest_editor_store, } from "../../../test/src/quest_editor/stores/store_creation"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; import { Vector3 } from "three"; import { euler } from "../model/euler"; import { deg_to_rad } from "../../core/math"; -import { load_default_quest_model } from "../../../test/src/utils"; +import { load_default_quest_model, pw_test } from "../../../test/src/utils"; -test("When input values change, this should be reflected in the selected entity.", () => - with_disposer(disposer => { +test( + "When input values change, this should be reflected in the selected entity.", + pw_test({}, disposer => { const area_store = create_area_store(disposer); const store = create_quest_editor_store(disposer, area_store); const ctrl = new EntityInfoController(store); @@ -45,4 +45,5 @@ test("When input values change, this should be reflected in the selected entity. expect(entity.rotation.val.x).toBeCloseTo(deg_to_rad(180), 5); expect(entity.rotation.val.y).toBeCloseTo(deg_to_rad(45), 5); expect(entity.rotation.val.z).toBeCloseTo(deg_to_rad(223.83), 5); - })); + }), +); diff --git a/src/quest_editor/controllers/QuestEditorToolBarController.test.ts b/src/quest_editor/controllers/QuestEditorToolBarController.test.ts index 93737cd3..877fb44c 100644 --- a/src/quest_editor/controllers/QuestEditorToolBarController.test.ts +++ b/src/quest_editor/controllers/QuestEditorToolBarController.test.ts @@ -5,12 +5,13 @@ import { } from "../../../test/src/quest_editor/stores/store_creation"; import { QuestEditorToolBarController } from "./QuestEditorToolBarController"; import { Episode } from "../../core/data_formats/parsing/quest/Episode"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; import { QuestLoader } from "../loading/QuestLoader"; import { FileSystemHttpClient } from "../../../test/src/core/FileSystemHttpClient"; +import { pw_test } from "../../../test/src/utils"; -test("Some widgets should only be enabled when a quest is loaded.", async () => - with_disposer(async disposer => { +test( + "Some widgets should only be enabled when a quest is loaded.", + pw_test({}, async disposer => { const quest_loader = disposer.add(new QuestLoader(new FileSystemHttpClient())); const gui_store = disposer.add(new GuiStore()); const area_store = create_area_store(disposer); @@ -31,4 +32,5 @@ test("Some widgets should only be enabled when a quest is loaded.", async () => expect(ctrl.can_save.val).toBe(true); expect(ctrl.can_select_area.val).toBe(true); - })); + }), +); diff --git a/src/quest_editor/controllers/QuestEditorToolBarController.ts b/src/quest_editor/controllers/QuestEditorToolBarController.ts index a4b6333d..35135605 100644 --- a/src/quest_editor/controllers/QuestEditorToolBarController.ts +++ b/src/quest_editor/controllers/QuestEditorToolBarController.ts @@ -16,7 +16,7 @@ import { import { ArrayBufferCursor } from "../../core/data_formats/block/cursor/ArrayBufferCursor"; import { Endianness } from "../../core/data_formats/block/Endianness"; import { convert_quest_from_model, convert_quest_to_model } from "../stores/model_conversion"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; import { basename } from "../../core/util"; import { Version } from "../../core/data_formats/parsing/quest/Version"; import { WritableProperty } from "../../core/observable/property/WritableProperty"; diff --git a/src/quest_editor/controllers/QuestInfoController.test.ts b/src/quest_editor/controllers/QuestInfoController.test.ts index c9917dc2..51f924a0 100644 --- a/src/quest_editor/controllers/QuestInfoController.test.ts +++ b/src/quest_editor/controllers/QuestInfoController.test.ts @@ -3,11 +3,11 @@ import { create_quest_editor_store, } from "../../../test/src/quest_editor/stores/store_creation"; import { QuestInfoController } from "./QuestInfoController"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; -import { load_default_quest_model } from "../../../test/src/utils"; +import { load_default_quest_model, pw_test } from "../../../test/src/utils"; -test("When a property's input value changes, this should be reflected in the current quest object and the undo stack.", async () => - with_disposer(async disposer => { +test( + "When a property's input value changes, this should be reflected in the current quest object and the undo stack.", + pw_test({}, async disposer => { const area_store = create_area_store(disposer); const store = create_quest_editor_store(disposer, area_store); const ctrl = disposer.add(new QuestInfoController(store)); @@ -39,4 +39,5 @@ test("When a property's input value changes, this should be reflected in the cur expect(store.current_quest.val!.long_description.val).toBe( "Created with phantasmal.world.", ); - })); + }), +); diff --git a/src/quest_editor/gui/DebugView.ts b/src/quest_editor/gui/DebugView.ts index cdc8c06d..bb5e91a1 100644 --- a/src/quest_editor/gui/DebugView.ts +++ b/src/quest_editor/gui/DebugView.ts @@ -2,7 +2,7 @@ import { bind_children_to, div, Icon } from "../../core/gui/dom"; import { ToolBar } from "../../core/gui/ToolBar"; import "./DebugView.css"; import { Select } from "../../core/gui/Select"; -import { LogEntry, time_to_string } from "../../core/Logger"; +import { LogEntry, time_to_string } from "../../core/logging"; import { ResizableView } from "../../core/gui/ResizableView"; import { Severities, Severity } from "../../core/Severity"; import { Button } from "../../core/gui/Button"; diff --git a/src/quest_editor/gui/EntityInfoView.test.ts b/src/quest_editor/gui/EntityInfoView.test.ts index 4130c1a6..ae61a187 100644 --- a/src/quest_editor/gui/EntityInfoView.test.ts +++ b/src/quest_editor/gui/EntityInfoView.test.ts @@ -4,12 +4,12 @@ import { create_area_store, create_quest_editor_store, } from "../../../test/src/quest_editor/stores/store_creation"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; import { undo_manager } from "../../core/undo/UndoManager"; -import { load_default_quest_model } from "../../../test/src/utils"; +import { load_default_quest_model, pw_test } from "../../../test/src/utils"; -test("Renders correctly without an entity selected.", () => { - with_disposer(disposer => { +test( + "Renders correctly without an entity selected.", + pw_test({}, disposer => { const area_store = create_area_store(disposer); const store = create_quest_editor_store(disposer, area_store); const view = disposer.add( @@ -21,11 +21,12 @@ test("Renders correctly without an entity selected.", () => { store.set_current_quest(load_default_quest_model(area_store)); expect(view.element).toMatchSnapshot('should render a "No entity selected." view'); - }); -}); + }), +); -test("Renders correctly with an entity selected.", () => { - with_disposer(disposer => { +test( + "Renders correctly with an entity selected.", + pw_test({}, disposer => { const area_store = create_area_store(disposer); const store = create_quest_editor_store(disposer, area_store); const view = disposer.add( @@ -37,11 +38,12 @@ test("Renders correctly with an entity selected.", () => { store.set_selected_entity(quest.npcs.get(0)); expect(view.element).toMatchSnapshot("should render a table of editable properties"); - }); -}); + }), +); -test("When the view's element is focused the quest editor store's undo stack should become the current stack.", () => { - with_disposer(disposer => { +test( + "When the view's element is focused the quest editor store's undo stack should become the current stack.", + pw_test({}, disposer => { const store = create_quest_editor_store(disposer); const view = disposer.add( new EntityInfoView(disposer.add(new EntityInfoController(store))), @@ -55,5 +57,5 @@ test("When the view's element is focused the quest editor store's undo stack sho view.element.focus(); expect(undo_manager.current.val).toBe(store.undo); - }); -}); + }), +); diff --git a/src/quest_editor/gui/EventSubGraphView.ts b/src/quest_editor/gui/EventSubGraphView.ts index ad2b5a88..9b583e41 100644 --- a/src/quest_editor/gui/EventSubGraphView.ts +++ b/src/quest_editor/gui/EventSubGraphView.ts @@ -12,7 +12,7 @@ import { ListProperty, } from "../../core/observable/property/list/ListProperty"; import { WritableProperty } from "../../core/observable/property/WritableProperty"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; import { View } from "../../core/gui/View"; const logger = LogManager.get("quest_editor/gui/EventSubGraphView"); diff --git a/src/quest_editor/gui/NpcCountsView.test.ts b/src/quest_editor/gui/NpcCountsView.test.ts index a343695f..e58454d0 100644 --- a/src/quest_editor/gui/NpcCountsView.test.ts +++ b/src/quest_editor/gui/NpcCountsView.test.ts @@ -4,19 +4,21 @@ import { create_area_store, create_quest_editor_store, } from "../../../test/src/quest_editor/stores/store_creation"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; -import { load_default_quest_model } from "../../../test/src/utils"; +import { load_default_quest_model, pw_test } from "../../../test/src/utils"; -test("Renders correctly without a current quest.", () => - with_disposer(disposer => { +test( + "Renders correctly without a current quest.", + pw_test({}, disposer => { const store = create_quest_editor_store(disposer); const view = disposer.add(new NpcCountsView(disposer.add(new NpcCountsController(store)))); expect(view.element).toMatchSnapshot('Should render a "No quest loaded." view.'); - })); + }), +); -test("Renders correctly with a current quest.", () => - with_disposer(disposer => { +test( + "Renders correctly with a current quest.", + pw_test({}, disposer => { const area_store = create_area_store(disposer); const store = create_quest_editor_store(disposer, area_store); const view = disposer.add(new NpcCountsView(disposer.add(new NpcCountsController(store)))); @@ -24,4 +26,5 @@ test("Renders correctly with a current quest.", () => store.set_current_quest(load_default_quest_model(area_store)); expect(view.element).toMatchSnapshot("Should render a table with NPC names and counts."); - })); + }), +); diff --git a/src/quest_editor/gui/QuestEditorToolBarView.test.ts b/src/quest_editor/gui/QuestEditorToolBarView.test.ts index 2725c309..4727aec9 100644 --- a/src/quest_editor/gui/QuestEditorToolBarView.test.ts +++ b/src/quest_editor/gui/QuestEditorToolBarView.test.ts @@ -3,13 +3,14 @@ import { QuestEditorToolBarView } from "./QuestEditorToolBarView"; import { GuiStore } from "../../core/stores/GuiStore"; import { create_area_store } from "../../../test/src/quest_editor/stores/store_creation"; import { QuestEditorStore } from "../stores/QuestEditorStore"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; import { LogStore } from "../stores/LogStore"; import { QuestLoader } from "../loading/QuestLoader"; import { StubHttpClient } from "../../core/HttpClient"; +import { pw_test } from "../../../test/src/utils"; -test("Renders correctly.", () => - with_disposer(disposer => { +test( + "Renders correctly.", + pw_test({}, disposer => { const quest_loader = disposer.add(new QuestLoader(new StubHttpClient())); const gui_store = disposer.add(new GuiStore()); const area_store = create_area_store(disposer); @@ -31,4 +32,5 @@ test("Renders correctly.", () => ); expect(tool_bar.element).toMatchSnapshot(); - })); + }), +); diff --git a/src/quest_editor/gui/QuestEditorView.ts b/src/quest_editor/gui/QuestEditorView.ts index b28bffbd..4441a9ba 100644 --- a/src/quest_editor/gui/QuestEditorView.ts +++ b/src/quest_editor/gui/QuestEditorView.ts @@ -16,7 +16,7 @@ import { DebugView } from "./DebugView"; import { QuestRunnerRendererView } from "./QuestRunnerRendererView"; import { QuestEditorStore } from "../stores/QuestEditorStore"; import { QuestEditorUiPersister } from "../persistence/QuestEditorUiPersister"; -import { LogManager } from "../../core/Logger"; +import { LogManager } from "../../core/logging"; import { ErrorWidget } from "../../core/gui/ErrorWidget"; import { div } from "../../core/gui/dom"; import { ResizableView } from "../../core/gui/ResizableView"; diff --git a/src/quest_editor/gui/QuestInfoView.test.ts b/src/quest_editor/gui/QuestInfoView.test.ts index ecf4dc37..20d4aaea 100644 --- a/src/quest_editor/gui/QuestInfoView.test.ts +++ b/src/quest_editor/gui/QuestInfoView.test.ts @@ -5,11 +5,11 @@ import { create_area_store, create_quest_editor_store, } from "../../../test/src/quest_editor/stores/store_creation"; -import { with_disposer } from "../../../test/src/core/observables/disposable_helpers"; -import { load_default_quest_model } from "../../../test/src/utils"; +import { load_default_quest_model, pw_test } from "../../../test/src/utils"; -test("Renders correctly without a current quest.", () => - with_disposer(disposer => { +test( + "Renders correctly without a current quest.", + pw_test({}, disposer => { const view = disposer.add( new QuestInfoView( disposer.add(new QuestInfoController(create_quest_editor_store(disposer))), @@ -17,10 +17,12 @@ test("Renders correctly without a current quest.", () => ); expect(view.element).toMatchSnapshot('should render a "No quest loaded." view'); - })); + }), +); -test("Renders correctly with a current quest.", () => - with_disposer(async disposer => { +test( + "Renders correctly with a current quest.", + pw_test({}, async disposer => { const area_store = create_area_store(disposer); const store = create_quest_editor_store(disposer); const view = disposer.add(new QuestInfoView(disposer.add(new QuestInfoController(store)))); @@ -28,10 +30,12 @@ test("Renders correctly with a current quest.", () => await store.set_current_quest(load_default_quest_model(area_store)); expect(view.element).toMatchSnapshot("should render property inputs"); - })); + }), +); -test("When the view's element is focused the quest editor store's undo stack should become the current stack.", () => - with_disposer(disposer => { +test( + "When the view's element is focused the quest editor store's undo stack should become the current stack.", + pw_test({}, disposer => { const store = create_quest_editor_store(disposer); const view = disposer.add(new QuestInfoView(disposer.add(new QuestInfoController(store)))); @@ -43,4 +47,5 @@ test("When the view's element is focused the quest editor store's undo stack sho view.element.focus(); expect(undo_manager.current.val).toBe(store.undo); - })); + }), +); diff --git a/src/quest_editor/gui/__snapshots__/QuestInfoView.test.ts.snap b/src/quest_editor/gui/__snapshots__/QuestInfoView.test.ts.snap index 9bd37603..89d7eb3c 100644 --- a/src/quest_editor/gui/__snapshots__/QuestInfoView.test.ts.snap +++ b/src/quest_editor/gui/__snapshots__/QuestInfoView.test.ts.snap @@ -1,114 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Renders correctly with a current quest.: should render property inputs 1`] = ` -
- - - - - - - - - - - - - - - - - -
- Episode: - - I -
- ID: - - - - -
- Name: - - - - -
- Short description: -
-
-