From f5b390393b185d4fb15b4b7ba05c1683399df343 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 2 Oct 2024 12:42:41 -0700 Subject: [PATCH 1/3] add failing test, re issue 312 --- tests/local/importsChangelogParser.js | 3 +++ tests/package.json | 1 + tests/tests-node/esmock.node.test.js | 12 ++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 tests/local/importsChangelogParser.js diff --git a/tests/local/importsChangelogParser.js b/tests/local/importsChangelogParser.js new file mode 100644 index 0000000..4869b25 --- /dev/null +++ b/tests/local/importsChangelogParser.js @@ -0,0 +1,3 @@ +import parseChangelog from 'changelog-parser' + +export default parseChangelog diff --git a/tests/package.json b/tests/package.json index 6bd65bc..e988760 100644 --- a/tests/package.json +++ b/tests/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "express": "^4.18.2", + "changelog-parser": "^3.0.1", "@aws-sdk/client-s3": "^3.408.0", "babelGeneratedDoubleDefault": "file:./local/babelGeneratedDoubleDefault", "eslint": "^8.54.0", diff --git a/tests/tests-node/esmock.node.test.js b/tests/tests-node/esmock.node.test.js index 40c59c7..1d0f5fb 100644 --- a/tests/tests-node/esmock.node.test.js +++ b/tests/tests-node/esmock.node.test.js @@ -5,6 +5,18 @@ import esmock from 'esmock' import sinon from 'sinon' import esmockCache from '../../src/esmockCache.js' +// https://github.com/iambumblehead/esmock/issues/312 +test('should mock changelog-parser', {skip: true}, async () => { + const parseChangelog = await esmock( + '../local/importsChangelogParser.js', {}, { + 'node:fs': { + read: test.mock.fn(() => 'content') + } + }) + + assert.strictEqual(await parseChangelog({ filePath: 'fake' }), 'content') +}) + test('should mock node:process', async () => { // has direct and in-direct calls to `process.cwd()` const thingBeingTested = await esmock('../local/usesNodeProcess.js', {}, { From 8c0b796c7a7d3d1c2fb4f76138f9ed175eec8377 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 2 Oct 2024 12:50:46 -0700 Subject: [PATCH 2/3] skip: false --- tests/tests-node/esmock.node.test.js | 4 +++- tests/tests-node/package.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/tests-node/esmock.node.test.js b/tests/tests-node/esmock.node.test.js index 1d0f5fb..c26dfd0 100644 --- a/tests/tests-node/esmock.node.test.js +++ b/tests/tests-node/esmock.node.test.js @@ -6,10 +6,12 @@ import sinon from 'sinon' import esmockCache from '../../src/esmockCache.js' // https://github.com/iambumblehead/esmock/issues/312 -test('should mock changelog-parser', {skip: true}, async () => { +test('should mock changelog-parser', {skip: false}, async () => { const parseChangelog = await esmock( '../local/importsChangelogParser.js', {}, { 'node:fs': { + open: test.mock.fn(), + close: test.mock.fn(), read: test.mock.fn(() => 'content') } }) diff --git a/tests/tests-node/package.json b/tests/tests-node/package.json index 5bf8edd..4906a3b 100644 --- a/tests/tests-node/package.json +++ b/tests/tests-node/package.json @@ -10,6 +10,7 @@ "sinon": "file:../node_modules/sinon", "eslint": "file:../node_modules/eslint", "form-urlencoded": "file:../node_modules/form-urlencoded", + "changelog-parser": "file:../node_modules/changelog-parser", "babelGeneratedDoubleDefault": "file:../local/babelGeneratedDoubleDefault" }, "scripts": { From af90140aeae227707b8393de5fbae478c9698c44 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 2 Oct 2024 13:05:40 -0700 Subject: [PATCH 3/3] { only: true, skip: true } --- tests/tests-node/esmock.node.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/tests-node/esmock.node.test.js b/tests/tests-node/esmock.node.test.js index c26dfd0..ebd4d1a 100644 --- a/tests/tests-node/esmock.node.test.js +++ b/tests/tests-node/esmock.node.test.js @@ -6,7 +6,10 @@ import sinon from 'sinon' import esmockCache from '../../src/esmockCache.js' // https://github.com/iambumblehead/esmock/issues/312 -test('should mock changelog-parser', {skip: false}, async () => { +test('should mock changelog-parser', { + only: true, + skip: true +}, async () => { const parseChangelog = await esmock( '../local/importsChangelogParser.js', {}, { 'node:fs': {