Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'main' into build-on-windows
  • Loading branch information
searls committed Feb 19, 2023
2 parents 903ae7f + 56d5b2b commit d5088b7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* eol=lf
25 changes: 25 additions & 0 deletions docs/7-replacing-dependencies.md
Expand Up @@ -351,6 +351,31 @@ path shouldn't exist yet, a second argument `manualReplacement` can be provided
to short-circuit any attempts to load and imitate a module at
`relativePathToModule`.

## td.replaceEsm() API

`td.replaceEsm` can only be used to replace ESM module compared to `td.replace`
which can either replace properties on object or replace a Nodejs module.

### td.replaceEsm(relativePathToModule)

Without any argument, `td.replaceEsm` will imitate the module with all exported
properties replaced with `td.function()`.

### td.replaceEsm(relativePathToModule, namedExportReplacements, defaultExportReplacement)

When you need to give replacement implementations, you can do it by giving
`namedExportReplacements` and `defaultExportReplacement` arguments.

`namedExportReplacements` is an object to be used to replace ESM named exports.
Each object properties will have its key matching the export name and value
must be the implementation to use.

`defaultExportReplacement` is used to replace the default export and can be
directly the implementation to use as default export.

See [quibble ESM API](https://github.com/testdouble/quibble#quibble-esm-api)
for more information and note about mocking internal Node.js modules.

***
Previous: [Verifying interactions](6-verifying-invocations.md#verifying-interactions)
Next: [Custom argument matchers](8-custom-matchers.md#custom-argument-matchers)
16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -48,14 +48,14 @@
"test:no-loader-esm": "cross-env TS_NODE_IGNORE=\"node_modules,notypescript\" teenytest test/helper.js './test/safe-esm/*.no-loader-test.{mjs,js}'",
"test:ci": "npm run compile && run-p style test && echo \"All done!\"",
"test:example": "run-s test:example:babel test:example:jest test:example:jest-broken test:example:node test:example:node-ava test:example:node-esm",
"test:example:babel": "./script/run-examples babel",
"test:example:jest": "./script/run-examples jest",
"test:example:jest-broken": "./script/run-examples jest-broken",
"test:example:plain-html": "./script/run-examples plain-html",
"test:example:node": "./script/run-examples node",
"test:example:node-ava": "./script/run-examples node-ava",
"test:example:node-esm": "./script/run-examples node-esm",
"test:example:webpack": "./script/run-examples webpack",
"test:example:babel": "bash ./script/run-examples babel",
"test:example:jest": "bash ./script/run-examples jest",
"test:example:jest-broken": "bash ./script/run-examples jest-broken",
"test:example:plain-html": "bash ./script/run-examples plain-html",
"test:example:node": "bash ./script/run-examples node",
"test:example:node-ava": "bash ./script/run-examples node-ava",
"test:example:node-esm": "bash ./script/run-examples node-esm",
"test:example:webpack": "bash ./script/run-examples webpack",
"version:write": "echo \"export default '$npm_package_version'\" > src/version.js",
"preversion": "git pull --rebase",
"version": "npm run version:write && npm run compile && git add src/version.js",
Expand Down
2 changes: 1 addition & 1 deletion test/safe-esm/teenytest-proxy.js
Expand Up @@ -6,4 +6,4 @@
//
// Once these bugs are solved, we can go back to running teenytest regularly for ESM tests

require('../../node_modules/.bin/teenytest')
require('../../node_modules/teenytest/bin/teenytest')

0 comments on commit d5088b7

Please sign in to comment.