Share the beforeEach and afterEach bodies of the Duo chat MSW specs

Why

Every MSW integration spec that renders Duo Agentic Chat needs the same setup and the same teardown. That is a consequence of the websocket seam introduced in !248777 (merged): the transport is faked by swapping global.WebSocket, and stream_manager keeps its worker, subscribers and message buffer in module state that outlives the component, so both have to be undone by hand.

Two specs on master carry that boilerplate today. The five MRs that follow in this chain add nine more, so it is worth naming before it multiplies.

What this changes

test_setup.js gains the two hook bodies:

Helper Replaces
setupDuoChatTest() installWebSocketMock() + clearPanelStorage()
teardownDuoChatTest() terminate() + restoreWebSocket() + clearPanelStorage()

glql_spec.js and hydrate_thread_spec.js use them. Assertions are untouched — the diff is hooks and imports only.

Each spec still calls both from its own beforeEach / afterEach. Nothing registers hooks on a spec's behalf, so terminate() — the call that releases real resources — stays visible at the point it happens. Specs that also need GraphQL handlers add installAgenticChatFlowHandlers() on the next line.

The wrapper variable goes away too. spec/frontend/__helpers__/shared_test_setup.js calls VTU's enableAutoDestroy(afterEach), so wrappers are unmounted for us, and neither spec used its wrapper for anything but mounting and destroying. That is also what the @gitlab/vtu-no-explicit-wrapper-destroy rule asks for.

One oddity worth flagging: afterEach takes an arrow (afterEach(() => teardownDuoChatTest())) rather than the bare reference, because that eslint rule crashes on afterEach(fn) — it reads node.arguments[0].body unconditionally, which is undefined for an identifier. Worth an upstream fix in @gitlab/eslint-plugin, out of scope here.

The MR chain

# MR Status
1 !248777 (merged) — MSW foundations Merged
2 This MR — share the chat specs' hooks Targets master
3 !248782 (merged) — AI panel shell Targets this branch
4 !248783 (merged) — conversation lifecycle Targets 3
5 !248785 (merged) — tool calls Targets 4
6 !248787 (merged) — agent and model selection Targets 5
7 !248791 (merged) — additional context Targets 6
8 !244590 (merged) — remove the Capybara specs Merges last

Test plan

yarn jest:msw-integration ee/spec/frontend/msw_integration/duo_agentic_chat
VUE_VERSION=3 yarn jest:msw-integration ee/spec/frontend/msw_integration/duo_agentic_chat

6 tests across 3 suites, green on both.

Part of #603605 (closed)

Merge request reports

Loading
Loading