Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test and README about tsx compatibility #305

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"install:test-ava": "cd tests-ava && npm install",
"install:test-uvu": "cd tests-uvu && npm install",
"install:test-tsm": "cd tests-tsm && npm install",
"install:test-tsx": "cd tests-tsx && npm install",
"install:test-node": "cd tests-node && npm install",
"install:test-jest": "cd tests-jest && npm install",
"install:test-jest-ts": "cd tests-jest-ts && npm install",
Expand All @@ -49,8 +50,10 @@
"test:test-uvu": "cd tests-uvu && npm test",
"test:test-mocha": "cd tests-mocha && npm test",
"test:test-ava": "cd tests-ava && npm test",
"test:test-tsx": "cd tests-tsx && npm test",
"test:node19-tsm": " cd tests-tsm && npm test",
"test:node18-test-tsm": "npm run isnodenight || npm run test:node19-tsm",
"test:node18-test-tsx": "cd tests-tsx && npm run test",
"test:node18-test-node": "cd tests-node && npm test",
"test:node18-test-jest": "cd tests-jest && npm test",
"test:node18-test-jest-ts": "cd tests-jest-ts && npm test",
Expand Down
25 changes: 0 additions & 25 deletions tests/tests-FAIL-tsx/esmock.node.tsx.test.ts

This file was deleted.

15 changes: 0 additions & 15 deletions tests/tests-FAIL-tsx/package.json

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')
})
21 changes: 21 additions & 0 deletions tests/tests-tsx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "module",
"description": "esmock unit tests, tsx with node",
"repository": {
"type": "git",
"url": "https://github.com/iambumblehead/esmock.git"
},
"dependencies": {
"esmock": "file:..",
"tsx": "^4.15.5"
},
"scripts": {
"isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"",
"test:loader": "node --loader=tsx/esm --loader=esmock --test esmock.node.tsx.test.ts",
"test:current": "node --import=tsx/esm --test esmock.node.tsx.test.ts",
"test": "npm run isloaderavailable && npm run test:loader || npm run test:current"
},
"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"]
}
}
Loading