testdouble / testdouble/testdouble.js

`replaceEsm` breaks usage of mongo db

Open
#488 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.4k
Forks
140
Avg merge
22h
Merged PRs (30d)
1

Description

Description

Using replaceEsm breaks usage of Mongo in the files under test

Issue

See repo for details. I have a module, A with a dependency on another module, B. Module A queries Mongo DB. When testing module A, I call replaceEsm('path/to/B') and this causes all queries to Mongo in module A to return nothing. However, I also have another module C which also queries Mongo. If I make calls to module C from the tests of module A, the mongo queries work as expected.

It seems there might be an issue with replaceEsm + imports in beforeEach + mongo db.

Environment
  • node -v output: v17.6.0
  • npm -v (or yarn --version) output: 8.5.1
  • npm ls testdouble (or yarn list testdouble) version:
    example@ /Users/paymahn/code/tripvector/example
    └── testdouble@3.16.5
Example Repo

Here's a minimal repo: https://github.com/paymog/testdouble-example

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 the linked minimal repository and reproduce the interaction between replaceEsm, imports in beforeEach, and Mongo queries. Compare calls from module A with calls from module C, then confirm the fix by showing that module A's queries return results while its dependency is replaced.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
databases, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.