testing-library / svelte-testing-library

:chipmunk: Simple and complete Svelte DOM testing utilities that encourage good testing practices
https://testing-library.com/docs/svelte-testing-library/intro
MIT License
608 stars 34 forks source link

fix: ensure fireEvent is exported #339

Closed mcous closed 3 months ago

mcous commented 3 months ago

Overview

328 moved exports from pure.js to index.js and switched everything to wildcard exports:

https://github.com/testing-library/svelte-testing-library/blob/0593819ca0e083eadf536d20d9d61944d594fb91/src/index.js#L15-L16

If two wildcard exports emit the same export, neither will be included.

There is also export * from "mod", although there's no import * from "mod". This re-exports all named exports from mod as the named exports of the current module, but the default export of mod is not re-exported. If there are two wildcard exports statements that implicitly re-export the same name, neither one is re-exported.

This means the current release on next is not exporting fireEvent. This PR moves the STL exports back to named exports to resolve the bug

Observing the bug

pnpm add -D svelte @testing-library/svelte@next
node
> const stl = await import('@testing-library/svelte')
> stl.fireEvent
undefined

Why didn't tests catch this?

Vite/Vitest appears to resolve exports differently from local files compared to node_modules. Since the test suite imports directly from src/index.js, the behavior is slightly different:

In our case, since export * from '@testing-library/dom' is listed second, that means the tests are running with the vanilla fireEvent, and coincidentally passing because a no-op await in the test was enough of a wait for Svelte to flush pending changes.

Without a more sophisticated test suite that packs and installs the library into example projects (which is a good long term idea!) this particular problem is hard to guard against with unit tests.

Change log

mcous commented 3 months ago

@yanick did you see this one? Relatively bad regression on the next tag

yanick commented 3 months ago

yup. was waiting for the other branch to be merged.

github-actions[bot] commented 3 months ago

:tada: This PR is included in version 4.2.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: