-
Notifications
You must be signed in to change notification settings - Fork 26
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
ESM support #29
ESM support #29
Conversation
Hi @giltayar! Did you by chance see this PR on teenytest by @jkrems? testdouble/teenytest#53 Since you are many steps ahead of me in understanding how Node's ESM support works, if you're game to help make teenytest support what you need, I'd really really appreciate it (I'd be loathe to add a second test runner to this project) |
@searls Funnily enough, I was the one that implemented ESM for Mocha (mochajs/mocha#4038), and it was not easy there, but I guess it could be easier in teenytest, due to it being... teeny. I looked at the PR, and interestingly enough, it uses a similar approach that I took in loading ESM: But I'm game if you're game, and if @jkrems is OK with me continuing with the PR. Assuming it's OK to drop Node versions <8 (which it should be, because they are officially not supported anyway). I'd love it if you could look at the rest of the code, and the changes I noted in the PR description to see if you're OK with them. In any case, I've already started working on |
Hahah, I'm sure he's ok since he expressly said it was a starting point to help us down that direction. I'm also fine with dropping non-LTS Nodes. Thank you for looking at it! I did a quick review of the code and I think it looks great. I appreciate how thorough you were in mimicking the existing style and shape of the codebase |
Thanks. Will start sometime this week. (As for code-style. You wouldn't believe how hard it is for me to use |
BTW, there are a lot of cool "loader" techniques I used in that codebase. Definitely worth a blog post somteimes. |
@searls I replaced Mocha with teenytest. But! To make the tests pass you need to merge the PR in teenytest (testdouble/teenytest#57) and publish the module (which it itself is dependenant on another PR testdouble/function-names-at-line#3 which needs to be merged and published) |
Ok! now that I've published the two depended libraries, try updating this one to your liking? |
I see we have a problem with Node v8, because |
Oh, no. Wait. The problem is also in teenytest. Do we want to support Node v8? |
@searls: for this to pass, you need to merge (and publish) another PR: testdouble/teenytest#58 (this brings back to teenytest support for Node v8, which I broke inadvertently) |
Ok, [email protected] should fix you. Would have hand-merged this but wasn't 100% sure you thought it was ready to go p.s. @pingortle, I flagged this as obviating your #24 PR |
Landed in 0.6.0 |
Woopeee! I've started working on testdouble.js. Looking good, but I'll need a few more days. |
Node.js Native ES module support for quibble
Finished implementing and testing quibble support for Node.js ESM. The support adds two functions:
quibble.esm
: an async function that enables mocking named exports (second argument) and default export (third argument) in the same wayquibble
does. See below for reasons why this function is async.quibble.esmImportWithPath
: an async function that imports the module, but also returns the path to it. Will be used in thetestdouble.js
implementation to get at the named/default exports so they can be imitated (see below for proposed implementation oftd.replaceEsm
.The reason that
quibble.esm
is that I found a really cool way of resolving the real path of an import (this works only if you're a loader), and it works only if you "dummy import" the module, which needs to be async. But I believe this is fine becausetd.replaceEsm
needs to be async anyway due to it having to import the module (see draft code below).Draft code for
testdouble.js
implementation oftd.replaceEsm
:Notes for PR
--loader
, failed (bugs will be opened in Node.js), and just installed mocha (and chai with it)example-esm
with same functionality asexample
config({defaultFakeCreator})
(not used intestdouble.js
)Fixes #24