From 0b24e1f960a549a64907a1bd0eade45647b3f0b7 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 11:40:00 -0700 Subject: [PATCH 01/19] use encodeURI rather than whitespace regexp --- src/esmockLoader.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/esmockLoader.mjs b/src/esmockLoader.mjs index ebd70039..1e81373d 100644 --- a/src/esmockLoader.mjs +++ b/src/esmockLoader.mjs @@ -69,9 +69,9 @@ const resolve = async (specifier, context, defaultResolve) => { return resolved; }; -const load = async (url, context, defaultGetSource) => { +const load = async (url, context, nextLoad) => { if (esmockModuleKeysRe.test(url)) // parent of mocked modules - return defaultGetSource(url, context, defaultGetSource); + return nextLoad(url, context, nextLoad); url = url.replace(esmockGlobalsAndAfterRe, ''); if (url.startsWith(urlDummy)) { @@ -84,7 +84,7 @@ const load = async (url, context, defaultGetSource) => { return { format : 'module', shortCircuit : true, - responseURL : url.replace(/\s+/g,'%20'), + responseURL : encodeURI(url), source : exportedNames.map(name => name === 'default' ? `export default global.esmockCacheGet("${url}").default` : `export const ${name} = global.esmockCacheGet("${url}").${name}` @@ -92,7 +92,7 @@ const load = async (url, context, defaultGetSource) => { }; } - return defaultGetSource(url, context, defaultGetSource); + return nextLoad(url, context, nextLoad); }; // node lt 16.12 require getSource, node gte 16.12 warn remove getSource From 5310dafdb84ac86a557106041fdd2cfdd2b2deaf Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:31:33 -0700 Subject: [PATCH 02/19] added node native test runner. update README to use native test runner --- README.md | 31 +-- package.json | 3 +- spec/node/esmock.node.noloader.test.js | 11 + spec/node/esmock.node.only.test.js | 15 ++ spec/node/esmock.node.test.js | 350 +++++++++++++++++++++++++ 5 files changed, 394 insertions(+), 16 deletions(-) create mode 100644 spec/node/esmock.node.noloader.test.js create mode 100644 spec/node/esmock.node.only.test.js create mode 100644 spec/node/esmock.node.test.js diff --git a/README.md b/README.md index 95895105..844736a7 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,13 @@ esmock -`esmock` must be used with node's experimental --loader +`esmock` must be used with node's --loader ``` json { "name": "give-esmock-a-star", "type": "module", "scripts": { + "test": "node --loader=esmock --test ./spec/", "test-uvu": "node --loader=esmock ./node_modules/uvu/bin.js ./spec/", "test-ava": "ava --node-arguments=\"--loader=esmock\"", "test-mocha": "mocha --loader=esmock --no-warnings" @@ -29,16 +30,16 @@ esmock await esmock( './to/module.js', // path to target module being tested { ...childmocks }, // mock definitions imported by target module - { ...globalmocks } // mock definitions imported everywhere -); + { ...globalmocks }) // mock definitions imported everywhere ``` -`esmock` demonstrated with `ava` unit test examples +`esmock` demonstrated with unit test examples ``` javascript -import test from 'ava'; +import test from 'node:test'; +import assert from 'node:assert/strict'; import esmock from 'esmock'; -test('should mock local files and packages', async t => { +test('should mock local files and packages', async () => { const main = await esmock('../src/main.js', { stringifierpackage : JSON.stringify, '../src/hello.js' : { @@ -47,38 +48,38 @@ test('should mock local files and packages', async t => { } }); - t.is(main(), JSON.stringify({ test : 'world foobar' })); + assert.strictEqual(main(), JSON.stringify({ test : 'world foobar' })); }); -test('should do global instance mocks —third param', async t => { +test('should do global instance mocks —third param', async () => { const { getFile } = await esmock('../src/main.js', {}, { fs : { readFileSync : () => 'returns this globally'; } }); - t.is(getFile(), 'returns this globally'); + assert.strictEqual(getFile(), 'returns this globally'); }); -test('should mock "await import()" using esmock.p', async t => { +test('should mock "await import()" using esmock.p', async () => { // using esmock.p, mock definitions are kept in cache const doAwaitImport = await esmock.p('../awaitImportLint.js', { eslint : { ESLint : cfg => cfg } }); // mock definition is there, in cache, when import is called - t.is(await doAwaitImport('cfg'), 'cfg'); + assert.strictEqual(await doAwaitImport('cfg'), 'cfg'); esmock.purge(doAwaitImport); // clear cache, if you wish }); -test('should merge "default" value, when safe', async t => { +test('should merge "default" value, when safe', async () => { const main = await esmock('../src/main.js'); - t.is(main(), main.default()); // use the form you prefer + assert.strictEqual(main(), main.default()); }); -test('should use implicit "default"', async t => { +test('should use implicit "default"', async () => { const mainA = await esmock('../src/exportsMain.js', { '../src/main.js' : () => 'mocked main' // short-hand, smaller }); @@ -86,6 +87,6 @@ test('should use implicit "default"', async t => { '../src/main.js' : { default : () => 'mocked main' } }); - t.is(mainA(), mainB()); + assert.strictEqual(mainA(), mainB()); }); ``` diff --git a/package.json b/package.json index 589e8cea..cae5b4ab 100644 --- a/package.json +++ b/package.json @@ -62,9 +62,10 @@ "sinon": "^12.0.1" }, "scripts": { + "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", - "test": "npm run test-ava && npm run test-uvu", + "test": "npm run test-node && npm run test-ava && npm run test-uvu", "test-no-warn": "npx ava --node-arguments=\"--loader=esmock --no-warnings\"", "lint": "npx eslint src/*js spec" } diff --git a/spec/node/esmock.node.noloader.test.js b/spec/node/esmock.node.noloader.test.js new file mode 100644 index 00000000..6f356276 --- /dev/null +++ b/spec/node/esmock.node.noloader.test.js @@ -0,0 +1,11 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import esmock from '../../src/esmock.js'; + +test('should throw error if !esmockloader', async () => { + global.esmockloader = false; + await assert.rejects(() => esmock('./to/module.js'), { + message : 'process must be started with --loader=esmock' + }); + global.esmockloader = true; +}); diff --git a/spec/node/esmock.node.only.test.js b/spec/node/esmock.node.only.test.js new file mode 100644 index 00000000..8ae269db --- /dev/null +++ b/spec/node/esmock.node.only.test.js @@ -0,0 +1,15 @@ +import test from 'node:test'; +import assert from 'assert'; +import esmock from '../../src/esmock.js'; + +// this error can occur when sources do not define 'esmockloader' +// on 'global' but use a process linked variable instead +test('should not error when esmock used with ava.only', { + only : true +},async t => { + await esmock('../local/mainUtil.js', { + 'form-urlencoded' : () => 'mock encode' + }); + + assert.ok(true); +}); diff --git a/spec/node/esmock.node.test.js b/spec/node/esmock.node.test.js new file mode 100644 index 00000000..f6656e85 --- /dev/null +++ b/spec/node/esmock.node.test.js @@ -0,0 +1,350 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import esmock from '../../src/esmock.js'; +import sinon from 'sinon'; + +test('should return un-mocked file', async () => { + const main = await esmock('../local/main.js'); + const mainqs = [ + 'a+string', + 'mainUtilNamedExportOneValue=namedExportOne', + 'mainUtilNamedExportTwoValue=namedExportTwo' + ].join('&'); + + assert.strictEqual(main(), `main string, mainUtil=${mainqs}`); +}); + +test('should mock a local file', async () => { + const main = await esmock('../local/main.js', { + '../local/mainUtil.js' : { + createString : () => 'test string' + } + }); + + assert.strictEqual(typeof main, 'function'); + assert.strictEqual(main(), 'main string, test string'); +}); + +test('should throw error if local file not found', async () => { + await assert.rejects(() => esmock('../local/not/found.js', { + '../local/mainUtil.js' : { + createString : () => 'test string' + } + }), { + message : 'modulePath not found: "../local/not/found.js"' + }); +}); + +test('should throw error if local definition file not found', async () => { + await assert.rejects(() => esmock('../local/not/found.js', { + '../local/not/found.js' : { + createString : () => 'test string' + } + }), { + message : /not a valid path: \"..\/local\/not\/found.js\" \(used by/ + }); +}); + +test('should mock a module', async () => { + const main = await esmock('../local/mainUtil.js', { + 'form-urlencoded' : () => 'mock encode' + }); + + assert.strictEqual(typeof main, 'function'); + assert.strictEqual(main.createString(), 'mock encode'); +}); + +test('should mock a module, globally', async () => { + const main = await esmock('../local/main.js', { + '../local/mainUtilNamedExports.js' : { + mainUtilNamedExportOne : 'mocked' + } + }, { + 'form-urlencoded' : () => 'mock encode', + fs : { + existsSync : () => true, + readFileSync : filepath => filepath === 'checkfilepath.js' + ? 'success' + : filepath + } + }); + + assert.strictEqual(typeof main, 'function'); + assert.strictEqual( + main.mainDependencyUsingCoreModuleFSReadPath('checkfilepath.js'), + 'success' + ); + assert.strictEqual(main(), 'main string and mocked export, mock encode'); +}); + +test('should purge local and global mocks', async () => { + await esmock('../local/main.js', { + '../local/mainUtilNamedExports.js' : { + mainUtilNamedExportOne : 'mocked' + } + }, { + 'form-urlencoded' : () => 'mock encode', + fs : { + existsSync : () => true, + readFileSync : filepath => filepath === 'checkfilepath.js' + ? 'success' + : filepath + } + }, { + key : 999 + }); + + const keys = Object + .keys(esmock.esmockCache.mockDefs) + .filter(key => /esmockKey=999/.test(key)); + + assert.ok(keys.length); + assert.ok(keys.every(key => esmock.esmockCache.mockDefs[key] === null)); +}); + +test('should mock a module, many times differently', async () => { + const mainfoo = await esmock('../local/mainUtil.js', { + 'form-urlencoded' : () => 'mock encode foo' + }); + const mainbar = await esmock('../local/mainUtil.js', { + 'form-urlencoded' : () => 'mock encode bar' + }); + const mainbaz = await esmock('../local/mainUtil.js', { + 'form-urlencoded' : () => 'mock encode baz' + }); + assert.strictEqual(typeof mainfoo, 'function'); + assert.strictEqual(mainfoo.createString(), 'mock encode foo'); + assert.strictEqual(mainbar.createString(), 'mock encode bar'); + assert.strictEqual(mainbaz.createString(), 'mock encode baz'); +}); + +test('should return un-mocked file (again)', async () => { + const main = await esmock('../local/main.js'); + const mainqs = [ + 'a+string', + 'mainUtilNamedExportOneValue=namedExportOne', + 'mainUtilNamedExportTwoValue=namedExportTwo' + ].join('&'); + + assert.strictEqual(main(), `main string, mainUtil=${mainqs}`); +}); + +test('should mock local file', async () => { + const mainUtil = await esmock('../local/mainUtil.js', { + '../local/mainUtilNamedExports.js' : { + mainUtilNamedExportOne : () => 'foobar' + } + }); + + const mainqs = [ + 'mainUtil=a+string', + 'mainUtilNamedExportOneValue=foobar', + 'mainUtilNamedExportTwoValue=namedExportTwo' + ].join('&'); + + assert.strictEqual(mainUtil.createString(), mainqs); +}); + +test('should mock module and local file at the same time', async () => { + const mainUtil = await esmock('../local/mainUtil.js', { + 'form-urlencoded' : o => JSON.stringify(o), + '../local/mainUtilNamedExports.js' : { + mainUtilNamedExportOne : () => 'foobar' + } + }); + + assert.strictEqual(mainUtil.createString(), JSON.stringify({ + mainUtil : 'a string', + mainUtilNamedExportOneValue : 'foobar', + mainUtilNamedExportTwoValue : 'namedExportTwo' + })); +}); + +test('__esModule definition, inconsequential', async () => { + const mainUtil = await esmock('../local/mainUtil.js', { + 'form-urlencoded' : o => JSON.stringify(o), + '../local/mainUtilNamedExports.js' : { + mainUtilNamedExportOne : () => 'foobar', + __esModule : true + } + }); + + assert.strictEqual(mainUtil.createString(), JSON.stringify({ + mainUtil : 'a string', + mainUtilNamedExportOneValue : 'foobar', + mainUtilNamedExportTwoValue : 'namedExportTwo' + })); +}); + +test('should work well with sinon', async () => { + const mainUtil = await esmock('../local/mainUtil.js', { + '../local/mainUtilNamedExports.js' : { + mainUtilNamedExportOne : sinon.stub().returns('foobar') + } + }); + + assert.strictEqual(mainUtil.createString(), [ + 'mainUtil=a+string', + 'mainUtilNamedExportOneValue=foobar', + 'mainUtilNamedExportTwoValue=namedExportTwo' + ].join('&')); +}); + +test('should mock an mjs file', async () => { + const main = await esmock('../local/usesmjsModule.js', { + '../local/exampleMJS.mjs' : () => 'first mocked' + }); + + assert.strictEqual(main.verifyImportedMock(), 'first mocked'); +}); + +test('should mock an mjs file, again', async () => { + const main = await esmock('../local/usesmjsModule.js', { + '../local/exampleMJS.mjs' : () => 'second mocked' + }); + + assert.strictEqual(main.verifyImportedMock(), 'second mocked'); +}); + +test('should mock an exported constant values', async () => { + const main = await esmock('../local/usesmjsModule.js', { + '../local/env.js' : { + TESTCONSTANT : 'hello world' + } + }); + + assert.strictEqual(main.verifyImportedConstant(), 'hello world'); +}); + +test('should mock core module', async () => { + const usesCoreModule = await esmock('../local/usesCoreModule.js', { + fs : { + existsSync : () => true, + readFileSync : filepath => filepath === 'checkfilepath.js' + ? 'success' + : filepath + } + }); + + assert.strictEqual(usesCoreModule.readPath('checkfilepath.js'), 'success'); +}); + +test('should apply third parameter "global" definitions', async () => { + const main = await esmock('../local/main.js', { + '../local/mainUtil.js' : { + exportedFunction : () => 'foobar' + } + }, { + fs : { + readFileSync : () => { + return 'this value anywhere the instance imports fs, global'; + } + } + }); + + const tplStr = main.readTemplateFile(); + // eslint-disable-next-line max-len + assert.strictEqual(tplStr, 'this value anywhere the instance imports fs, global'); +}); + +test('returns spread-imported [object Module] default export', async () => { + const main = await esmock('../local/usesObjectModule.js', { + fs : { + exportedFunction : () => 'foobar' + } + }); + + assert.strictEqual(main.exportedFunction(), 'foobar'); +}); + +test('mocks inline `async import("name")`', async () => { + const writeJSConfigFile = await esmock.p('../local/usesInlineImport.mjs', { + eslint : { + ESLint : function (...o) { + this.stringify = () => JSON.stringify(...o); + + return this; + } + } + }); + + assert.strictEqual( + (await writeJSConfigFile('config', 'filePath')).stringify(), + JSON.stringify({ + baseConfig : 'config', + fix : true, + useEslintrc : false, + filePath : 'filePath' + })); + + const [ , key ] = writeJSConfigFile.esmockKey.match(/esmk=(\d*)/); + const keyRe = new RegExp(`esmockKey=${key}[^d]`); + + const moduleKeys = Object.keys(esmock.esmockCache.mockDefs) + .filter(moduleKey => keyRe.test(moduleKey)); + + assert.ok(moduleKeys.every(mkey => esmock.esmockCache.mockDefs[mkey])); + esmock.purge(writeJSConfigFile); + // eslint-disable-next-line max-len + assert.ok(moduleKeys.every(mkey => esmock.esmockCache.mockDefs[mkey] === null)); +}); + +test('should have small querystring in stacktrace filename', async () => { + const { causeRuntimeError } = await esmock('../local/mainUtil.js'); + + try { + causeRuntimeError(); + } catch (e) { + assert.ok(/\?esmk=\d/.test(e.stack.split('\n')[1])); + } + + assert.ok(true); +}); + +test('should have small querystring in stacktrace filename, deep', async () => { + const { + causeRuntimeErrorFromImportedFile + } = await esmock('../local/main.js', {}, { + '../local/mainUtil.js' : { + causeRuntimeError : () => { + assert.nonexistantmethod(); + } + } + }); + + try { + causeRuntimeErrorFromImportedFile(); + } catch (e) { + assert.ok( + e.stack.split('\n') + .every(line => !line.includes('?') || /\?esmk=\d/.test(line))); + } + + assert.ok(true); +}); + +test('should merge "default" value, when safe', async () => { + const main = await esmock('../local/main.js'); + + assert.strictEqual(main(), main.default()); + + const mockMainA = await esmock('../local/exportsMain.js', { + '../local/main.js' : () => 'mocked main' + }); + const mockMainB = await esmock('../local/exportsMain.js', { + '../local/main.js' : { default : () => 'mocked main' } + }); + + assert.strictEqual(mockMainA(), mockMainB()); +}); + +test('should not error when mocked file has space in path', async () => { + const main = await esmock('../local/main.js', { + '../local/space in path/wild-file.js' : { + default : 'tamed' + } + }); + + assert.strictEqual(main.wild, 'tamed'); +}); + From a88f5286ae8b77b52a25665d58639ca1a00258fd Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:33:55 -0700 Subject: [PATCH 03/19] update CHANGELOG and increment version --- CHANGELOG.md | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee19daf8..1f8524b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # changelog + * 1.7.8 _Jul.16.2022_ + * add tests using the node native test-runner + * update README to use node native test-runner * 1.7.7 _Jul.14.2022_ - * support node v18.6.0 loader changes, credit @swivelgames + * support node v18.6.0 loader changes, credit @swivelgamesw * 1.7.6 _Jul.13.2022_ * use npx script commands, credit @swivelgames * add NODE_OPTIONS support, credit @swivelgames diff --git a/package.json b/package.json index cae5b4ab..950cafac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "esmock", - "version": "1.7.7", + "version": "1.7.8", "license": "MIT", "readmeFilename": "README.md", "description": "provides native ESM import mocking for unit tests", From 97e412cfa9664b22e5e59e8fcdb2892142e513b4 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:35:05 -0700 Subject: [PATCH 04/19] remove typo from changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8524b3..abc85dd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * add tests using the node native test-runner * update README to use node native test-runner * 1.7.7 _Jul.14.2022_ - * support node v18.6.0 loader changes, credit @swivelgamesw + * support node v18.6.0 loader changes, credit @swivelgames * 1.7.6 _Jul.13.2022_ * use npx script commands, credit @swivelgames * add NODE_OPTIONS support, credit @swivelgames From 343a8380e878db3521e24015948b62bfbb4442bc Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:41:37 -0700 Subject: [PATCH 05/19] only call node test runner for node v18 --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 950cafac..046f4176 100644 --- a/package.json +++ b/package.json @@ -63,9 +63,10 @@ }, "scripts": { "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", + "test-node18": "(node --version | grep v18) && npm run test-node", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", - "test": "npm run test-node && npm run test-ava && npm run test-uvu", + "test": "npm run test-node18 && npm run test-ava && npm run test-uvu", "test-no-warn": "npx ava --node-arguments=\"--loader=esmock --no-warnings\"", "lint": "npx eslint src/*js spec" } From ba5c17dfe963a578a2769159e8d170f7e0616839 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:44:15 -0700 Subject: [PATCH 06/19] return exit code 0 from node18 test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 046f4176..9f6b0e99 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "scripts": { "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", - "test-node18": "(node --version | grep v18) && npm run test-node", + "test-node18": "(node --version | grep v18) && npm run test-node; exit 0", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", "test": "npm run test-node18 && npm run test-ava && npm run test-uvu", From de00f820006e321234e7daa8850e01b7d507801a Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:46:42 -0700 Subject: [PATCH 07/19] correct lint --- spec/node/esmock.node.only.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/node/esmock.node.only.test.js b/spec/node/esmock.node.only.test.js index 8ae269db..17777f2f 100644 --- a/spec/node/esmock.node.only.test.js +++ b/spec/node/esmock.node.only.test.js @@ -6,7 +6,7 @@ import esmock from '../../src/esmock.js'; // on 'global' but use a process linked variable instead test('should not error when esmock used with ava.only', { only : true -},async t => { +}, async () => { await esmock('../local/mainUtil.js', { 'form-urlencoded' : () => 'mock encode' }); From 2b3dc45de508074376e906f90cec554377d25574 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 12:54:48 -0700 Subject: [PATCH 08/19] change condition bash --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f6b0e99..26efe29c 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "scripts": { "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", - "test-node18": "(node --version | grep v18) && npm run test-node; exit 0", + "test-node18": "if (node --version | grep v18); then npm run test-node; fi;", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", "test": "npm run test-node18 && npm run test-ava && npm run test-uvu", From 13295793b7130706bfd9781cd61f72b07e05fe28 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 13:01:17 -0700 Subject: [PATCH 09/19] try node -v --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26efe29c..4c0366b8 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "scripts": { "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", - "test-node18": "if (node --version | grep v18); then npm run test-node; fi;", + "test-node18": "if (node -v | grep v18); then npm run test-node; fi;", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", "test": "npm run test-node18 && npm run test-ava && npm run test-uvu", From 9c5ed9c7fd5b9be8237139be49a4a825b6e0907e Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 13:13:17 -0700 Subject: [PATCH 10/19] use npx run-script-os --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4c0366b8..196b0698 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,9 @@ "test-node18": "if (node -v | grep v18); then npm run test-node; fi;", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", - "test": "npm run test-node18 && npm run test-ava && npm run test-uvu", + "test:default": "npm run test-node18 && npm run test-ava && npm run test-uvu", + "test:windows": "npm run test-ava && npm run test-uvu", + "test": "npx run-script-os", "test-no-warn": "npx ava --node-arguments=\"--loader=esmock --no-warnings\"", "lint": "npx eslint src/*js spec" } From 8c06304728ed6c7c35c13b89ced7fb1b8bdc6ec4 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 13:18:00 -0700 Subject: [PATCH 11/19] use run-script-os --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 196b0698..f20dc48e 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "eslint": "^8.12.0", "esmock": "file:.", "form-urlencoded": "4.2.1", + "run-script-os": "^1.1.6", "sinon": "^12.0.1" }, "scripts": { @@ -68,7 +69,7 @@ "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", "test:default": "npm run test-node18 && npm run test-ava && npm run test-uvu", "test:windows": "npm run test-ava && npm run test-uvu", - "test": "npx run-script-os", + "test": "run-script-os", "test-no-warn": "npx ava --node-arguments=\"--loader=esmock --no-warnings\"", "lint": "npx eslint src/*js spec" } From 5f6f01ec39772d5028902050cbca77db2e0adc78 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 13:44:46 -0700 Subject: [PATCH 12/19] use smaller test command in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 844736a7..a306ee17 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ esmock "name": "give-esmock-a-star", "type": "module", "scripts": { - "test": "node --loader=esmock --test ./spec/", + "test": "node --loader=esmock --test", "test-uvu": "node --loader=esmock ./node_modules/uvu/bin.js ./spec/", "test-ava": "ava --node-arguments=\"--loader=esmock\"", "test-mocha": "mocha --loader=esmock --no-warnings" From c6dfd95f0c76745ad88e45e4236cd2c8f3776811 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 14:07:05 -0700 Subject: [PATCH 13/19] added test-tap to README script example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a306ee17..890c00a9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ esmock "type": "module", "scripts": { "test": "node --loader=esmock --test", + "test-tap": "tap --node-arg=\"--loader=esmock\"", "test-uvu": "node --loader=esmock ./node_modules/uvu/bin.js ./spec/", "test-ava": "ava --node-arguments=\"--loader=esmock\"", "test-mocha": "mocha --loader=esmock --no-warnings" From 529de0c525178cf91358dd06c98be9fae337664a Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 14:26:01 -0700 Subject: [PATCH 14/19] remove --no-warnings from test-mocha example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 890c00a9..7998b3f0 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ esmock "test-tap": "tap --node-arg=\"--loader=esmock\"", "test-uvu": "node --loader=esmock ./node_modules/uvu/bin.js ./spec/", "test-ava": "ava --node-arguments=\"--loader=esmock\"", - "test-mocha": "mocha --loader=esmock --no-warnings" + "test-mocha": "mocha --loader=esmock" } } ``` From 6bfe5402a22d14c628bfe98b065a06bd63097904 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 14:47:44 -0700 Subject: [PATCH 15/19] added esmock ascii title --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7998b3f0..c2da59b6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ -esmock -====== +```diff ++███████╗███████╗███╗ ███╗ ██████╗ ██████╗██╗ ██╗ ++██╔════╝██╔════╝████╗ ████║██╔═══██╗██╔════╝██║ ██╔╝ ++█████╗ ███████╗██╔████╔██║██║ ██║██║ █████╔╝ ++██╔══╝ ╚════██║██║╚██╔╝██║██║ ██║██║ ██╔═██╗ ++███████╗███████║██║ ╚═╝ ██║╚██████╔╝╚██████╗██║ ██╗ ++╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ +``` [![npm version](https://badge.fury.io/js/esmock.svg)](https://badge.fury.io/js/esmock) [![Build Status](https://github.com/iambumblehead/esmock/workflows/nodejs-ci/badge.svg)][2] [![install size](https://packagephobia.now.sh/badge?p=esmock)](https://packagephobia.now.sh/result?p=esmock) [![downloads](https://badgen.now.sh/npm/dm/esmock)](https://npmjs.org/package/esmock) **esmock provides native ESM import mocking for unit tests.** Use examples below as a quick-start guide or use the [descriptive and friendly esmock guide here.][10] From 8a4a10a963457ac9ae1a6b0e5c34ee8e07c790ab Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 16:19:17 -0700 Subject: [PATCH 16/19] lower-case esmock --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c2da59b6..c14bd9df 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ ```diff -+███████╗███████╗███╗ ███╗ ██████╗ ██████╗██╗ ██╗ -+██╔════╝██╔════╝████╗ ████║██╔═══██╗██╔════╝██║ ██╔╝ -+█████╗ ███████╗██╔████╔██║██║ ██║██║ █████╔╝ -+██╔══╝ ╚════██║██║╚██╔╝██║██║ ██║██║ ██╔═██╗ -+███████╗███████║██║ ╚═╝ ██║╚██████╔╝╚██████╗██║ ██╗ -+╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ++ ██╗ ++ ██████╗ ███████╗ █████═████╗ ██████╗ ██████╗██║ ██╗ ++██╔═══██╗██╔═════╝██╔══██╔══██╗██╔═══██╗██╔════╝██║ ██╔╝ ++████████║╚██████╗ ██║ ██║ ██║██║ ██║██║ ██████╔╝ ++██╔═════╝ ╚════██╗██║ ██║ ██║██║ ██║██║ ██╔══██╗ ++╚███████╗███████╔╝██║ ██║ ██║╚██████╔╝╚██████╗██║ ╚██╗ ++ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ``` [![npm version](https://badge.fury.io/js/esmock.svg)](https://badge.fury.io/js/esmock) [![Build Status](https://github.com/iambumblehead/esmock/workflows/nodejs-ci/badge.svg)][2] [![install size](https://packagephobia.now.sh/badge?p=esmock)](https://packagephobia.now.sh/result?p=esmock) [![downloads](https://badgen.now.sh/npm/dm/esmock)](https://npmjs.org/package/esmock) From b8a147fab18b2ca6c9ff603ef1de4a18b63be34a Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 23:44:08 -0700 Subject: [PATCH 17/19] update README example commands to use NODE_OPTIONS --- README.md | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c14bd9df..ec39b774 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ "type": "module", "scripts": { "test": "node --loader=esmock --test", - "test-tap": "tap --node-arg=\"--loader=esmock\"", - "test-uvu": "node --loader=esmock ./node_modules/uvu/bin.js ./spec/", - "test-ava": "ava --node-arguments=\"--loader=esmock\"", + "test-tap": "NODE_OPTIONS='--loader=esmock' tap", + "test-uvu": "NODE_OPTIONS='--loader=esmock' uvu ./spec/", + "test-ava": "NODE_OPTIONS='--loader=esmock' ava", "test-mocha": "mocha --loader=esmock" } } diff --git a/package.json b/package.json index f20dc48e..63736ac0 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", "test-node18": "if (node -v | grep v18); then npm run test-node; fi;", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", - "test-uvu": "node --no-warnings --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", + "test-uvu": "NODE_OPTIONS='--loader=esmock' uvu ./spec/uvu/", "test:default": "npm run test-node18 && npm run test-ava && npm run test-uvu", "test:windows": "npm run test-ava && npm run test-uvu", "test": "run-script-os", From 4edcfecff54033b7ca44ba3ba1d3e8000fd2edba Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 23:49:13 -0700 Subject: [PATCH 18/19] remove NODE_OPTIONS from npm script commands --not supported by older node versions --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63736ac0..a075597e 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "test-node": "node --no-warnings --loader=esmock --test ./spec/node/", "test-node18": "if (node -v | grep v18); then npm run test-node; fi;", "test-ava": "npx ava --node-arguments=\"--loader=esmock\" ./spec/ava/*.spec.js", - "test-uvu": "NODE_OPTIONS='--loader=esmock' uvu ./spec/uvu/", + "test-uvu": "node --loader=esmock ./node_modules/uvu/bin.js ./spec/uvu/", "test:default": "npm run test-node18 && npm run test-ava && npm run test-uvu", "test:windows": "npm run test-ava && npm run test-uvu", "test": "run-script-os", From 294657c750befa897481bb5b1e8bd033d27232d8 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 16 Jul 2022 23:53:11 -0700 Subject: [PATCH 19/19] remove un-needed quote --- CHANGELOG.md | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abc85dd7..de69a3ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ * 1.7.3 _Feb.02.2022_ * increment resolvewithplus to handle array esm export, used by 'yargs' * 1.7.2 _Dec.15.2021_ - * remove README at npm packagew + * remove README at npm package * 1.7.1 _Dec.15.2021_ * increment resolvewithplus, better tests * 1.7.0 _Dec.13.2021_ diff --git a/README.md b/README.md index ec39b774..6869b94b 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ "type": "module", "scripts": { "test": "node --loader=esmock --test", - "test-tap": "NODE_OPTIONS='--loader=esmock' tap", - "test-uvu": "NODE_OPTIONS='--loader=esmock' uvu ./spec/", - "test-ava": "NODE_OPTIONS='--loader=esmock' ava", + "test-tap": "NODE_OPTIONS=--loader=esmock tap", + "test-uvu": "NODE_OPTIONS=--loader=esmock uvu ./spec/", + "test-ava": "NODE_OPTIONS=--loader=esmock ava", "test-mocha": "mocha --loader=esmock" } }