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

Proposal: share core rendering logic with @testing-library/svelte #3

Open
mcous opened this issue Dec 5, 2024 · 4 comments
Open

Proposal: share core rendering logic with @testing-library/svelte #3

mcous opened this issue Dec 5, 2024 · 4 comments

Comments

@mcous
Copy link

mcous commented Dec 5, 2024

👋 hey, I'm the maintainer over at @testing-library/svelte and I noticed y'all forked the core directory over to this repo! I think this makes a lot of sense; there's no need for the @testing-library/dom / fake event stuff in Vitest's browser mode, and you can get tighter integration with test hooks in a way that's harder to do in a test-runner agnostic library like @testing-library/svelte.

Before I saw this fork, I'd been toying with the idea exposing @testing-library/svelte/core as an entry point to provide:

  • Argument checking
  • DOM target preparation
  • Svelte-version-agnostic mounting logic and type signatures
  • A manual cleanup function

Originally the motivation was to help out with @threlte/test-renderer, but I think it could be helpful here, too. (See work-in-progress PR if you're curious)

If I was to move forward with the work of exposing @testing-library/svelte/core, would you be interested in replacing the duplicated logic in core directory of vitest-browser-svelte with a dependency on @testing-library/svelte?

P.S. I find myself directing users of @testing-library/svelte to Vitest's browser mode more and more, and we're about to start using it at my work, so if there's any maintenance help I can offer here in vitest-browser-svelte, let me know!

@sheremet-va
Copy link
Member

Hello! This package exists basically to provide a lightweight wrapper for screen.getBy* locators with the browser mode. This means we cannot depend on any testing-library package directly here because the browser mode already provides enough utilities to work with the DOM and we don't want to load extra scripts that will never be used.

At the time of creating this package, @testing-library/svelte depended on @testing-library/dom, so we couldn't use it directly - if it can provide a core functionality just to render the component and give the element, then I would gladly use it instead of maintaining a fork 😄

@sheremet-va
Copy link
Member

This package exists basically to provide a lightweight wrapper for screen.getBy* locators with the browser mode.

Another important reason is cleaning up before the test so we can show the preview, of course!

@mcous
Copy link
Author

mcous commented Dec 5, 2024

At the time of creating this package, @testing-library/svelte depended on @testing-library/dom, so we couldn't use it directly

Figured that might be the case, and very reasonable! I like the idea of splitting svelte-core and svelte into separate packages (though I may have to fight some Testing Library org release infra out of my direct control to do it). No good technical reason why it can't be split, though, so I'll give it a shot and report back

This package exists basically to provide a lightweight wrapper for screen.getBy* locators with the browser mode.

Another important reason is cleaning up before the test so we can show the preview, of course!

It's a very nice touch, for sure

@mcous
Copy link
Author

mcous commented Dec 26, 2024

Looks like I have a viable path forward on splitting the packages out! I'll move forward with splitting out the rendering core on a prerelease dist tag and open a preliminary PR here once that's done

Feel free to close this issue out if it's not helpful from a tracking standpoint

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

No branches or pull requests

2 participants