Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ahmed-hritani/esmock into u…
Browse files Browse the repository at this point in the history
…pdate-docs
  • Loading branch information
ahmed-hritani committed Nov 14, 2023
2 parents d1ae7a0 + d40c0ca commit 233b6b6
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"Set": true
},
"rules": {
"no-trailing-spaces": [2],
"no-unused-vars": [ "error", {
"vars": "all",
"args": "after-used",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# changelog

* 2.6.1 _???.??.2023_
* [update README to work w/ eslint-plugin-markdown](https://github.com/iambumblehead/esmock/pull/275)
* [update eslint](https://github.com/iambumblehead/esmock/pull/276) disallow trailing whitespace
* 2.6.0 _Nov.07.2023_
* [typings: make MockFunction generic,](https://github.com/iambumblehead/esmock/pull/267) thanks @uwinkelvos
* 2.5.9 _Nov.01.2023_
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ If `esmock` is failing for you, feel free to submit a PR that reproduces the iss

Please do not submit PRs to convert esmock to typescript or add build scripts. Typescript and build scripts are fine, however, esmock's current setup is ideal for me now.

Collaborators may reject or revert any issue or PR for any reason.

[0]: https://github.com/iambumblehead/esmock/tree/master/tests

[0]: https://github.com/iambumblehead/esmock/tree/main/tests
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
_**Note: For versions of node prior to v20.6.0,** "--loader" command line arguments must be used with `esmock` as demonstrated [in the wiki.][4] Current versions of node do not require "--loader"._

`esmock` has the below signature
``` javascript
```js
await esmock(
'./to/module.js', // path to target module being tested
{ ...childmocks }, // mock definitions imported by target module
{ ...globalmocks }) // mock definitions imported everywhere
```

`esmock` examples

JavaScript
``` javascript
```js
import test from 'node:test'
import assert from 'node:assert'
import esmock from 'esmock'
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"test": "npm run test:all",
"test-ci": "npm run test:install && npm run test:all-ci",
"test-cover": "npm run test:install && c8 npm run test:all",
"lint": "eslint --ext=.js,.mjs .",
"lint-fix": "eslint --ext=.js,.mjs --fix .",
"lint": "eslint .",
"lint-fix": "eslint --fix .",
"mini:pkg": "npm pkg delete scripts devDependencies dependencies",
"mini:src": "cd src && npx rimraf \"!(esmock|esmockLoader).js\"",
"mini": "npm run mini:src && npm run mini:pkg",
Expand Down
2 changes: 1 addition & 1 deletion src/esmock.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ export {
type MockFunction,
type MockMap,
type Options,
type Resolver
type Resolver
}
2 changes: 1 addition & 1 deletion src/esmockModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const isJSONExtnRe = /\.json$/i

// assigning the object to its own prototypal inheritor can error, eg
// 'Cannot assign to read only property \'F_OK\' of object \'#<Object>\''
//
//
// if not plain obj, assign enumerable vals only. core modules === plain obj
const esmockModuleMerge = (defLive, def) => isPlainObj(defLive)
? Object.assign({}, defLive, def)
Expand Down
2 changes: 1 addition & 1 deletion tests/local/pnp/enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function resolve (specifier, context, next) {
? '../tests/local/pnp/api.js'
: specifier, context)
}

module.register && (process.versions.pnp = '3') && module.register(`
data:text/javascript,
export ${encodeURIComponent(resolve)}`.slice(1))
2 changes: 1 addition & 1 deletion tests/tests-node/esmock.node.resolver-pnp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test.beforeEach(() => {
test('should work with pnp resolver', async ({ mock }) => {
if (!module.register)
return assert.ok('skip test')

pnpapi.resolveRequest = mock.fn(resolver)

const main = await esmock('../local/main.js', {
Expand Down
4 changes: 2 additions & 2 deletions tests/tests-node/esmock.node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ test('should mock imported json', async () => {

if (/^(18|20)$/.test(process.versions.node.split('.')[0]))
return assert.ok(true)

assert.strictEqual(
Object.keys(importsJSON.JSONobj).sort().join(), 'example,test-example')
assert.strictEqual(importsJSON.JSONobj['test-example'], 'test-json-a')
Expand All @@ -576,7 +576,7 @@ test('should mock imported json (strict)', async () => {

if (/^(18|20)$/.test(process.versions.node.split('.')[0]))
return assert.ok(true)

assert.strictEqual(
Object.keys(importsJSON.JSONobj).sort().join(), 'test-example')
assert.strictEqual(importsJSON.JSONobj['test-example'], 'test-json-b')
Expand Down

0 comments on commit 233b6b6

Please sign in to comment.