Skip to content

test: describe('Logout') blocks reuse logged-out agent, invalidating cookie for subsequent tests #3472

@PierreBrisorgueil

Description

@PierreBrisorgueil

Symptom

In full-suite runs, tests immediately after a describe('Logout') block fail with socket hang up or 401s. Example from downstream (trawl_node):

```
historys.integration.tests.js:199
describe('Logout')
should be able to get historys stats → socket hang up
```

Running the file alone passes; the failure only surfaces when a prior inner `describe` exercised logout paths.

Root cause

The shared `agent` instance holds a cookie scoped to a user who gets invalidated inside the inner `describe('Logout')` — typically via `afterAll(() => UserService.remove(user))`. The next outer `describe` reuses the same `agent` but the cookie now points to a deleted/logged-out user.

Scope

Pattern identified in 3 devkit/Node test files (source of truth) that propagate to 6+ downstream files via `/update-all-projects`:

  • Identify the 3 devkit source files
  • Document the correct pattern: either `afterEach(() => logoutAgent())` + re-signin, OR nest Logout in its own top-level `describe` with dedicated agent
  • Fix devkit, propagate to downstream

Repro

```bash

From any downstream project (trawl_node, comes_node, etc.)

NODE_ENV=trawl npm run test:unit -- --runInBand --testPathPattern=historys.integration

Passes in isolation

NODE_ENV=trawl npm run test:unit -- --runInBand

Fails: historys.integration.tests.js:199

```

Priority

P2 — not failing CI (fresh Mongo container per run masks it), but causes noise in local full-suite runs and makes debugging downstream harder. Fix propagates via devkit update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions