Skip to content
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

Initial testing setup #100

Closed

Conversation

eyelidlessness
Copy link
Collaborator

This includes one example test (which I'll delete when I get around to actually fixing #96). The runner is a bit more complex than I anticipated (due to rsms/estrella#29), but I'm quite impressed with its performance! I hope it's alright I branched off v1.1.0, it's totally fine if you want to rebase to main.

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2021

⚠️ No Changeset found

Latest commit: 17357c1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "@example/*" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@vercel
Copy link

vercel bot commented Jan 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

microsite-examples – ./

🔍 Inspect: https://vercel.com/nmoo/microsite-examples/pyqpa7wnw
✅ Preview: Failed

microsite – ./site

🔍 Inspect: https://vercel.com/nmoo/microsite/nnj6wr4e0
✅ Preview: Canceled

@eyelidlessness
Copy link
Collaborator Author

Oh I meant to add... it wasn't entirely clear to me which bootstap command was correct, but nothing I tried could prevent the huge package-lock.json changes.

@eyelidlessness
Copy link
Collaborator Author

This is probably a wrap for me today, it’s puppy time again. But I wanted to also add that it’s not always clear to me when Actions are accessible so I’m going to include a screenshot showing I did get the expected red x/green check on the CI run in my fork:

DBC4180E-5225-47CD-9D9E-D18A0BFD9076 NICE

Copy link
Owner

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks great! Just a few changes I'd like to see.

packages/microsite/README.md Show resolved Hide resolved
@@ -50,7 +52,6 @@
"cosmiconfig": "^7.0.0",
"esbuild": "^0.8.16",
"execa": "^4.0.3",
"globby": "^11.0.1",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, I think globby needs to stay here. I think it got hoisted into the root? There is some logic in the cli that uses it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right! I'll add it back. And I'll look at adding a regression test so I don't make the same mistake again! :)

Incidentally, this is something that PNPM would catch. I've been meaning to investigate switching my projects over from Yarn since it's a dead end for me (they apply semi-mysterious patches to some dependencies for their Plug'N'Play alternative to node_modules, even if you opt out of PnP, which is also a security concern in my opinion).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp, glad I wanted to write a real non-example test. Turns out this setup doesn’t support tsconfig paths, which is probably gonna cause some pain with this directory structure. So I’m also looking into the solve for that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that would be a problem, yeah. Let me know if you get stuck.


3. Install dependencies for the monorepo: `npm install`.

4. Install and link dependencies in sub-packages: `npx lerna bootstrap`. <!-- Note for review: I actually have no idea which command is preferred here, each one I've tried has still produced changes to most or all `package-lock.json` files in the project. -->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not positive either. I think npx lerna bootstrap --hoist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that and it had an even bigger impact on the package locks. I'll go with that if it's what you prefer, and now it'll be documented so we're both doing the same flow!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the normal dev setup this is probably the preferred solution, in that it minimizes the hit to the file system. But I will note that it doesn’t play nice with npm install in the root package, because it wipes out most of the root lock file. This isn’t a problem I’ve had using Yarn with workspaces, because both tools know about each other’s hoist behavior. However another call to bootstrap does work. It’s just a somewhat slow operation.

Copy link
Owner

@natemoo-re natemoo-re Jan 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, weird. I would be open to using yarn if it would solve this, although I know you mentioned you prefer pnpm? Volta does manage your package managers (npm, yarn, etc), but it's probably best to stick with npm if possible.

Also I have my eye on turborepo to solve a lot of lerna headaches... Not the biggest lerna fan but it seems to be the least terrible option for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to recommend Yarn due to issues I mentioned here, even though I'm pretty familiar with it, and have even somewhat validated using it in a monorepo without any other tools. Most of my own projects are currently pinned to Yarn 1 to avoid those PnP issues, and I don't think there's a future where I'll want to migrate them to Yarn 2 because of those issues, so for my use Yarn is only viable as long as v1 is actively being maintained. The other alternative I mentioned in that comment, PNPM, also supports workspaces, so I would imagine it's also well positioned to play well in a monorepo.

I'm not familiar with Turborepo, so I can't speak to that. Another one I've wanted to look into is Rush, which is developed by Microsoft (they definitely do monorepos!), and supports NPM, PNPM, and Yarn.

@@ -15,7 +15,9 @@
"scripts": {
"prepare": "npm run build",
"prebuild": "node ./scripts/clean.js",
"build": "tsc -p tsconfig.json --skipLibCheck"
"build": "tsc -p tsconfig.json --skipLibCheck",
"test": "node ../../scripts/test.js --once",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to move these scripts to the monorepo root and have the script be responsible for running all the packages tests? That's usually how I see Jest setup in a monorepo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly happy to do that. I was considering doing that, but when I've worked with Jest on past projects it was so unbearably slow and false failure prone (the way it does "isolation" is horrifically stateful with any module that has side-effects on import) that I did everything I could to make it easy to run as few tests as possible during dev. I didn't even consider that case for this initial PR, so I have no problem with the naive solution being "just run everything". All the tools in use here are so fast anyway that it may even be good enough long term.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one concern I have with this as I’m trying to make the change is that it may not play nicely with any config difference between packages, as it’ll resolve to a different CWD. But I’ll see if I can make it work, I’m not giving up!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right that makes sense. I don't think I'm extending a base config between packages to keep them consistent. That's probably a good idea.

.nvmrc Show resolved Hide resolved
@natemoo-re
Copy link
Owner

natemoo-re commented Jan 23, 2021

@eyelidlessness I took a pass at implementing uvu tests. I was curious if there was a way to handle .ts tests without using ts-node (slow) or using Estrella to compile/write the tests to disk. I got a setup working with uvu -r @swc-node/register—want to take a look at #104? Specifically this commit.

@eyelidlessness
Copy link
Collaborator Author

@natemoo-re I'm glad you're looking at alternatives, because honestly I'm ready to throw my computer into the ocean and walk in after it, after struggling to get the changes in with Estrella. Unfortunately I'm seeing the same thing fail with @swc-node/register as I've seen with Estrella: importing... well, anything that would be tested. In the Estrella case, you can't use TSConfig paths (and nothing I've tried has worked without adding an additional transform, as tsconfig-paths doesn't appear to handle ESM. In the SWC case, it's apparently compiling to CJS and producing require calls rather than to ESM, which doesn't seem consistent with their docs.

I don't have any more steam for this today (which is a shame, I really thought I'd wrap up this review in ~1h and make some progress on #96 and my own project today, but if I've learned anything with frontend tooling, it's that everything is gonna not work until you wanna quit tech forever).

@natemoo-re
Copy link
Owner

Ugh, the tooling wormholes in Frontend are the worst. I'm going to take a pass at finishing this up so you can focus on some actual tests and not wrestling with the config. I'll be sure to write up some docs on how things are working.

Thanks so much for all the legwork on this!

@natemoo-re
Copy link
Owner

@eyelidlessness Couldn't have gotten this working without you!

I'm going to close this in favor of #104, which I got to respect ESM import. There are a few outstanding issues in the PR description. One is upstream—merged but not yet released. The other is on me to figure out how to rewrite TypeScript paths so that they don't have a .js extension, probably with rollup.

@natemoo-re natemoo-re closed this Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants