paritytech / paritytech/polkadot-cli
mock.module in load-meta.test.ts leaks into other test files
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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