Skip to content
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

added failing test #197

Merged
merged 4 commits into from
Apr 4, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changelog

* 2.2.1 _Apr.03.2023_
* [use Object.defineProperty](https://github.com/iambumblehead/esmock/pull/197) to write mock definitions protected on inherited prototype chain
* 2.2.0 _Mar.23.2023_
* [throw error when](https://github.com/iambumblehead/esmock/pull/193) esmock.strictest is called with empty mock definition, @koshic @Swivelgames
* [update jest and jest-light-runner packages](https://github.com/iambumblehead/esmock/pull/194) at unit-tests, @koshic
* 2.1.0 _Nov.29.2022_
* [add node v19](https://github.com/iambumblehead/esmock/pull/189) to ci-test pipeline
* [use live default export](https://github.com/iambumblehead/esmock/pull/189) to populate enumerable properties of mock definition
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "esmock",
"type": "module",
"version": "2.2.0",
"version": "2.2.1",
"license": "ISC",
"readmeFilename": "README.md",
"description": "provides native ESM import mocking for unit tests",
Expand Down
5 changes: 4 additions & 1 deletion src/esmockModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const isPlainObj = o => Object.getPrototypeOf(o) === objProto
const esmockModuleMerge = (defLive, def) => isPlainObj(defLive)
? Object.assign({}, defLive, def)
: Object.assign(Object.keys(defLive).reduce(
(prev, k) => (prev[k] = defLive[k], prev), Object.create(defLive)), def)
(prev, k) => (Object.defineProperty(prev, k, {
value: defLive[k],
writable: true
}), prev), Object.create(defLive)), def)

const esmockModuleMergeDefault = (defLive, def) =>
(isObj(defLive) && isObj(def)) ? esmockModuleMerge(defLive, def) : def
Expand Down
3 changes: 3 additions & 0 deletions tests/local/usesNodeProcess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import nodeprocess from 'node:process'

export default nodeprocess
9 changes: 9 additions & 0 deletions tests/tests-node/esmock.node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import esmock from 'esmock'
import sinon from 'sinon'
import esmockCache from '../../src/esmockCache.js'

test('should mock node:process', async () => {
// has direct and in-direct calls to `process.cwd()`
const thingBeingTested = await esmock('../local/usesNodeProcess.js', {}, {
'node:process': { cwd: () => 'tempDir' }
})

assert.strictEqual(thingBeingTested.cwd(), 'tempDir')
})

test('should mock package, even when package is not installed', async () => {
const component = await esmock(`../local/notinstalledVueComponent.js`, {
vue: {
Expand Down