Skip to content

Commit ad0d538

Browse files
Merge pull request #305 from galexite/tsx-is-now-compatible
Update test and README about tsx compatibility
2 parents 7d0f56d + cdd1292 commit ad0d538

File tree

7 files changed

+50
-42
lines changed

7 files changed

+50
-42
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
_**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"._
1515

16-
_**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._
16+
_**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._
1717

1818
`esmock` has the below signature
1919
```js

tests/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"install:test-ava": "cd tests-ava && npm install",
3838
"install:test-uvu": "cd tests-uvu && npm install",
3939
"install:test-tsm": "cd tests-tsm && npm install",
40+
"install:test-tsx": "cd tests-tsx && npm install",
4041
"install:test-node": "cd tests-node && npm install",
4142
"install:test-jest": "cd tests-jest && npm install",
4243
"install:test-jest-ts": "cd tests-jest-ts && npm install",
@@ -49,8 +50,10 @@
4950
"test:test-uvu": "cd tests-uvu && npm test",
5051
"test:test-mocha": "cd tests-mocha && npm test",
5152
"test:test-ava": "cd tests-ava && npm test",
53+
"test:test-tsx": "cd tests-tsx && npm test",
5254
"test:node19-tsm": " cd tests-tsm && npm test",
5355
"test:node18-test-tsm": "npm run isnodenight || npm run test:node19-tsm",
56+
"test:node18-test-tsx": "cd tests-tsx && npm run test",
5457
"test:node18-test-node": "cd tests-node && npm test",
5558
"test:node18-test-jest": "cd tests-jest && npm test",
5659
"test:node18-test-jest-ts": "cd tests-jest-ts && npm test",

tests/tests-FAIL-tsx/esmock.node.tsx.test.ts

-25
This file was deleted.

tests/tests-FAIL-tsx/package.json

-15
This file was deleted.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import test from 'node:test'
2+
import assert from 'assert'
3+
import esmock from 'esmock'
4+
5+
test('should mock js when using tsx', async () => {
6+
const main = await esmock('../local/main.js', {
7+
path: {
8+
basename: () => 'hellow'
9+
}
10+
})
11+
12+
assert.strictEqual(main.pathbasenamewrap(), 'hellow')
13+
})
14+
15+
test('should mock ts when using tsx', async () => {
16+
const main = await esmock('../local/main-ts.ts', {
17+
path: {
18+
basename: () => 'hellow'
19+
}
20+
})
21+
22+
assert.strictEqual(main.pathbasenamewrap(), 'hellow')
23+
})

tests/tests-tsx/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"type": "module",
3+
"description": "esmock unit tests, tsx with node",
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/iambumblehead/esmock.git"
7+
},
8+
"dependencies": {
9+
"esmock": "file:..",
10+
"tsx": "^4.15.5"
11+
},
12+
"scripts": {
13+
"isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"",
14+
"test:loader": "node --loader=tsx/esm --loader=esmock --test esmock.node.tsx.test.ts",
15+
"test:current": "node --import=tsx/esm --test esmock.node.tsx.test.ts",
16+
"test": "npm run isloaderavailable && npm run test:loader || npm run test:current"
17+
},
18+
"devDependencies": {
19+
"@types/node": "^20.14.2"
20+
}
21+
}

tests/tests-FAIL-tsx/tsconfig.json renamed to tests/tests-tsx/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerOptions": {
44
"allowSyntheticDefaultImports": true,
55
"module": "ESNext",
6-
"moduleResolution": "node"
6+
"moduleResolution": "node",
7+
"lib": ["ES2015"]
78
}
89
}

0 commit comments

Comments
 (0)