paritytech / paritytech/polkadot-cli

mock.module in load-meta.test.ts leaks into other test files

Open
#287 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
10
Forks
2
Avg merge
12h 35m
Merged PRs (30d)
4

Description

Discovered while adding tests in #286.

`src/commands/load-meta.test.ts` installs `mock.module("../core/client.ts", …)` and `mock.module("../core/metadata.ts", …)`. Bun's module mocks are process-global and are never restored, so every test file that evaluates after it in the same run (alphabetically later, e.g. `tx-eth.test.ts`, `tx.test.ts`) silently gets the mocked `createChainClient` / `fetchMetadataFromChain` — i.e. the polkadot fixture metadata for any chain name, and no real network.

Observed effect: an in-process test connecting to previewnet failed deterministically in full-suite runs with "Chain "preview-asset-hub" does not expose pallet-revive" in ~15ms (fixture metadata served instead of a connection), while passing standalone. In #286 the affected test was converted to a subprocess `runCli` test to sidestep the leak (commit 8d7f574) — at the cost of coverage instrumentation.

Possible fixes: isolate load-meta tests behind dependency injection instead of `mock.module`, or run them in a dedicated process (bun `--preload` per-file isolation), or restore the real modules in `afterAll` by re-mocking with the captured originals. Until then: any in-process test that needs real chain connectivity must live in a file that sorts alphabetically before `load-meta.test.ts`, or run as a subprocess.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/commands/load-meta.test.ts and reproduce the full-suite ordering issue involving tx-eth.test.ts and tx.test.ts. Trace how Bun's mock.module calls persist between files, then verify that real chain connectivity is restored for later in-process tests without losing the intended load-meta coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, typescript
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.