Skip to content

Add "list replaced modules" #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ replaces all functions it encounters with fake test double functions which can,
in turn, be configured by your test to either stub responses or assert
invocations.

Additionally, if you're using Node 16 or newer, you can replace native ES modules with `td.replaceEsm()`. More details
For ES modules, you should use `td.replaceEsm()`. More details
[here](docs/7-replacing-dependencies.md#how-module-replacement-works-for-es-modules-using-import).

#### Module replacement with Node.js
Expand Down Expand Up @@ -568,6 +568,36 @@ completeness—a test will verify an invocation that already satisfied a stubbin
but this is almost [provably
unnecessary](/docs/B-frequently-asked-questions.md#why-shouldnt-i-call-both-tdwhen-and-tdverify-for-a-single-interaction-with-a-test-double).

### `td.listReplacedModules()` for listing the modules that were replaced

**`td.listReplacedModules()`**


Use `td.listReplacedModules()` to list the modules that are replaced. This function will return an array of the modules that are
currently being replaced via `td.replace()` or `td.replaceEsm()`.

The list is in no particular order, and returns the full path to the module that was replaced.
The path is returned as a `file:` URL as is customary in ESM (this is true even if the
replaced module was CJS).

For example, if you do this:

```js
td.replace('../src/save')
```

Then

```js
td.listReplacedModules()
```

will return something like:

```js
['file:///users/example/code/foo/src/save.js']
```

### Other functions

For other top-level features in the testdouble.js API, consult the [docs](/docs)
Expand Down
26 changes: 13 additions & 13 deletions examples/babel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions examples/jest-broken/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions examples/jest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions examples/node-ava/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions examples/node-esm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading