From d3796d433b6d3a161b7492fdb196f5d3d9ec24e2 Mon Sep 17 00:00:00 2001 From: Ahmed Hritani Date: Mon, 13 Nov 2023 12:35:21 +0100 Subject: [PATCH 1/7] Update contributing docs to save people's time --- CONTRIBUTING.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ede358b2..4c1db66d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,5 +4,10 @@ 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. +When it comes to adding examples to README, please follow the constraints below: +- The example should work. It should be possible to write a real unit-test that passes with the example, +- Each line less than 70 characters wide. This is a special optimization for the README so the examples fit inside most laptop screens without scrollbars, +- The example should be slightly interesting, if possible, and should use a unicode emoji + [0]: https://github.com/iambumblehead/esmock/tree/master/tests From 2667f5427c32ac211ae36298ad9d7aefa8efada8 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 13 Nov 2023 11:03:35 -0800 Subject: [PATCH 2/7] apply eslint to all files, to include markdown --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f658930f..ea30c4ba 100644 --- a/package.json +++ b/package.json @@ -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", From bb44660e26999a69e76736096f234c05b07e3f2f Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 13 Nov 2023 11:39:34 -0800 Subject: [PATCH 3/7] update README to work with markdown lint plugin --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8e865cf..dac22832 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ _**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 @@ -22,7 +22,7 @@ await esmock( ``` `esmock` examples -``` javascript +```js import test from 'node:test' import assert from 'node:assert' import esmock from 'esmock' From 8bb1a689a2d81af757f9632a0b63b4e135cd4e10 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 13 Nov 2023 11:47:14 -0800 Subject: [PATCH 4/7] update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 907740a4..b2659491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # changelog + * 2.6.1 _???.??.2023_ + * [update README to work w/ eslint-plugin-markdown](https://github.com/iambumblehead/esmock/pull/275) * 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_ From 02c3650eefdcd7d7fe793bfdeb86d155df71af76 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 13 Nov 2023 12:34:26 -0800 Subject: [PATCH 5/7] update eslint disallow trailing whitespace --- .eslintrc.json | 1 + src/esmock.d.ts | 2 +- src/esmockModule.js | 2 +- tests/local/pnp/enable.js | 2 +- tests/tests-node/esmock.node.resolver-pnp.test.js | 2 +- tests/tests-node/esmock.node.test.js | 4 ++-- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 0985a7db..d8dd0558 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,7 @@ "Set": true }, "rules": { + "no-trailing-spaces": [2], "no-unused-vars": [ "error", { "vars": "all", "args": "after-used", diff --git a/src/esmock.d.ts b/src/esmock.d.ts index 6e17319b..e8e35b01 100644 --- a/src/esmock.d.ts +++ b/src/esmock.d.ts @@ -93,5 +93,5 @@ export { type MockFunction, type MockMap, type Options, - type Resolver + type Resolver } diff --git a/src/esmockModule.js b/src/esmockModule.js index 214b0afd..31ade8f1 100644 --- a/src/esmockModule.js +++ b/src/esmockModule.js @@ -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 \'#\'' -// +// // if not plain obj, assign enumerable vals only. core modules === plain obj const esmockModuleMerge = (defLive, def) => isPlainObj(defLive) ? Object.assign({}, defLive, def) diff --git a/tests/local/pnp/enable.js b/tests/local/pnp/enable.js index bbbbd680..0da6644a 100644 --- a/tests/local/pnp/enable.js +++ b/tests/local/pnp/enable.js @@ -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)) diff --git a/tests/tests-node/esmock.node.resolver-pnp.test.js b/tests/tests-node/esmock.node.resolver-pnp.test.js index 02825ce2..ffac726b 100644 --- a/tests/tests-node/esmock.node.resolver-pnp.test.js +++ b/tests/tests-node/esmock.node.resolver-pnp.test.js @@ -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', { diff --git a/tests/tests-node/esmock.node.test.js b/tests/tests-node/esmock.node.test.js index 8b02f1fc..60952c1b 100644 --- a/tests/tests-node/esmock.node.test.js +++ b/tests/tests-node/esmock.node.test.js @@ -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') @@ -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') From 3b7a6097c6addd70ab515c49b232980b9aa17aea Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 13 Nov 2023 12:35:44 -0800 Subject: [PATCH 6/7] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2659491..7034e6fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * 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_ From 2abde45ebc2d4da883a02a37875dfbbf11b1ae02 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 13 Nov 2023 12:47:52 -0800 Subject: [PATCH 7/7] update CONTRIBUTING.md --- CONTRIBUTING.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c1db66d..cd5818ff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,10 +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. -When it comes to adding examples to README, please follow the constraints below: -- The example should work. It should be possible to write a real unit-test that passes with the example, -- Each line less than 70 characters wide. This is a special optimization for the README so the examples fit inside most laptop screens without scrollbars, -- The example should be slightly interesting, if possible, and should use a unicode emoji +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