-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
tape
runner does not support ESM files
#514
Comments
You no longer need the experimental modules flag on node v13.2+, fwiw. Separately, on node 12, prior to v12.16, the experimental modules implementation is incomplete and/or broken. So, if you want to use ESM, you must use node |
Thanks — updating node.js would be ok for me, but I seem to be getting the same result on Continuing to test the example above:
|
Ah, here we go :-) ESM must be written in an As such, you'd currently have to pass a CJS file to the You can, of course, run all tape tests with I'm not sure how it'd be possible for the |
tape
runner does not support ESM files
The ES module imported by my actual project was in a dependency, so changing the file extensions or import syntax would have been tricky for sure. Instead, I was able to get this working well with the require = require('esm')(module);
const test = require('tape');
const foo = require('foo'); // 'foo' package contains references to ES modules
test('test', function(t) {
// ...
}); With that, the usual syntax works fine:
It seems to have some limitations with Thanks for looking into this! Feel free to close the issue; I don't think any fixes are necessary here except perhaps a tip in the docs? |
Nah, the |
Should we add a "known to be working example" to the README for ESM ? Something like We could also open a PR for |
@Raynos there's no way to conditionally use |
Wait wtf. I thought import function was just a global function you can check for with type of === undefined |
Absolutely not, it's syntax, not a function. |
Is there a Maybe this should be a dual package issue on the npm CLI |
No, there's not - but that's a good feature request for the node ESM modules implementation (although it wouldn't help us to support ESM in the versions already released). We could do some tricks with a different published package to make it work, perhaps. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I don't mean to confuse and also please ignore this :), but:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import |
@christiaanwesterbeek yes, that's syntax, not a function. You can use it anywhere, but it can only consume modules. |
Worse-case scenario, can't you publish two different runner implementations and let users trigger the right one depending on their environment? |
@cowwoc that would work if every user either had 100% CJS tests, or 100% ESM tests, but I doubt that will always be the case, since most packages will (and should) have both CJS and ESM files to test. |
@ljharb In that case, users would have to segment test runs in their build script. They'd run the tape-cjs runner for CJS files followed by tape-esm for ESM files. It's slightly annoying to end up with two separate outputs but it's a start (certainly better than not being able to run at all.) |
@cowwoc I suppose i'd be willing to accept a PR that added an option to |
Yes - also, |
@ljharb Okay, that's a bit of an issue. I guess we can concatenate the output from multiple runs somehow? And I guess we should expect a performance loss from multiple Another thing to consider: we're going to have to patch N different tape plugins versus updating the code once in |
I mean, you'd have to update all the tape dependencies anyways to support a different binary, or a different command line argument - the only way it'd avoid that work is if |
@ljharb We might be able to do that. If you Maybe you can surround |
That's certainly one alternative; something I'd prefer (but while more reliable, may not be as performant) to make a package that, given a path, determines the parse goal (CJS or ESM) and selects the appropriate loader. |
That is also a nice approach. Let users provide a regex indicating whether a match is CJS or ESM and go from there. I can see some people separating such code by directory name, others by filename extension. |
Nah, it wouldn't and shouldn't be user configurable - it'd be:
In other words, node, not users, determine what kind of file it is (based on how the user has named it and the user's package.json). |
Fine with me. |
Just a heads up that I published a very basic (30 lines of code) module that runs tests in isolation, one after the other, and works with ESM too. Nothing fancy but it works for me. In case it helps: https://github.com/small-tech/esm-tape-runner |
That’s roughly the same technique #547 will use; however, tape supports many node and browser versions beyond the ones that have async/await, or even Promises. |
Thanks for the validation :) And yeah, that’s why I thought I’d make a quick and separate module. Basically, just scratching my own itch but happy if it ends up scratching anyone else’s too. 🐾 |
This is fixed by #547. |
Reading #414 — which I realize is about writing Tape with ES modules, not testing ES modules — I found this suggestion:
#414 (comment)
Testing now, in node.js v12.9.1 and macOS, I'm getting a silent failure when trying to use that. For example:
Should this be supported? It may be worth noting that I also get no output running
tape -v
ortape -h
. I'm not sure if that indicates a problem with my environment.The text was updated successfully, but these errors were encountered: