Skip to content

Commit

Permalink
Update test and README about tsx compatibility
Browse files Browse the repository at this point in the history
tsx has been compatible with other loaders since around the end of 3.x
and the start of 4.x when the aforementioned issue
privatenumber/tsx#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.
  • Loading branch information
galexite committed Jun 15, 2024
1 parent 7d0f56d commit 05d2154
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions tests/tests-FAIL-tsx/esmock.node.tsx.test.ts

This file was deleted.

23 changes: 23 additions & 0 deletions tests/tests-tsx/esmock.node.tsx.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "node"
"moduleResolution": "node",
"lib": ["ES2015"]
}
}

0 comments on commit 05d2154

Please sign in to comment.