Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement listReplacedModules
  • Loading branch information
giltayar committed Oct 20, 2023
1 parent 7d0010a commit 4a40ce8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,7 +44,7 @@
"test": "run-s test:unit test:safe test:esm test:no-loader-esm test:example",
"test:unit": "teenytest --helper test/helper.js \"test/unit/**/*.test.{js,ts}\"",
"test:safe": "teenytest --helper test/helper.js \"test/safe/**/*.test.{js,ts}\"",
"test:esm": "cross-env NODE_OPTIONS=\"--loader=quibble\" TS_NODE_IGNORE=\"node_modules,notypescript\" ./test/safe-esm/teenytest-proxy.js --helper test/helper.js test/safe-esm/replace.test.js",
"test:esm": "cross-env NODE_OPTIONS=\"--loader=quibble\" TS_NODE_IGNORE=\"node_modules,notypescript\" ./test/safe-esm/teenytest-proxy.js --helper test/helper.js test/safe-esm/replace.test.js test/safe-esm/list.test.js",
"test:esm-auto-loader": "node test/esm-lib/supports-auto-load.js not || TS_NODE_IGNORE=\"node_modules,notypescript\" ./test/safe-esm/teenytest-proxy.js --helper test/helper.js test/safe-esm/replace.test.js",
"test:no-loader-esm": "node test/esm-lib/supports-auto-load.js || 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!\"",
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Expand Up @@ -7,6 +7,7 @@ import when from './when'
import verify from './verify'
import matchers from './matchers'
import replace, { replaceEsm } from './replace'
import listReplacedModules from './list'
import explain from './explain'
import reset from './reset'
import config from './config'
Expand All @@ -26,6 +27,7 @@ module.exports = {
matchers,
replace,
replaceEsm,
listReplacedModules,
explain,
reset,
config,
Expand Down
5 changes: 5 additions & 0 deletions src/list.js
@@ -0,0 +1,5 @@
import { listMockedModules } from 'quibble'

export default function listReplacedModules () {
return listMockedModules()
}
28 changes: 28 additions & 0 deletions test/safe-esm/list.test.js
@@ -0,0 +1,28 @@
const { pathToFileURL } = require('url')
const quibble = require('quibble')

module.exports = {
async 'listing mocked modules' () {
assert._isEqual(td.listReplacedModules(), [])

await td.replaceEsm('./fixtures/honk.mjs')

assert._isEqual(td.listReplacedModules(), [
pathToFileURL(quibble.absolutify('./fixtures/honk.mjs', __filename)).href
])

await td.replaceEsm('./fixtures/turn.mjs')

assert._isEqual(td.listReplacedModules(), [
pathToFileURL(quibble.absolutify('./fixtures/honk.mjs', __filename)).href,
pathToFileURL(quibble.absolutify('./fixtures/turn.mjs', __filename)).href
])
},
async 'listing replaced modules after a reset' () {
await td.replaceEsm('./fixtures/honk.mjs')

td.reset()

assert._isEqual(td.listReplacedModules(), [])
}
}
28 changes: 28 additions & 0 deletions test/safe/list.test.js
@@ -0,0 +1,28 @@
const { pathToFileURL } = require('url')
const quibble = require('quibble')

module.exports = {
'listing mocked modules' () {
assert._isEqual(td.listReplacedModules(), [])

td.replace('./fixtures/honk')

assert._isEqual(td.listReplacedModules(), [
pathToFileURL(quibble.absolutify('./fixtures/honk.js', __filename)).href
])

td.replace('./fixtures/turn')

assert._isEqual(td.listReplacedModules(), [
pathToFileURL(quibble.absolutify('./fixtures/honk.js', __filename)).href,
pathToFileURL(quibble.absolutify('./fixtures/turn.js', __filename)).href
])
},
'listing replaced modules after a reset' () {
td.replace('./fixtures/honk')

td.reset()

assert._isEqual(td.listReplacedModules(), [])
}
}
2 changes: 2 additions & 0 deletions test/unit/index.test.js
Expand Up @@ -7,6 +7,7 @@ module.exports = () => {
const constructor = td.replace('../../src/constructor').default
const instance = td.replace('../../src/instance').default
const { default: replace, replaceEsm } = td.replace('../../src/replace')
const listReplacedModules = td.replace('../../src/list').default
const imitate = td.replace('../../src/imitate').default
// Stubbing & Verifying
const when = td.replace('../../src/when').default
Expand All @@ -30,6 +31,7 @@ module.exports = () => {
instance,
replace,
replaceEsm,
listReplacedModules,
imitate,
when,
verify,
Expand Down

0 comments on commit 4a40ce8

Please sign in to comment.