-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Version 4.9.0 causes jest tests fail to run due to a SyntaxError #7944
Comments
Hi @slaweet. First if all, thank you for your detailed report.
Yes, I've realized that after 4.9.0 release. I've issued PR #7946 that will remedy the issue by using following jest config in "jest": {
"preset": "@vue/cli-plugin-unit-jest",
"transformIgnorePatterns": ["/node_modules/(?!(swagger-client|react-syntax-highlighter)/)"]
}
I've cloned the repo and verified that after the above mentioned PR is merged and
Some time ago, we switched our primary build fragment to be Pure ESM packageMore info about this is here and here. This is about ESM build fragmentsThis is our case. SwaggerUI is still technically More information about SwaggerUI build fragments and future plans is here: #7831 |
@char0n thank you for the update. I tried to use v4.10.0 and it's still failing with the same error. Can you re-open this or should I create a new issue? I've pushed the commit to my reproduction repo slaweet/swagger-ui-import-issue@34c7b5c so that you can try it out The output of
|
@slaweet did you use the jest config I've suggested in my previous comments? "transformIgnorePatterns": ["/node_modules/(?!(swagger-client|react-syntax-highlighter)/)"] |
@char0n I thought the |
I too am seeing this error, and One thing worth noting is that I'm using I have a small repo here: https://github.com/scottohara/swagger-ui-webpack Running
|
@scottohara I'm using swagger-ui in another project with typescript and |
Here is a patch that makes your tests work. It's usually a matter of configuration with jest. |
Many thanks, that was a great help. For anyone reading along that has a similar issue, the main changes in @char0n 's patch that resolves the issue are: In - preset: "ts-jest"
+ preset: "ts-jest/presets/js-with-ts" (Ref: https://kulshekhar.github.io/ts-jest/docs/getting-started/presets) In {
"compilerOptions": {
+ "allowJs": true |
For me, this was not working:
but this was: "transformIgnorePatterns": ["/node_modules/(?!(swagger*|react-syntax-highlighter)/)"] |
Unfortunately still seeing this using:
|
Still facing this issue in 4.12.0 |
Still facing the same in v4.14.2 |
Still facing same issue in v4.14.3 with react. any workaround? with transformIgnorePatterns also jest failing. |
I've just tested on create-react-app@5.0.1 and except some source map related warnings, I was able to build and run the app with SwaggerUI succussfuly. Regarding jest tests, after injecting following jest config into "jest": {
"transformIgnorePatterns": [
"/node_modules/(?!(swagger-ui-react|swagger-client|react-syntax-highlighter)/)"
]
}, If you use "jest": {
"transformIgnorePatterns": [
"/node_modules/(?!(swagger-ui|swagger-client|react-syntax-highlighter)/)"
]
}, |
Q&A (please complete the following information)
Describe the bug you're encountering
After upgrading to swagger-ui 4.9.0, my jest tests of a page that uses
import SwaggerUI from 'swagger-ui';
fail to run because of a SyntaxError (see full output below).To reproduce...
I've created a minimum reproduction repo: https://github.com/slaweet/swagger-ui-import-issue/. The repo contains 3 commits to illustrate the problem. (1) is a general basic app created with https://cli.vuejs.org/. (2) is adding the swagger-ui v4.8.1 which has no problem. (3) is changing the version of swagger-ui required to use the
^
caret version notation (^4.8.1), which causesyarn install
to install4.9.0
.Steps to reproduce the behavior:
git clone git@github.com:slaweet/swagger-ui-import-issue.git cd swagger-ui-import-issue yarn install yarn jest
Additionally, to see that there was no issue before v4.9.0, you can revert swagger-ui to v4.8.1 by running:
Expected behavior
Either there is some (package.json?) config that needs to be made so that running a jest test of a component that imports svagger-ui still works.
Or the release 4.9.0 should instead be 5.0.0, because switching to ESM (#7937) apparently is a breaking change. Using a major SemVer version would prevent the caret version notation from silently switching swagger-ui to that version.
Screenshots
Additional context or thoughts
The test output:
The text was updated successfully, but these errors were encountered: