-
Notifications
You must be signed in to change notification settings - Fork 33
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
jest-transform-svelte is a bit funky #33
Comments
Got any alternatives? Not sure if there's a call to action here but happy to discuss. |
There aren't many options sadly. The only updated ones all use I came across this problem when I was trying to write some testing documentation so I wrote the transform found in |
hmm, ok. well closing for now, if you think of any options, feel free to re-open. |
There is an option for this. Instead use
Then, include a .babelrc file with the next config:
npm run test ("test": "jest src", inside scripts) and has to work!! |
Shold the docs be updated with this suggestion? I was not able to get it to work with the documentation but this worked |
Hey @felipesere I'm not seeing the difference? What was suggested is taken from the docs, except we suggest a transformer now that also supports preprocessors. If you're referring to what silvestrevivo suggested. |
Oh you might be referring to the the |
We will probably release an official Svelte transform at some point and point people to that from the Svelte docs. This way we won't need to rely on third parties for maintenance or proper documentation. I've personally spent a great deal of time supporting users using transforms that aren't fit for purpose so this will probably happen when we sort out some better documentation around testing. The transform mentioned (twice) in this issue worked from the beginning with no issues and continues to do so. |
If you're referring to svelte-test then the reason I didn't link to that is a few issues:
I also found |
The reason I wrote the svelte-test transform was to specifically work with preprocessors (without relying on node bindings) without bundling, which it does (I've been using it like this for over 6 months now). I'd need a repro to know why that might not be the case. Using the jest config file is the defacto way to pass options to jest transforms because you have access to the config in the preprocess method. Using a non-standard |
I'd love an official one and happy to contribute :) I wasn't referring to passing options to the transform through the config, but that the options in I would definitely not put I do believe though the transformer should be able to load from the shared config or be passed in as an option, which I'll add in. |
I've been trying svelte-jest and svelte-test and both seem to not really work. I get errors like this: |
|
Locking this thread. For any new readers feel free to use |
The recommended Jest transform
jest-transform-svelte
, has a few issues that make it hard to recommend to svelte community.The first issue is that it uses
deasync
to bundle using rollup in the transform. This is necessary because rollup's bundling is asynchronous but Jest transforms only support synchronous code. The issue withdeasync
is that is usesnode-gyp
which often causes problems for users running the windows operating system. Debugging problems withdeasync
(due tonode-gyp
) can be difficult and time-consuming for users.The second issue is that there is no easy way to hook into the svelte and node-resolve plugins that
jest-transform-svelte
uses to bundle the code, this makes passing custom compiler options and svelte preprocessors very difficult (if it is possible at all).The solution to both of these issues is to just use the
svelte.compile
method directly , compiling tocjs
, allowing node to do its own thing regarding module resolution. This doesn't solve the use of custom preprocessors (which are asynchronous) but I have written a Jest transform that supports svelte preprocessors and custom compiler options. The solution is also a touch hacky but it uses only node APIs and doesn't require the use ofnode-gyp
so it should give more consistent behaviour in different environments. Many production applications use svelte preprocessors (for sass/ less -> CSS usually but increasingly TS -> JS) and the lack of support for these in any transform make it essentially unusable for those users.I don't have any strong recommendations here, just letting you know that the current transform has a few issues and a few limitations that won't present themselves until you try to configure the compilation process or test in a variety of environments.
The text was updated successfully, but these errors were encountered: