From 05d21546da5810b5e51090c2666b9fe4583fe0fd Mon Sep 17 00:00:00 2001 From: George White Date: Sat, 15 Jun 2024 10:17:20 +0100 Subject: [PATCH] Update test and README about tsx compatibility tsx has been compatible with other loaders since around the end of 3.x and the start of 4.x when the aforementioned issue https://github.com/privatenumber/tsx/issues/264 was resolved. Update the test to use a newer version of tsx which does not exhibit the bug and the README to say tsx is compatible. --- README.md | 2 +- tests/tests-FAIL-tsx/esmock.node.tsx.test.ts | 25 ------------------- tests/tests-tsx/esmock.node.tsx.test.ts | 23 +++++++++++++++++ .../package.json | 7 ++++-- .../tsconfig.json | 3 ++- 5 files changed, 31 insertions(+), 29 deletions(-) delete mode 100644 tests/tests-FAIL-tsx/esmock.node.tsx.test.ts create mode 100644 tests/tests-tsx/esmock.node.tsx.test.ts rename tests/{tests-FAIL-tsx => tests-tsx}/package.json (62%) rename tests/{tests-FAIL-tsx => tests-tsx}/tsconfig.json (67%) diff --git a/README.md b/README.md index 47dc9913..5fabe641 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ _**Note: For versions of node prior to v20.6.0,** "--loader" command line arguments must be used with `esmock` as demonstrated [in the wiki.][4] Current versions of node do not require "--loader"._ -_**Note: Typescript loaders** `ts-node` 👍 and `tsm` 👍 are compatible with other loaders, [including esmock.][3] `swc` 👎 and `tsx` 👎 are demonstrated as **incompatible** with other loaders, including esmock._ +_**Note: TypeScript loaders** `ts-node` 👍, `tsm` 👍 and `tsx` 👍 are compatible with other loaders, [including esmock.][3] `swc-node` has, at time of writing, been demonstrated as **incompatible** with other loaders, including esmock._ `esmock` has the below signature ```js diff --git a/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts b/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts deleted file mode 100644 index ac032abd..00000000 --- a/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import test from 'node:test' -import assert from 'assert' -import esmock from 'esmock' - -test('should mock js when using tsx', async () => { - const main = await esmock('../local/main.js', { - path: { - basename: () => 'hellow' - } - }) - - assert.strictEqual(main.pathbasenamewrap(), 'hellow') -}) - -// 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.ts', { -// path: { -// basename: () => 'hellow' -// } -// }) -// -// assert.strictEqual(main.pathbasenamewrap(), 'hellow') -// }) diff --git a/tests/tests-tsx/esmock.node.tsx.test.ts b/tests/tests-tsx/esmock.node.tsx.test.ts new file mode 100644 index 00000000..558f0a03 --- /dev/null +++ b/tests/tests-tsx/esmock.node.tsx.test.ts @@ -0,0 +1,23 @@ +import test from 'node:test' +import assert from 'assert' +import esmock from 'esmock' + +test('should mock js when using tsx', async () => { + const main = await esmock('../local/main.js', { + path: { + basename: () => 'hellow' + } + }) + + assert.strictEqual(main.pathbasenamewrap(), 'hellow') +}) + +test('should mock ts when using tsx', async () => { + const main = await esmock('../local/main-ts.ts', { + path: { + basename: () => 'hellow' + } + }) + + assert.strictEqual(main.pathbasenamewrap(), 'hellow') +}) diff --git a/tests/tests-FAIL-tsx/package.json b/tests/tests-tsx/package.json similarity index 62% rename from tests/tests-FAIL-tsx/package.json rename to tests/tests-tsx/package.json index 80ab97dd..2b1437bb 100644 --- a/tests/tests-FAIL-tsx/package.json +++ b/tests/tests-tsx/package.json @@ -7,9 +7,12 @@ }, "dependencies": { "esmock": "file:..", - "tsx": "^3.12.7" + "tsx": "^4.15.5" }, "scripts": { - "test": "node --loader=tsx --loader=esmock --test esmock.node.tsx.test.ts" + "test": "node --import=tsx/esm --test esmock.node.tsx.test.ts" + }, + "devDependencies": { + "@types/node": "^20.14.2" } } diff --git a/tests/tests-FAIL-tsx/tsconfig.json b/tests/tests-tsx/tsconfig.json similarity index 67% rename from tests/tests-FAIL-tsx/tsconfig.json rename to tests/tests-tsx/tsconfig.json index 5b17f4eb..266f26f0 100644 --- a/tests/tests-FAIL-tsx/tsconfig.json +++ b/tests/tests-tsx/tsconfig.json @@ -3,6 +3,7 @@ "compilerOptions": { "allowSyntheticDefaultImports": true, "module": "ESNext", - "moduleResolution": "node" + "moduleResolution": "node", + "lib": ["ES2015"] } }