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
Getting tape working with TypeScript and/or ESM #595
Comments
tape just runs node, so the only extensions it understands by default are js, cjs, or mjs - so if you want jsx/tsx/ts to work directly, you'll have to |
@EvHaus have you had any progress on using a loader here, or transpiling beforehand? |
I haven't spent any more time with it. Would you recommend the transpiling route or the |
For performance, I'd recommend pre-transpiling; for DX, ts-node. It might be good to do both, because the delta wouldn't be due to tape. |
I just turned my tests into TypeScript and in my case it was as easy as:
Not great because it requires running TypeScript first, but in my case I was already doing it: fregante/text-field-edit#29 |
Got it working. The trick was to:
|
Glad you got it working! type module just makes things worse anyways :-) |
You got it working by not doing what the issue suggested. Now it's not ESM anymore. It'd be good to keep the issue open. Likewise in my case it worked by not having TS anymore. |
Removing type module means that only @fregante maybe i'm confused, help me understand why this should be open and what we need to fix? |
Documenting how to deal with ESM/TS given that all the tries with ts-node above failed |
@fregante if you know the answer to that, a PR to the docs would be most helpful :-) I prefer to avoid native ESM or native TS, so I'm not the expert here. |
@ljharb Would you be able to provide a (non working) example of running tape using node and passing nodes The documentation mentions the
|
@darcyrush that sounds like a great idea to add to https://github.com/tape-testing/tape/tree/HEAD/example ! Specifically, it's something like |
@ljharb Thank you for the example. I tried to get I tried the following;
With import { pathToFileURL } from "node:url";
import { register } from "node:module";
register("ts-node/esm", pathToFileURL("./")); I thought that would transpile to JS before reaching tape, but I'm still not really sure about how the 'piping' works. |
I'm trying to add
tape
to https://github.com/EvHaus/test-runner-benchmarks as a follow up to @ljharb's Twitter post here, but I'm having a really hard time figuring out how to get it to work with a Typescript codebase.My test file looks like this:
And my
package.json
has"type": "module"
set.1st Attempt (
tape
)If I run:
I get:
2nd Attempt (
ts-node
)If I switch to
ts-node
and use:I get:
3rd Attempt (
ts-node --esm
)If I try with
ts-node --esm
, ala:I get:
4th Attempt (
tape-es
)If I try with tape-es:
I get:
5th Attempt (
ts-node
&tape-es
)If I combine
ts-node
andtape-es
, ala:I get:
I know how much you hate the ESM drama, but I'm out of ideas and I'd really love to add
tape
to the benchmarks (so it can also serve as possible documentation for those who want to try it). Any pointers?The text was updated successfully, but these errors were encountered: