swagger-api / swagger-api/swagger-ui

Having issues with jest testing going from swagger-ui-react 4.19.1 to 5.X cannot find module '#swagger-ui'

Open
#10,149 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: WSL Ubuntu 22.04 Windows 10
  • Browser: Chrome
  • Version: 129.0.6668.59
  • Method of installation: npm install
  • Swagger-UI version: 5.X in general but as of now 5.17.14
  • Swagger/OpenAPI version: OpenAPI 3.0
Screenshots

image

How can we help?

Snippet of my code that I am testing:

import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';

When I was running create react app (react-scripts 5.0.1) and jest with swagger-react-ui 4.19.1 I had no issues with jest rendering the SwaggerUI component from swagger-ui-react. Everything ran and the tests all passed.

Due to a security vulnerability in 4.19.1 I am being forced to upgrade to swagger-react-ui 5.X (currently trying the latest which is 5.17.14 as of writting this.

When I run jest it looks like it's trying to pull from the node_modules/swagger-ui-react/index.cjs which is what i'd expect... however within that file there is a line that looks like this:

var _swaggerUi = _interopRequireDefault(require("#swagger-ui"));

This is where jest cannot find #swagger-ui module.

I would like to say that as far as my react-app goes everything runs just fine, it's ONLY testing with jest do i get this issue.

Any help is appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with Jest, create-react-app/react-scripts 5.0.1, and swagger-ui-react 5.17.14 using the imports shown. Inspect node_modules/swagger-ui-react/index.cjs, especially its require("#swagger-ui") line, and compare this behavior with version 4.19.1. Done means the SwaggerUI component can render in the Jest tests after upgrading to 5.X.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.