-
Notifications
You must be signed in to change notification settings - Fork 2
Redo component unit test migration #31
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
base: main
Are you sure you want to change the base?
Conversation
2681807 to
5b713b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fascinating approach, very interesting to learn this is possible. A couple questions:
- Does this not work with ESM? It looks you were converting to CJS; is that for consistency or because
imports don't respect subpath import definitions? - Does this work with Bun?
I was thinking that using TypeStrip was actually less constrained by any global switch of the code base (most of our source code is TypeStrip compatible), and more constrained by the tests themselves (that's where the biggest incompatilities with TS ESM exist, IIUC). That is, some existing tests still rely on mutating exports and some don't. Wouldn't it make sense for individual tests to reference './dist/' if they need to mutate exports ("test doubles"), and tests that don't need to do that can directly reference source? This would allow the tests to be transitioned over time to using source, with clear indication of which tests used source vs dist. And would remove the biggest blocker for us to be able to use TypeStrip SRTL.
| @@ -1,317 +0,0 @@ | |||
| /* eslint-disable @typescript-eslint/no-require-imports */ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we deleting this file (or the contents of it)? Is this a rename that I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe @Ethan-Arrowood is planning to bring it back after this lands. We discussed it and he said it would be fine to delete it for now to clear the slate for the redo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah for the sake of doing things right we can delete this new test file I created recently and add it back later following conventions.
I didn't so much convert to CJS as I just left them how them were in the harperdb repo (which was CJS). The subpath import patterns should work fine with imports. In fact the examples in the docs are all imports.
Good question! I will investigate.
We could certainly explore that approach, but I thought we had decided to run all unit tests against the CJS artifact we ship to users in |
Ah, I see, great.
Yeah, we have. And starting with tests using dist sounds good. But it is certainly not the ultimate goal, right? We do want to be able to run against source eventually. And so I think the crux question is what that transition looks like. If it is matter of making some fixes to the source code and then "flipping the switch" for the tests, then the |
Yes, agreed. So we could do this with subpath import patterns too, if we wanted to (I do!). Something like |
🔥 |
I made that change and tested it with bun. It all seemed to work! I also converted |
|
...although I wasn't seeing these CI errors locally. Will investigate. |
9929730 to
49d7a75
Compare
cacdc60 to
a870812
Compare
|
Strange. |
...so we don't have to use relative paths into dist/ in all of our unit tests
...to make it easier to use this in other tooling
I'm planning to add this to a code style doc, probably in CONTRIBUTING.md
...in preparation for adding a #src one too for things that want to require / import TypeStrip source code
...to test that the #src import alias pattern works
...which appears to help with the "#src" import alias pattern
...with import / require split on how they're handled. import is always TypeStrip, require is CJS by default, but TypeStrip when the "typestrip" Node condition is set. Component unit tests are all updated to use this, and some source code is to (just to make sure it's working).
...by moving the createReuseportFd stuff out to a CJS module that only exports the node-unix-socket stuff when not on a win32 platform
...to ensure we're pulling in compiled CJS when appropriate. Node 20 was having a hard time with some of these otherwise.
cfdf599 to
d585ad7
Compare
Still haven't figured out what's going on here. Works every time locally and with the same version of bun as in CI. |
Could be affected by the node version available during the run? I get various results depending on the node version I have available at the time of running |
|
Bun might need more specific scripts. Something like this? |
|
You may be running into the same issue I did... you just need more bun: |
Got a laugh reading out 'bun bun run' 😂 Still need to update the package.json imports and I get a segfault trying that :-/ https://bun.report/1.3.3/Mn1274e01cwjCqgggB___utuqnB______________2x8tjB_A2AA |
|
|
I do request that we don't overload this PR. If we can get unit tests running with Node.js lets just send it. That at least enables us to iterate on the core codebase more reliably. Adding Bun support is an awesome objective, but I hope not a requirement to get unit tests supported again here |
|
Yeah, I know I had asked about Bun earlier in this ticket, but I was specifically asking to verify that subpath imports would work with Bun, and we weren't heading in a direction that we would have to revert. But, I didn't intend to require this PR to add support for Bun. I guess if we want to add scripts, so it is easy to start seeing what failures exist for Bun, that's fine, but definitely shouldn't be a blocker (or block CI passing or anything). |
|
Just pull it from the workflow? |
|
Thanks for all of the suggestions and feedback, everyone! Bun absolutely does not need to hold this up. I mostly just wanted to make sure the environment discrepancy wasn't indicative of some deeper issue. It seems like it is not, and I have a good path forward there. Next I need to figure out what's up with the integration tests. |
It works and all tests pass locally, but I can't get it to work in CI and have already spent more time on it than is warranted for a nice-to-have for this particular PR
Alright, here's version 2.0 of how we might bring unit tests over from the harperdb repo.
Things to note:
distdir. So be sure to runnpm run buildbefore you run these tests (which you do vianpm run test:unit:all)./distdir), so this uses Node's subpath import patterns feature to accomplish that. Once we're in TypeStrip land and running unit tests against that, we can just change the target of that pattern inpackage.json.*.test.*filename pattern so no further renaming was needed.Let's take our time reviewing this so we don't have to redo it again. 😅