(@wdio/cli): corrected TypeScript loading#10816
(@wdio/cli): corrected TypeScript loading#10816christian-bromann merged 2 commits intowebdriverio:mainfrom
Conversation
…on GitHub Windows runner
|
Great work on this @jan-molak! |
|
Thanks, @nextlevelbeard!
I added a separate test file to limit issues like that, but if you know of a better way to do it I'm happy to review the proposed approach! The main advantage of TS Node is that everything happens in memory. Unfortunately, it's also a big challenge from the testing perspective as there's no source map file we could check and are limited to looking at what comes out the other side... |
christian-bromann
left a comment
There was a problem hiding this comment.
I have been adding this because it was the only way to use ESM import statement with TypeScript in an CJS project. Anyway, @erwinheitzman has mentioned issues with this too so happy to revert it.
Thanks 👍
Yeah, it looks like mixing CJS and ESM is quite a challenge. I'm starting to understand @sindresorhus with pure ESM approach. Maybe that's what we should consider for WebdriverIO 9 and Serenity/JS 4 ;-) |
Proposed changes
Change 4292733 introduced a regression where TypeScript files get loaded using both
-r ts-node/registerAND--loader ts-node/esm/transpile-only, preventing source maps from working correctly:webdriverio/packages/wdio-cli/src/commands/run.ts
Line 180 in 54cbada
Even though one part of ts-node documentation seems to indicate that specifying both flags should be supported, another part talks about specifying only one of the flags at the time.
Looking at the source code of
ts-node/esm/transpile-only, we can see that the methodregisterAndCreateEsmHooksalready callsregister(opts), which means specifying the flag-r ts-node/registeris redundant.From what I've observed, using both flags results in TS Node incorrectly mapping the resulting JavaScript to the original TypeScript, which means that stack traces point to incorrect lines.
I've modified
@wdio/clirunning locally on a CJS project to remove thets-node/registerflag and the stack traces started to work correctly again.Types of changes
Checklist
Further comments
Reviewers: @webdriverio/project-committers