Skip to content

Cut back to minimal reproduction #1

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

Closed
wants to merge 1 commit into from
Closed

Cut back to minimal reproduction #1

wants to merge 1 commit into from

Conversation

mcous
Copy link

@mcous mcous commented Oct 11, 2024

@playerfine thanks for your removals! For future reference, I still wouldn't consider it a minimal reproduction, though. I spent a little time cutting out even more stuff while keeping the bug present.

In doing so, I found that the issue is not related to nx at all, but simply your particular monorepo structure. (Hence the value in getting to the truly minimal reproduction 😜)

I was also able to identify a workaround for the issue: add "@testing-library/svelte": "^5.2.3" to libs/counter/package.json:

  {
    "name": "@svelteunit/counter",
    "version": "0.0.1",
    "private": true,
-   "type": "module"
+   "type": "module",
+   "devDependencies": {
+     "@testing-library/svelte": "^5.2.3"
+   }
  }

This is the only change that is needed, you don't even have to re-run npm install. This, to me, suggests a potential bug in @sveltejs/vite-plugin-svelte's heuristics around when to apply the Svelte transform to .svelte.js files.

I'll dig a little more and file an issue with the Svelte team if I find something concrete. In the mean time, y'all may want to consider moving to a package manager with more robust monorepo support, like pnpm, which will allow you to define dev dependencies in the projects they're actually used in, but still maintain minimal installs and consistent versions

@playerfine
Copy link
Owner

playerfine commented Oct 11, 2024

@mcous my bad, I assumed this was a nx problem because I got it working without nx! Hence the reason why I didnt remove all the nx stuff

Your solutions seems to be working in your branch, but when I try to apply the same solution to my branch I get this error:

Error: Failed to load url /home/moba/projects/svelte5unittestingexample/node_modules/@testing-library/svelte/src/vitest.js (resolved id: /home/moba/projects/svelte5unittestingexample/node_modules/@testing-library/svelte/src/vitest.js). Does the file exist?

Do you have any clue on why this is happening?

Again thanks for you help! 😃

@mcous
Copy link
Author

mcous commented Oct 11, 2024

Yeah, interesting, I'm able to reproduce that as well. No clue why, so far!

In the meantime, you can workaround the second issue by using globals mode in Vitest (which you're already doing) and setting autoCleanup: false on the svelteTesting plugin, since globals mode makes that setting redundant

@playerfine
Copy link
Owner

Thanks, that seems to be working for now! If you make anymore progress let me know!

@mcous
Copy link
Author

mcous commented Oct 18, 2024

@playerfine I have tracked down the source of the Failed to load url error: your monorepo is set up such that Vite does not understand that the libs/counter project is part of a larger workspace. I found that this addition to the root package.json fixes the issue:

+ "workspaces": [
+   "./libs/*"
+ ]

If you use Vitest workspaces directly, this isn't an issue, because you can run Vitest from the monorepo root. However, since you're using NX instead of Vitest workspaces, NX will instead use libs/counter as the working directory / root and run Vitest inside that directory. In this latter case, the workspaces field in the root package.json tells Vite "you're allowed to find files in this directory"

@mcous
Copy link
Author

mcous commented Oct 18, 2024

Issue resolved! See: testing-library/svelte-testing-library#403 (comment)

@mcous mcous closed this Oct 18, 2024
@mcous mcous deleted the minimal-repro branch October 18, 2024 16:26
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