From 66a9474cda586d5ec1fa2ca4e08336f1491eaf9c Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 19 Aug 2022 07:35:53 -0700 Subject: [PATCH 1/3] reproduce not a valid path error --- tests/local/main.ts | 4 +++- tests/package.json | 1 + tests/tests-tsm/esmock.node-tsm.test.ts | 14 +++++++++++++- tests/tests-tsm/package.json | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/local/main.ts b/tests/local/main.ts index 6330783f..d3c1cef7 100644 --- a/tests/local/main.ts +++ b/tests/local/main.ts @@ -1,5 +1,7 @@ import path from 'path'; +import pg from 'pg'; export default { - pathbasenamewrap: (n: any) => path.basename(n) + pathbasenamewrap: (n: any) => path.basename(n), + pgpoolwrap: (n: any) => pg.Pool(n) }; diff --git a/tests/package.json b/tests/package.json index af009ac3..bd4f23ff 100644 --- a/tests/package.json +++ b/tests/package.json @@ -8,6 +8,7 @@ }, "main": "package.json.esmock.export.js", "dependencies": { + "pg": "^8.7.3", "eslint": "^8.12.0", "sinon": "^12.0.1", "form-urlencoded": "^6.0.7", diff --git a/tests/tests-tsm/esmock.node-tsm.test.ts b/tests/tests-tsm/esmock.node-tsm.test.ts index 4c938782..8688f253 100644 --- a/tests/tests-tsm/esmock.node-tsm.test.ts +++ b/tests/tests-tsm/esmock.node-tsm.test.ts @@ -2,7 +2,7 @@ import test from 'node:test'; import assert from 'assert'; import esmock from 'esmock'; -test('should mock ts when using node-ts', { only : true }, async () => { +test('should mock ts when using node-ts', async () => { const main = await esmock('../local/main.ts', { path: { basename: () => 'hellow' @@ -12,3 +12,15 @@ test('should mock ts when using node-ts', { only : true }, async () => { assert.strictEqual( main.pathbasenamewrap(), 'hellow' ); assert.ok(true); }); + +test('should mock pg', async () => { + const main = await esmock('../local/main-pg.ts', { + pg: { + Pool: (config:any) => { + return 'mocked pool' + } + } + }); + + assert.strictEqual( main.pgpoolwrap(), 'mocked pool' ); +}); diff --git a/tests/tests-tsm/package.json b/tests/tests-tsm/package.json index 23326cad..4969a6cf 100644 --- a/tests/tests-tsm/package.json +++ b/tests/tests-tsm/package.json @@ -8,6 +8,7 @@ "dependencies": { "tsm": "^2.2.2", "esmock": "file:..", + "pg": "file:../node_modules/pg", "sinon": "file:../node_modules/sinon", "eslint": "file:../node_modules/eslint", "form-urlencoded": "file:../node_modules/form-urlencoded", From 9f2d1977e09e0c7f9f3c30d05c4e4c9971a304e6 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 19 Aug 2022 08:25:50 -0700 Subject: [PATCH 2/3] updated test to us correct path to main.ts --- package.json | 2 +- tests/tests-tsm/esmock.node-tsm.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e9a720d6..8edce3ae 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "rewire" ], "dependencies": { - "resolvewithplus": "^0.8.7" + "resolvewithplus": "^0.8.9" }, "devDependencies": { "c8": "^7.12.0", diff --git a/tests/tests-tsm/esmock.node-tsm.test.ts b/tests/tests-tsm/esmock.node-tsm.test.ts index 8688f253..a92b8b4b 100644 --- a/tests/tests-tsm/esmock.node-tsm.test.ts +++ b/tests/tests-tsm/esmock.node-tsm.test.ts @@ -14,8 +14,8 @@ test('should mock ts when using node-ts', async () => { }); test('should mock pg', async () => { - const main = await esmock('../local/main-pg.ts', { - pg: { + const main = await esmock('../local/main.ts', { + 'pg': { Pool: (config:any) => { return 'mocked pool' } From 9a2730ad193f22f69b0d6e04a7ebe81dfaf407d0 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 19 Aug 2022 08:28:58 -0700 Subject: [PATCH 3/3] increment version and update changelog --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e01ff0a2..20bc209d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # changelog + * 1.9.5 + * support cjs packges that define [main relative directory only](https://github.com/iambumblehead/esmock/issues/119) * 1.9.4 _Aug.15.2022_ * support core modules [w/ node: prefix](https://github.com/iambumblehead/resolvewithplus/pull/27), credit @gmahomarf * 1.9.3 _Aug.13.2022_ diff --git a/package.json b/package.json index 8edce3ae..a984b61b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "esmock", "type": "module", - "version": "1.9.4", + "version": "1.9.5", "license": "ISC", "readmeFilename": "README.md", "description": "provides native ESM import mocking for unit tests",