Open threepipes opened 1 year ago
Oh this is gold, spent days on this.
Thanks @threepipes for posting the solution. I also struggled to find the cause of the issue.
The straightforward solution is to simply not prettify the compilation output when processing the template. @lmiller1990, is there a use case for it in the context of this plugin? If not I'm happy to submit a PR to change this behavior (like this).
I guess the main reason to do this is for better stack traces/error messages. Although broken out of the box is definitely not ideal... should we just default to having prettier off? Any way to fix this so it works out of the box with formatting?
I reproduced the issue on this repo and tried to see what benefits the formatting with prettier brings by using Prettier 2 and making the test fail. With and without Prettier, the output is the same:
If I force an error in the template, then I can see an error in the output (location in the proxy render):
With Prettier:
Without Prettier:
But I don't know if this is helping a lot. Is it possible to analyse the compiled template in case of failure?
All this to say, offering the possibility to prettify the output of the template compiler might be unnecessary. If that's the case we can just solve the issue by always passing prettify:false
to the compileTemplate function.
Reproduction and the test result
https://github.com/threepipes/vue-jest-prettier-issue
What happened?
The
jest
test passes with prettier v2.8.8 but fails when updated to v3.0.0 or higher.Description
prettier
is invoked here through the compiler-sfc, butcompiler-sfc
doesn't impose any version restriction onprettier
, whereascomponent-compiler-utils
does. With the release ofprettier
v3, the interface has changed. As a result,vue-jest
fails to transform.vue
files properly.Error
Workaround
The issue can be avoided by modifying the Jest configuration settings as shown below:
https://github.com/vuejs/component-compiler-utils/blob/82a37174990e31eaec609887a0ec262f06b454dd/lib/compileTemplate.ts#L175