Comparing version 0.8.0 to 0.9.0
@@ -15,3 +15,3 @@ { | ||
"..": { | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"dev": true, | ||
@@ -18,0 +18,0 @@ "license": "MIT", |
@@ -15,3 +15,3 @@ { | ||
"..": { | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"dev": true, | ||
@@ -18,0 +18,0 @@ "license": "MIT", |
@@ -122,2 +122,9 @@ const Module = require('module') | ||
quibble.listMockedModules = function () { | ||
const esmMockedModules = quibbleUserToLoaderCommunication()?.listMockedModules() ?? [] | ||
const cjsMockedModules = Object.keys(quibbles).map((modulePath) => pathToFileURL(modulePath).href) | ||
return esmMockedModules.concat(cjsMockedModules) | ||
} | ||
quibble.isLoaderLoaded = function () { | ||
@@ -124,0 +131,0 @@ return !!quibbleUserToLoaderCommunication() |
@@ -19,3 +19,3 @@ exports.thisWillRunInUserThread = (globalThis, port) => { | ||
}, | ||
async addMockedModule ( | ||
addMockedModule ( | ||
moduleUrl, | ||
@@ -49,2 +49,25 @@ { namedExportStubs, defaultExportStub } | ||
} | ||
}, | ||
listMockedModules () { | ||
if (!loaderAndUserRunInSameThread(globalThis)) { | ||
const hasListMockedModulesHappened = new Int32Array(new SharedArrayBuffer(4)) | ||
const mockedModulesListLength = new Int32Array(new SharedArrayBuffer(4)) | ||
const mockedModulesList = new Uint8Array(new SharedArrayBuffer(20 * 1024 * 1024)) // 20MB should be sufficient | ||
port.postMessage({ | ||
type: 'listMockedModules', | ||
hasListMockedModulesHappened, | ||
mockedModulesListLength, | ||
mockedModulesList | ||
}) | ||
Atomics.wait(hasListMockedModulesHappened, 0, 0) | ||
if (mockedModulesListLength[0] > mockedModulesList.length) { | ||
throw new Error('Not enough buffer allocated for result') | ||
} | ||
const serializedMockedModules = new TextDecoder().decode(mockedModulesList.slice(0, mockedModulesListLength[0])) | ||
return serializedMockedModules ? serializedMockedModules.split(' ') : [] | ||
} else { | ||
const quibbleLoaderState = globalThis[Symbol.for('__quibbleLoaderState')] | ||
return Array.from(quibbleLoaderState.quibbledModules.keys()) | ||
} | ||
} | ||
@@ -51,0 +74,0 @@ } |
{ | ||
"name": "quibble", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Makes it easy to replace require'd dependencies.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/testdouble/quibble", |
const quibble = require('../../lib/quibble') | ||
const { pathToFileURL } = require('url') | ||
@@ -130,2 +131,20 @@ module.exports = { | ||
}, | ||
'list mocked modules': async function () { | ||
quibble('../fixtures/a-function', function () { return 'kek' }) | ||
assert.deepEqual(quibble.listMockedModules(), [ | ||
pathToFileURL(quibble.absolutify('../fixtures/a-function', __filename)).href | ||
]) | ||
quibble('../fixtures/b-function', function () { return 'kek' }) | ||
assert.deepEqual(quibble.listMockedModules(), [ | ||
pathToFileURL(quibble.absolutify('../fixtures/a-function', __filename)).href, | ||
pathToFileURL(quibble.absolutify('../fixtures/b-function', __filename)).href | ||
]) | ||
quibble.reset() | ||
assert.deepEqual(await quibble.listMockedModules(), []) | ||
}, | ||
afterEach: function () { | ||
@@ -132,0 +151,0 @@ quibble.reset() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
157058
3988
0