From 5241adcd19a09f8c6bb7b271f137f5d3bd1ea921 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 30 Jul 2023 14:07:11 -0500 Subject: [PATCH 1/2] add failing test --- tests/local/usesModuleWithCJSDependency.js | 5 +++++ tests/package.json | 9 +++++---- tests/tests-node/esmock.node.global.test.js | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/local/usesModuleWithCJSDependency.js diff --git a/tests/local/usesModuleWithCJSDependency.js b/tests/local/usesModuleWithCJSDependency.js new file mode 100644 index 00000000..96055c8b --- /dev/null +++ b/tests/local/usesModuleWithCJSDependency.js @@ -0,0 +1,5 @@ +import meow from 'meow' + +const cli = meow('foo', { importMeta: import.meta, description: false }) + +console.log(cli.help); diff --git a/tests/package.json b/tests/package.json index a831cd82..fab261d1 100644 --- a/tests/package.json +++ b/tests/package.json @@ -15,13 +15,14 @@ "#sub": "./local/subpath.js" }, "dependencies": { - "pg": "^8.7.3", + "babelGeneratedDoubleDefault": "file:./local/babelGeneratedDoubleDefault", "eslint": "^8.12.0", - "sinon": "^12.0.1", "form-urlencoded": "^6.0.7", - "run-script-os": "^1.1.6", + "meow": "12.0.1", "npm-run-all": "^4.1.5", - "babelGeneratedDoubleDefault": "file:./local/babelGeneratedDoubleDefault" + "pg": "^8.7.3", + "run-script-os": "^1.1.6", + "sinon": "^12.0.1" }, "scripts": { "mini": "cd .. && cd src && npx esbuild esmock.js --minify --bundle --allow-overwrite --platform=node --format=esm --outfile=esmock.js", diff --git a/tests/tests-node/esmock.node.global.test.js b/tests/tests-node/esmock.node.global.test.js index 80df389f..93e824e5 100644 --- a/tests/tests-node/esmock.node.global.test.js +++ b/tests/tests-node/esmock.node.global.test.js @@ -63,3 +63,15 @@ test('should mock files with hashbangs', async () => { assert.deepEqual(logs, ['foo']) }) + +test('should work when modules have CJS imports', async () => { + const logs = [] + + await esmock('../local/usesModuleWithCJSDependency.js', {}, { + import: { + console: { log: (...args) => logs.push(...args) } + } + }) + + assert.deepEqual(logs, ['\nfoo\n']) +}); From 017b7aeafc7576f4110b808ed711569958e15d1a Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Sun, 30 Jul 2023 14:40:36 -0500 Subject: [PATCH 2/2] fix(`lint`) --- tests/local/usesModuleWithCJSDependency.js | 2 +- tests/tests-node/esmock.node.global.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/local/usesModuleWithCJSDependency.js b/tests/local/usesModuleWithCJSDependency.js index 96055c8b..bfeb0557 100644 --- a/tests/local/usesModuleWithCJSDependency.js +++ b/tests/local/usesModuleWithCJSDependency.js @@ -2,4 +2,4 @@ import meow from 'meow' const cli = meow('foo', { importMeta: import.meta, description: false }) -console.log(cli.help); +console.log(cli.help) diff --git a/tests/tests-node/esmock.node.global.test.js b/tests/tests-node/esmock.node.global.test.js index 93e824e5..a2908cf6 100644 --- a/tests/tests-node/esmock.node.global.test.js +++ b/tests/tests-node/esmock.node.global.test.js @@ -74,4 +74,4 @@ test('should work when modules have CJS imports', async () => { }) assert.deepEqual(logs, ['\nfoo\n']) -}); +})