backstage / community-plugins

Community plugins for Backstage
Apache License 2.0
157 stars 181 forks source link

🐛 tech-insights-backend: Forbidden dependency on @backstage/backend-test-utils #1715

Open rohitmishr opened 3 days ago

rohitmishr commented 3 days ago

🔖 Need

Issue: ReferenceError: jest is not defined

Context: We recently upgraded our Backstage version and created a custom TechInsights plugin. This plugin has a dependency on @backstage/backend-test-utils. When attempting to run yarn dev, we encounter the following error:

/Users/rxxxmxxxx/Documents/bug-fix-tech-insights/xyzz-idp-app/packages/backend/node_modules/@backstage-community/plugin-tech-insights-backend/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64 child: jest.fn().mockImplementation(createLoggerMock), ^

ReferenceError: jest is not defined at createLoggerMock (/Users/rxxxmxxxx/Documents/bug-fix-tech-insights/xyzz-idp-app/packages/backend/node_modules/@backstage-community/plugin-tech-insights-backend/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64)

Steps Taken:

  1. Upgraded Backstage version.
  2. Created a custom TechInsights plugin.
  3. Added @backstage/backend-test-utils as a dependency.
  4. Ran yarn dev.

Error Details:

Request for Help: Could anyone provide guidance on how to resolve this ReferenceError? Specifically, how can we ensure that jest is properly defined and available in the context of mockServices.ts?

🎉 Proposal

Issue: ReferenceError: jest is not defined Context: We recently upgraded our Backstage version and created a custom TechInsights plugin. This plugin has a dependency on @backstage/backend-test-utils. When attempting to run yarn dev, we encounter the following error:

/Users/rxxxmxxxx/Documents/bug-fix-tech-insights/xyzz-idp-app/packages/backend/node_modules/@backstage-community/plugin-tech-insights-backend/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64 child: jest.fn().mockImplementation(createLoggerMock), ^

ReferenceError: jest is not defined at createLoggerMock (/Users/rxxxmxxxx/Documents/bug-fix-tech-insights/xyzz-idp-app/packages/backend/node_modules/@backstage-community/plugin-tech-insights-backend/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64)

when we checked this repo link for latest @backstage/backend-test-utils but after doing yarn install and yarn dev we are getting jest not define.

〽️ Alternatives

No response

❌ Risks

No response

👀 Have you spent some time to check if this RFC has been raised before?

🏢 Have you read the Code of Conduct?

Rugvip commented 3 days ago

Are you seeing this error when importing @backstage/backend-test-utils in a test file? It is only intended to be used in tests, if it's imported in the main build it's expected that it breaks in this way.

rohitmishr commented 22 hours ago

when we are trying to run application via yarn dev then I am getting this jest not define.

The thing is we are not able to find mockservice.ts inside backend/node_modules.

when we tried to upgrade backstage version from 1.26 to 1.31 then we are getting this error.

rohitmishr commented 22 hours ago

And this is getting from plugin tech-insigths.

Rugvip commented 22 hours ago

I see that the tech-insights backend has a production dependency on backend-test-utils: https://github.com/backstage/community-plugins/blob/fdb08e6fe73cc3c0d2be8e37b059979a5cd2eb0c/workspaces/tech-insights/plugins/tech-insights-backend/package.json#L53

There's also no /testUtils entry point or similar, so that dependency shouldn't be there and is looking like a bug in the tech insights plugin. Gonna move this over to the community plugins repo for fixing there

awanlin commented 20 hours ago

Contributions to fix this welcome 👍