Skip to content

Commit 63f3368

Browse files
Copilotkobenguyent
andcommitted
Add README for tsx ESM test case
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent c1696b2 commit 63f3368

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# TypeScript tsx ESM Test
2+
3+
This test demonstrates the recommended way to use TypeScript with CodeceptJS 4.x when you have `"type": "module"` in your package.json.
4+
5+
## Key Features
6+
7+
- Uses `tsx/cjs` as the TypeScript loader (recommended over ts-node/esm)
8+
- Has `"type": "module"` in package.json
9+
- Imports page objects without file extensions
10+
- Everything works seamlessly
11+
12+
## Configuration
13+
14+
- **Loader**: `tsx/cjs` in `require` array
15+
- **Package type**: `"module"`
16+
- **TypeScript module**: `"esnext"` with `"node"` module resolution
17+
- **Imports**: No file extensions needed (tsx handles resolution)
18+
19+
## Why tsx?
20+
21+
tsx is the recommended TypeScript loader for CodeceptJS 4.x because:
22+
- ✅ Works with `"type": "module"`
23+
- ✅ Handles extensionless imports
24+
- ✅ Fast (built on esbuild)
25+
- ✅ Zero config needed
26+
- ✅ Compatible with Mocha's loading system
27+
28+
## Why Not ts-node/esm?
29+
30+
ts-node/esm has significant limitations:
31+
- ❌ Doesn't work with `"type": "module"`
32+
- ❌ Doesn't resolve extensionless imports to .ts files
33+
- ❌ Requires complex configuration
34+
- ❌ Module resolution doesn't work like standard TypeScript ESM
35+
36+
## Running This Test
37+
38+
```bash
39+
cd test/data/typescript-tsx-esm
40+
../../../bin/codecept.js run --verbose
41+
```
42+
43+
You should see both scenarios pass successfully.

0 commit comments

Comments
 (0)