From 9cc92fed51644d738bf0773429dab8e2f702dba0 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 11 Sep 2023 00:52:51 -0700 Subject: [PATCH 01/12] added workspace test --- tests/tests-workspaces/package.json | 8 +++++++ tests/tests-workspaces/packages/a/index.js | 3 +++ .../tests-workspaces/packages/a/package.json | 6 +++++ tests/tests-workspaces/packages/b/index.js | 5 ++++ .../tests-workspaces/packages/b/package.json | 14 +++++++++++ tests/tests-workspaces/packages/b/test.js | 24 +++++++++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 tests/tests-workspaces/package.json create mode 100644 tests/tests-workspaces/packages/a/index.js create mode 100644 tests/tests-workspaces/packages/a/package.json create mode 100644 tests/tests-workspaces/packages/b/index.js create mode 100644 tests/tests-workspaces/packages/b/package.json create mode 100644 tests/tests-workspaces/packages/b/test.js diff --git a/tests/tests-workspaces/package.json b/tests/tests-workspaces/package.json new file mode 100644 index 00000000..074e1d1f --- /dev/null +++ b/tests/tests-workspaces/package.json @@ -0,0 +1,8 @@ +{ + "name": "esmock unit tests, workspaces", + "workspaces": ["packages/*"], + "esmock": "file:..", + "scripts": { + "test": "npm --prefix packages/b test" + } +} diff --git a/tests/tests-workspaces/packages/a/index.js b/tests/tests-workspaces/packages/a/index.js new file mode 100644 index 00000000..c970c823 --- /dev/null +++ b/tests/tests-workspaces/packages/a/index.js @@ -0,0 +1,3 @@ +export function foo () { + return 'foo' +} diff --git a/tests/tests-workspaces/packages/a/package.json b/tests/tests-workspaces/packages/a/package.json new file mode 100644 index 00000000..e9ec9a18 --- /dev/null +++ b/tests/tests-workspaces/packages/a/package.json @@ -0,0 +1,6 @@ +{ + "name": "a", + "version": "0.0.0", + "type": "module", + "main": "index.js" +} diff --git a/tests/tests-workspaces/packages/b/index.js b/tests/tests-workspaces/packages/b/index.js new file mode 100644 index 00000000..cd0f9ecb --- /dev/null +++ b/tests/tests-workspaces/packages/b/index.js @@ -0,0 +1,5 @@ +import {foo} from 'a' + +export default function test () { + return foo() +} diff --git a/tests/tests-workspaces/packages/b/package.json b/tests/tests-workspaces/packages/b/package.json new file mode 100644 index 00000000..acc4f3be --- /dev/null +++ b/tests/tests-workspaces/packages/b/package.json @@ -0,0 +1,14 @@ +{ + "name": "b", + "version": "0.0.0", + "type": "module", + "scripts": { + "test": "node --loader=esmock --test" + }, + "dependencies": { + "a": "^0.0.0" + }, + "devDependencies": { + "esmock": "^2.3.8" + } +} diff --git a/tests/tests-workspaces/packages/b/test.js b/tests/tests-workspaces/packages/b/test.js new file mode 100644 index 00000000..0d566e4b --- /dev/null +++ b/tests/tests-workspaces/packages/b/test.js @@ -0,0 +1,24 @@ +import esmock from 'esmock' +import module from 'module' +import test from 'node:test' +import assert from 'node:assert/strict' + +test('works ootb', async () => { + const sut = await esmock('./index.js', { + a: { foo: () => 'bar' } + }) + + assert.equal(sut(), 'bar') +}) + +test('works roubdabout way', async () => { + const require = module.createRequire(import.meta.url) + + const sut = await esmock('./index.js', { + [require.resolve('a')]: { + foo: () => 'bar' + } + }) + + assert.equal(sut(), 'bar') +}) From c6ad1457ddf2dcc78ae1e3fcac9545849037f573 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 11 Sep 2023 01:24:13 -0700 Subject: [PATCH 02/12] use local esmock --- tests/tests-workspaces/packages/b/package.json | 5 +---- tests/tests-workspaces/packages/b/test.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/tests-workspaces/packages/b/package.json b/tests/tests-workspaces/packages/b/package.json index acc4f3be..8d3f7cb1 100644 --- a/tests/tests-workspaces/packages/b/package.json +++ b/tests/tests-workspaces/packages/b/package.json @@ -3,12 +3,9 @@ "version": "0.0.0", "type": "module", "scripts": { - "test": "node --loader=esmock --test" + "test": "node --test" }, "dependencies": { "a": "^0.0.0" - }, - "devDependencies": { - "esmock": "^2.3.8" } } diff --git a/tests/tests-workspaces/packages/b/test.js b/tests/tests-workspaces/packages/b/test.js index 0d566e4b..827a41e2 100644 --- a/tests/tests-workspaces/packages/b/test.js +++ b/tests/tests-workspaces/packages/b/test.js @@ -1,7 +1,7 @@ -import esmock from 'esmock' import module from 'module' import test from 'node:test' import assert from 'node:assert/strict' +import esmock from '../../../../src/esmock.js' test('works ootb', async () => { const sut = await esmock('./index.js', { From b9899fb824e8c977e438a8ebd69609e6f7f96822 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 18:28:16 -0700 Subject: [PATCH 03/12] use latest resolvewithplus, improve typescript files resolution --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 49428876..bfb1bbd9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "node": ">=14.16.0" }, "dependencies": { - "resolvewithplus": "^2.0.2" + "resolvewithplus": "^2.0.3" }, "devDependencies": { "c8": "^8.0.1", From 9d28c026e4885cb1fb196594d596642523fcf3bc Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 18:39:39 -0700 Subject: [PATCH 04/12] use separate js and ts workspaces --- tests/package.json | 1 + tests/tests-workspaces/package.json | 11 ++++++--- tests/tests-workspaces/packages/b/test.js | 24 ------------------- .../a => workspaces-js/js-a}/index.js | 0 .../a => workspaces-js/js-a}/package.json | 2 +- .../workspaces-js/js-b/esmock.js | 4 ++++ .../b => workspaces-js/js-b}/index.js | 0 .../b => workspaces-js/js-b}/package.json | 4 ++-- .../workspaces-js/js-b/test.js | 11 +++++++++ .../workspaces-ts/ts-a/index.js | 3 +++ .../workspaces-ts/ts-a/package.json | 6 +++++ .../workspaces-ts/ts-b/esmock.js | 4 ++++ .../workspaces-ts/ts-b/index.js | 5 ++++ .../workspaces-ts/ts-b/package.json | 14 +++++++++++ .../workspaces-ts/ts-b/test.js | 11 +++++++++ .../workspaces-ts/tsconfig.json | 8 +++++++ 16 files changed, 78 insertions(+), 30 deletions(-) delete mode 100644 tests/tests-workspaces/packages/b/test.js rename tests/tests-workspaces/{packages/a => workspaces-js/js-a}/index.js (100%) rename tests/tests-workspaces/{packages/a => workspaces-js/js-a}/package.json (78%) create mode 100644 tests/tests-workspaces/workspaces-js/js-b/esmock.js rename tests/tests-workspaces/{packages/b => workspaces-js/js-b}/index.js (100%) rename tests/tests-workspaces/{packages/b => workspaces-js/js-b}/package.json (74%) create mode 100644 tests/tests-workspaces/workspaces-js/js-b/test.js create mode 100644 tests/tests-workspaces/workspaces-ts/ts-a/index.js create mode 100644 tests/tests-workspaces/workspaces-ts/ts-a/package.json create mode 100644 tests/tests-workspaces/workspaces-ts/ts-b/esmock.js create mode 100644 tests/tests-workspaces/workspaces-ts/ts-b/index.js create mode 100644 tests/tests-workspaces/workspaces-ts/ts-b/package.json create mode 100644 tests/tests-workspaces/workspaces-ts/ts-b/test.js create mode 100644 tests/tests-workspaces/workspaces-ts/tsconfig.json diff --git a/tests/package.json b/tests/package.json index 44c7d030..a6f77dde 100644 --- a/tests/package.json +++ b/tests/package.json @@ -55,6 +55,7 @@ "test:node18-test-nodets": "cd tests-nodets && npm test", "test:node18-test-source-map": "cd tests-source-map && npm test", "test:node18-test-no-loader": "cd tests-no-loader && npm test", + "test:node18-test-workspces": "cd tests-workspaces && npm test", "test:node18:all": "npm run isnodelt18 || npm-run-all test:node18-test*", "test:all": "npm-run-all test:test* && npm run test:node18:all", "test:all-cover": "c8 --src=../src/* npm run test:all", diff --git a/tests/tests-workspaces/package.json b/tests/tests-workspaces/package.json index 074e1d1f..c6de0cf5 100644 --- a/tests/tests-workspaces/package.json +++ b/tests/tests-workspaces/package.json @@ -1,8 +1,13 @@ { "name": "esmock unit tests, workspaces", - "workspaces": ["packages/*"], - "esmock": "file:..", + "workspaces": [ + "workspaces-js/*", + "workspaces-ts/*" + ], "scripts": { - "test": "npm --prefix packages/b test" + "test-workspaces-js": "npm --prefix workspaces-js/js-b test", + "test-workspaces-ts": "npm --prefix workspaces-js/js-b test", + "test-workspaces": "npm run test-workspaces-js && npm run test-workspaces-ts", + "test": "npm run test-workspaces" } } diff --git a/tests/tests-workspaces/packages/b/test.js b/tests/tests-workspaces/packages/b/test.js deleted file mode 100644 index 827a41e2..00000000 --- a/tests/tests-workspaces/packages/b/test.js +++ /dev/null @@ -1,24 +0,0 @@ -import module from 'module' -import test from 'node:test' -import assert from 'node:assert/strict' -import esmock from '../../../../src/esmock.js' - -test('works ootb', async () => { - const sut = await esmock('./index.js', { - a: { foo: () => 'bar' } - }) - - assert.equal(sut(), 'bar') -}) - -test('works roubdabout way', async () => { - const require = module.createRequire(import.meta.url) - - const sut = await esmock('./index.js', { - [require.resolve('a')]: { - foo: () => 'bar' - } - }) - - assert.equal(sut(), 'bar') -}) diff --git a/tests/tests-workspaces/packages/a/index.js b/tests/tests-workspaces/workspaces-js/js-a/index.js similarity index 100% rename from tests/tests-workspaces/packages/a/index.js rename to tests/tests-workspaces/workspaces-js/js-a/index.js diff --git a/tests/tests-workspaces/packages/a/package.json b/tests/tests-workspaces/workspaces-js/js-a/package.json similarity index 78% rename from tests/tests-workspaces/packages/a/package.json rename to tests/tests-workspaces/workspaces-js/js-a/package.json index e9ec9a18..17e9f94a 100644 --- a/tests/tests-workspaces/packages/a/package.json +++ b/tests/tests-workspaces/workspaces-js/js-a/package.json @@ -1,5 +1,5 @@ { - "name": "a", + "name": "js-a", "version": "0.0.0", "type": "module", "main": "index.js" diff --git a/tests/tests-workspaces/workspaces-js/js-b/esmock.js b/tests/tests-workspaces/workspaces-js/js-b/esmock.js new file mode 100644 index 00000000..87ab45dc --- /dev/null +++ b/tests/tests-workspaces/workspaces-js/js-b/esmock.js @@ -0,0 +1,4 @@ +export * from '../../../../src/esmock.js' +export {default} from '../../../../src/esmock.js' + +console.log('exportngf') diff --git a/tests/tests-workspaces/packages/b/index.js b/tests/tests-workspaces/workspaces-js/js-b/index.js similarity index 100% rename from tests/tests-workspaces/packages/b/index.js rename to tests/tests-workspaces/workspaces-js/js-b/index.js diff --git a/tests/tests-workspaces/packages/b/package.json b/tests/tests-workspaces/workspaces-js/js-b/package.json similarity index 74% rename from tests/tests-workspaces/packages/b/package.json rename to tests/tests-workspaces/workspaces-js/js-b/package.json index 8d3f7cb1..05296667 100644 --- a/tests/tests-workspaces/packages/b/package.json +++ b/tests/tests-workspaces/workspaces-js/js-b/package.json @@ -1,11 +1,11 @@ { - "name": "b", + "name": "js-b", "version": "0.0.0", "type": "module", "scripts": { "test": "node --test" }, "dependencies": { - "a": "^0.0.0" + "js-a": "^0.0.0" } } diff --git a/tests/tests-workspaces/workspaces-js/js-b/test.js b/tests/tests-workspaces/workspaces-js/js-b/test.js new file mode 100644 index 00000000..94d4b7da --- /dev/null +++ b/tests/tests-workspaces/workspaces-js/js-b/test.js @@ -0,0 +1,11 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import esmock from '../../../../src/esmock.js' + +test('works ootb', async () => { + const sut = await esmock('./index.js', { + 'js-a': { foo: () => 'bar' } + }) + + assert.equal(sut(), 'bar') +}) diff --git a/tests/tests-workspaces/workspaces-ts/ts-a/index.js b/tests/tests-workspaces/workspaces-ts/ts-a/index.js new file mode 100644 index 00000000..c970c823 --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-a/index.js @@ -0,0 +1,3 @@ +export function foo () { + return 'foo' +} diff --git a/tests/tests-workspaces/workspaces-ts/ts-a/package.json b/tests/tests-workspaces/workspaces-ts/ts-a/package.json new file mode 100644 index 00000000..b197b2fc --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-a/package.json @@ -0,0 +1,6 @@ +{ + "name": "ts-a", + "version": "0.0.0", + "type": "module", + "main": "index.js" +} diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/esmock.js b/tests/tests-workspaces/workspaces-ts/ts-b/esmock.js new file mode 100644 index 00000000..87ab45dc --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-b/esmock.js @@ -0,0 +1,4 @@ +export * from '../../../../src/esmock.js' +export {default} from '../../../../src/esmock.js' + +console.log('exportngf') diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/index.js b/tests/tests-workspaces/workspaces-ts/ts-b/index.js new file mode 100644 index 00000000..cd0f9ecb --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-b/index.js @@ -0,0 +1,5 @@ +import {foo} from 'a' + +export default function test () { + return foo() +} diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/package.json b/tests/tests-workspaces/workspaces-ts/ts-b/package.json new file mode 100644 index 00000000..0ba00655 --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "ts-b", + "version": "0.0.0", + "type": "module", + "scripts": { + "test": "node --loader=ts-node/esm --test test.ts" + }, + "dependencies": { + "ts-a": "^0.0.0" + }, + "devDependencies": { + "ts-node": "^10.9.1" + } +} diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/test.js b/tests/tests-workspaces/workspaces-ts/ts-b/test.js new file mode 100644 index 00000000..94d4b7da --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-b/test.js @@ -0,0 +1,11 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import esmock from '../../../../src/esmock.js' + +test('works ootb', async () => { + const sut = await esmock('./index.js', { + 'js-a': { foo: () => 'bar' } + }) + + assert.equal(sut(), 'bar') +}) diff --git a/tests/tests-workspaces/workspaces-ts/tsconfig.json b/tests/tests-workspaces/workspaces-ts/tsconfig.json new file mode 100644 index 00000000..5b17f4eb --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/tsconfig.json @@ -0,0 +1,8 @@ +{ + "esm": true, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node" + } +} From 863662467d32a5e2a94719c2069cc87beb64f8be Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 18:43:54 -0700 Subject: [PATCH 05/12] update workspaces tests --- tests/package.json | 3 ++- tests/tests-workspaces/package.json | 3 ++- tests/tests-workspaces/workspaces-js/js-b/index.js | 2 +- tests/tests-workspaces/workspaces-ts/ts-b/index.js | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/package.json b/tests/package.json index a6f77dde..63c715f9 100644 --- a/tests/package.json +++ b/tests/package.json @@ -43,6 +43,7 @@ "install:test-no-loader": "cd tests-no-loader && npm install", "install:test-nodets": "cd tests-nodets && npm install", "install:test-mocha": "cd tests-mocha && npm install", + "install:test-workspaces": "cd tests-workspaces && npm install", "install:all": "node --version && npm install && npm-run-all install:test*", "test:test-uvu": "cd tests-uvu && npm test", "test:test-mocha": "cd tests-mocha && npm test", @@ -55,7 +56,7 @@ "test:node18-test-nodets": "cd tests-nodets && npm test", "test:node18-test-source-map": "cd tests-source-map && npm test", "test:node18-test-no-loader": "cd tests-no-loader && npm test", - "test:node18-test-workspces": "cd tests-workspaces && npm test", + "test:node18-test-workspaces": "cd tests-workspaces && npm test", "test:node18:all": "npm run isnodelt18 || npm-run-all test:node18-test*", "test:all": "npm-run-all test:test* && npm run test:node18:all", "test:all-cover": "c8 --src=../src/* npm run test:all", diff --git a/tests/tests-workspaces/package.json b/tests/tests-workspaces/package.json index c6de0cf5..98077af2 100644 --- a/tests/tests-workspaces/package.json +++ b/tests/tests-workspaces/package.json @@ -5,9 +5,10 @@ "workspaces-ts/*" ], "scripts": { + "isnodelt20_6": "node -e \"(([mj, mn]) => (+mj < 20 || (+mj === 20 && +mn < 6)))(process.versions.node.split('.')) || process.exit(1)\"", "test-workspaces-js": "npm --prefix workspaces-js/js-b test", "test-workspaces-ts": "npm --prefix workspaces-js/js-b test", "test-workspaces": "npm run test-workspaces-js && npm run test-workspaces-ts", - "test": "npm run test-workspaces" + "test": "npm run isnodelt20_6 || npm run test-workspaces" } } diff --git a/tests/tests-workspaces/workspaces-js/js-b/index.js b/tests/tests-workspaces/workspaces-js/js-b/index.js index cd0f9ecb..cd6f8eba 100644 --- a/tests/tests-workspaces/workspaces-js/js-b/index.js +++ b/tests/tests-workspaces/workspaces-js/js-b/index.js @@ -1,4 +1,4 @@ -import {foo} from 'a' +import {foo} from 'js-a' export default function test () { return foo() diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/index.js b/tests/tests-workspaces/workspaces-ts/ts-b/index.js index cd0f9ecb..103d63b0 100644 --- a/tests/tests-workspaces/workspaces-ts/ts-b/index.js +++ b/tests/tests-workspaces/workspaces-ts/ts-b/index.js @@ -1,4 +1,4 @@ -import {foo} from 'a' +import {foo} from 'ts-a' export default function test () { return foo() From e4209573e114cf1d16a9e49098b97d160a3dd90e Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 19:51:28 -0700 Subject: [PATCH 06/12] fix workspaces-ts file arrangement --- package.json | 2 +- tests/tests-workspaces/package.json | 2 +- .../tests-workspaces/workspaces-ts/ts-b/{index.js => index.ts} | 0 tests/tests-workspaces/workspaces-ts/ts-b/{test.js => test.ts} | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename tests/tests-workspaces/workspaces-ts/ts-b/{index.js => index.ts} (100%) rename tests/tests-workspaces/workspaces-ts/ts-b/{test.js => test.ts} (87%) diff --git a/package.json b/package.json index bfb1bbd9..db0e6e3d 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "node": ">=14.16.0" }, "dependencies": { - "resolvewithplus": "^2.0.3" + "resolvewithplus": "^2.0.4" }, "devDependencies": { "c8": "^8.0.1", diff --git a/tests/tests-workspaces/package.json b/tests/tests-workspaces/package.json index 98077af2..3b91407d 100644 --- a/tests/tests-workspaces/package.json +++ b/tests/tests-workspaces/package.json @@ -7,7 +7,7 @@ "scripts": { "isnodelt20_6": "node -e \"(([mj, mn]) => (+mj < 20 || (+mj === 20 && +mn < 6)))(process.versions.node.split('.')) || process.exit(1)\"", "test-workspaces-js": "npm --prefix workspaces-js/js-b test", - "test-workspaces-ts": "npm --prefix workspaces-js/js-b test", + "test-workspaces-ts": "npm --prefix workspaces-ts/ts-b test", "test-workspaces": "npm run test-workspaces-js && npm run test-workspaces-ts", "test": "npm run isnodelt20_6 || npm run test-workspaces" } diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/index.js b/tests/tests-workspaces/workspaces-ts/ts-b/index.ts similarity index 100% rename from tests/tests-workspaces/workspaces-ts/ts-b/index.js rename to tests/tests-workspaces/workspaces-ts/ts-b/index.ts diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/test.js b/tests/tests-workspaces/workspaces-ts/ts-b/test.ts similarity index 87% rename from tests/tests-workspaces/workspaces-ts/ts-b/test.js rename to tests/tests-workspaces/workspaces-ts/ts-b/test.ts index 94d4b7da..f0d6d3f0 100644 --- a/tests/tests-workspaces/workspaces-ts/ts-b/test.js +++ b/tests/tests-workspaces/workspaces-ts/ts-b/test.ts @@ -4,7 +4,7 @@ import esmock from '../../../../src/esmock.js' test('works ootb', async () => { const sut = await esmock('./index.js', { - 'js-a': { foo: () => 'bar' } + 'ts-a': { foo: () => 'bar' } }) assert.equal(sut(), 'bar') From 582b1bb2dcf70157e791cdc608e265ad4d5d2538 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 19:52:45 -0700 Subject: [PATCH 07/12] remove esmock sketch file --- tests/tests-workspaces/workspaces-ts/ts-b/esmock.js | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 tests/tests-workspaces/workspaces-ts/ts-b/esmock.js diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/esmock.js b/tests/tests-workspaces/workspaces-ts/ts-b/esmock.js deleted file mode 100644 index 87ab45dc..00000000 --- a/tests/tests-workspaces/workspaces-ts/ts-b/esmock.js +++ /dev/null @@ -1,4 +0,0 @@ -export * from '../../../../src/esmock.js' -export {default} from '../../../../src/esmock.js' - -console.log('exportngf') From ed4dcd5155ed03d904b36900c1ee813c3508c531 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 19:57:59 -0700 Subject: [PATCH 08/12] added a local file test to workspaces-ts --- tests/tests-workspaces/workspaces-ts/ts-b/index.ts | 3 +++ tests/tests-workspaces/workspaces-ts/ts-b/local-file.ts | 1 + tests/tests-workspaces/workspaces-ts/ts-b/test.ts | 8 ++++++++ 3 files changed, 12 insertions(+) create mode 100644 tests/tests-workspaces/workspaces-ts/ts-b/local-file.ts diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/index.ts b/tests/tests-workspaces/workspaces-ts/ts-b/index.ts index 103d63b0..426e23a3 100644 --- a/tests/tests-workspaces/workspaces-ts/ts-b/index.ts +++ b/tests/tests-workspaces/workspaces-ts/ts-b/index.ts @@ -1,5 +1,8 @@ import {foo} from 'ts-a' +import localfile from './local-file.js' export default function test () { return foo() } + +export const localfilewrap = () => localfile() diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/local-file.ts b/tests/tests-workspaces/workspaces-ts/ts-b/local-file.ts new file mode 100644 index 00000000..6fd75c5f --- /dev/null +++ b/tests/tests-workspaces/workspaces-ts/ts-b/local-file.ts @@ -0,0 +1 @@ +export default () => 'local-value' diff --git a/tests/tests-workspaces/workspaces-ts/ts-b/test.ts b/tests/tests-workspaces/workspaces-ts/ts-b/test.ts index f0d6d3f0..6eb6f968 100644 --- a/tests/tests-workspaces/workspaces-ts/ts-b/test.ts +++ b/tests/tests-workspaces/workspaces-ts/ts-b/test.ts @@ -9,3 +9,11 @@ test('works ootb', async () => { assert.equal(sut(), 'bar') }) + +test('also mocks local file', async () => { + const { localfilewrap } = await esmock('./index.js', { + './local-file.js': () => 'local-value-mocked' + }) + + assert.equal(localfilewrap(), 'local-value-mocked') +}) From ecefd8d76a9808c2a38fb3db25081ddf237d7dc3 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 20:13:17 -0700 Subject: [PATCH 09/12] rename main.ts to main-ts.ts, so that resolver does not return main.js --- tests/local/main.ts | 7 ------- tests/tests-FAIL-swc/esmock.node-swc.test.ts | 4 ++-- tests/tests-FAIL-tsx/esmock.node.tsx.test.ts | 2 +- tests/tests-nodets/esmock.node-ts.test.ts | 3 +-- tests/tests-tsm/esmock.node-tsm.test.ts | 4 ++-- 5 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 tests/local/main.ts diff --git a/tests/local/main.ts b/tests/local/main.ts deleted file mode 100644 index aeb80a38..00000000 --- a/tests/local/main.ts +++ /dev/null @@ -1,7 +0,0 @@ -import path from 'path' -import pg from 'pg' - -export default { - pathbasenamewrap: (n: any) => path.basename(n), - pgpoolwrap: (n: any) => pg.Pool(n) -} diff --git a/tests/tests-FAIL-swc/esmock.node-swc.test.ts b/tests/tests-FAIL-swc/esmock.node-swc.test.ts index 0248852f..9b739f08 100644 --- a/tests/tests-FAIL-swc/esmock.node-swc.test.ts +++ b/tests/tests-FAIL-swc/esmock.node-swc.test.ts @@ -7,7 +7,7 @@ import esmock from 'esmock' // when the typescript sytax are removed, tests pass test('should mock ts when using node-ts', async () => { - const main = await esmock('../local/main.ts', { + const main = await esmock('../local/main-ts.ts', { path: { basename: () => 'hellow' } @@ -17,7 +17,7 @@ test('should mock ts when using node-ts', async () => { }) test('should mock pg', async () => { - const main = await esmock('../local/main.ts', { + const main = await esmock('../local/main-ts.ts', { 'pg': { Pool: (config:any) => { return config || 'mocked pool' diff --git a/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts b/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts index 3211030f..ac032abd 100644 --- a/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts +++ b/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts @@ -15,7 +15,7 @@ test('should mock js when using tsx', async () => { // tsx fails :/ https://github.com/esbuild-kit/tsx/issues/264 // // test('should mock ts when using tsx - unknown file extension', async () => { -// const main = await esmock('../local/main.ts', { +// const main = await esmock('../local/main-ts.ts', { // path: { // basename: () => 'hellow' // } diff --git a/tests/tests-nodets/esmock.node-ts.test.ts b/tests/tests-nodets/esmock.node-ts.test.ts index cca5049b..45571d3c 100644 --- a/tests/tests-nodets/esmock.node-ts.test.ts +++ b/tests/tests-nodets/esmock.node-ts.test.ts @@ -3,7 +3,7 @@ import assert from 'assert' import esmock from 'esmock' test('should mock ts when using node-ts', { only: true }, async () => { - const main = await esmock('../local/main.ts', { + const main = await esmock('../local/main-ts.ts', { path: { basename: () => 'hellow' } @@ -26,4 +26,3 @@ test('should mock import global at import tree w/ mixed esm cjs', async () => { assert.equal(consolelog.mock.calls[0].arguments[0], 'foo') assert.equal(consolelog.mock.calls[1].arguments[0], 'foo') }) - diff --git a/tests/tests-tsm/esmock.node-tsm.test.ts b/tests/tests-tsm/esmock.node-tsm.test.ts index 9c8085d9..5d591ba2 100644 --- a/tests/tests-tsm/esmock.node-tsm.test.ts +++ b/tests/tests-tsm/esmock.node-tsm.test.ts @@ -3,7 +3,7 @@ import assert from 'assert' import esmock from 'esmock' test('should mock ts when using node-ts', async () => { - const main = await esmock('../local/main.ts', { + const main = await esmock('../local/main-ts.ts', { path: { basename: () => 'hellow' } @@ -14,7 +14,7 @@ test('should mock ts when using node-ts', async () => { }) test('should mock pg', async () => { - const main = await esmock('../local/main.ts', { + const main = await esmock('../local/main-ts.ts', { 'pg': { Pool: (config:any) => { return config || 'mocked pool' From 029647f086b790d9fb663ac69d379335007619ca Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 20:20:08 -0700 Subject: [PATCH 10/12] git add local/main-ts.ts --- tests/local/main-ts.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/local/main-ts.ts diff --git a/tests/local/main-ts.ts b/tests/local/main-ts.ts new file mode 100644 index 00000000..aeb80a38 --- /dev/null +++ b/tests/local/main-ts.ts @@ -0,0 +1,7 @@ +import path from 'path' +import pg from 'pg' + +export default { + pathbasenamewrap: (n: any) => path.basename(n), + pgpoolwrap: (n: any) => pg.Pool(n) +} From 11907e8f55e940b1105207469456c701c38d1f67 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 20:53:36 -0700 Subject: [PATCH 11/12] update CHANGELOG, increment version number --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9764029..7d05728b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # changelog + * 2.5.1 _Sep.12.2023_ + * [resolve existing ".ts" files,](https://github.com/iambumblehead/esmock/pull/243) rather than ".js" files, when typescript detected * 2.5.0 _Sep.09.2023_ * [remove duplicate nextLoad call](https://github.com/iambumblehead/esmock/pull/239) * [add support for initialize hook](https://github.com/iambumblehead/esmock/pull/240) diff --git a/package.json b/package.json index db0e6e3d..9a9dde77 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "esmock", "type": "module", - "version": "2.5.0", + "version": "2.5.1", "license": "ISC", "readmeFilename": "README.md", "description": "provides native ESM import and globals mocking for unit tests", From 9591b4fe0f966e6f57de0436e24f49cd229c73ca Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 13 Sep 2023 12:30:21 -0700 Subject: [PATCH 12/12] credit @tpluscode --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d05728b..f407cd83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # changelog - * 2.5.1 _Sep.12.2023_ - * [resolve existing ".ts" files,](https://github.com/iambumblehead/esmock/pull/243) rather than ".js" files, when typescript detected + * 2.5.1 _Sep.13.2023_ + * [resolve existing ".ts" files,](https://github.com/iambumblehead/esmock/pull/243) rather than ".js" files, when typescript detected, thanks @tpluscode * 2.5.0 _Sep.09.2023_ * [remove duplicate nextLoad call](https://github.com/iambumblehead/esmock/pull/239) * [add support for initialize hook](https://github.com/iambumblehead/esmock/pull/240)