backstage/community-plugins

๐Ÿ› tech-insights: Using test-utils in production code causing error

ppiwow-apay opened this issue ยท 6 comments

Plugin Name

tech-insights

๐Ÿ“œ Description

I believe that production code shouldn't be dependent on mocks and test utils package.

๐Ÿ‘ Expected behavior

No need to depend on @backstage/backend-test-utils in production

๐Ÿ‘Ž Actual Behavior with Screenshots

Need to be dependent on: @backstage/backend-test-utils

https://github.com/backstage/community-plugins/blob/main/workspaces/tech-insights/plugins/tech-insights-backend/src/service/persistence/persistenceContext.ts#L40

๐Ÿ‘Ÿ Reproduction steps

Just update to newest version

๐Ÿ“ƒ Provide the context for the Bug.

No response

๐Ÿ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

๐Ÿข Have you read the Code of Conduct?

Are you willing to submit PR?

None

@secustor it is your change that introduces it in the newest version... is it something you wanted to achieve or just a mistake?

There is probably a null logger or a similar thing that can be used instead of mock.

This PR should address this issue: #787

We should make sure to include the error as others might be searching using that. For reference:

[1] /Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64
[1]     child: jest.fn().mockImplementation(createLoggerMock),
[1]            ^
[1] 
[1] 
[1] ReferenceError: jest is not defined
[1]     at createLoggerMock (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64:12)
[1]     at <anonymous> (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:406:7)
[1]     at Object.mock (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:114:18)
[1]     at Object.<anonymous> (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/plugins/tech-insights-backend/src/service/persistence/persistenceContext.ts:40:31)
[1]     at Module._compile (node:internal/modules/cjs/loader:1369:14)
[1]     at Module._compile (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/pirates/lib/index.js:117:24)
[1]     at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
[1]     at Object.newLoader [as .ts] (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/pirates/lib/index.js:121:7)
[1]     at Module.load (node:internal/modules/cjs/loader:1206:32)
[1]     at Module._load (node:internal/modules/cjs/loader:1022:12)
[1]     at Module.require (node:internal/modules/cjs/loader:1231:19)
[1]     at require (node:internal/modules/helpers:179:18)
[1]     at Object.<anonymous> (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/plugins/tech-insights-backend/src/service/persistence/index.ts:17:38)
[1]     at Module._compile (node:internal/modules/cjs/loader:1369:14)
[1]     at Module._compile (/Users/dweber019/Documents/ProjectPrivate/backstage-community-plugins/workspaces/tech-insights/node_modules/pirates/lib/index.js:117:24)
[1]     at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)

Did a quick update of the title to make it a bit more clear. Thanks for logging this @ppiwow-apay ๐Ÿ‘

same here, I updated the community plugins and having this error:

...
[1] //Repos/backstage/app/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64
[1]     child: jest.fn().mockImplementation(createLoggerMock),
[1]            ^
[1]
[1]
[1] ReferenceError: jest is not defined
[1]     at createLoggerMock (//Repos/backstage/app/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:64:12)
[1]     at <anonymous> (//Repos/backstage/app/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:406:7)
[1]     at Object.mock (//Repos/backstage/app/node_modules/@backstage/backend-test-utils/src/next/services/mockServices.ts:114:18)
[1]     at Object.<anonymous> (//Repos/backstage/app/node_modules/@backstage-community/plugin-tech-insights-backend/src/service/persistence/persistenceContext.ts:40:31)
[1]     at Module._compile (node:internal/modules/cjs/loader:1256:14)
[1]     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
[1]     at Object.newLoader [as .js] (//Repos/backstage/app/node_modules/pirates/lib/index.js:121:7)
[1]     at Module.load (node:internal/modules/cjs/loader:1119:32)
[1]     at Module._load (node:internal/modules/cjs/loader:960:12)
[1]     at Module.require (node:internal/modules/cjs/loader:1143:19)
[1]     at require (node:internal/modules/cjs/helpers:119:18)
[1]     at Object.<anonymous> (//Repos/backstage/app/packages/backend/src/plugins/techinsights.ts:25:31)
[1]     at Module._compile (node:internal/modules/cjs/loader:1256:14)
[1]     at Module._compile (//Repos/backstage/app/node_modules/pirates/lib/index.js:117:24)
[1]     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
[1]     at Object.newLoader [as .ts] (//Repos/backstage/app/node_modules/pirates/lib/index.js:121:7)

@secustor it is your change that introduces it in the newest version... is it something you wanted to achieve or just a mistake?

There is probably a null logger or a similar thing that can be used instead of mock.

That has been on purpose to keep the public API unchanged, but it seems like @backstage/test-utils has jest not defined as dependency even though it needs it.

And no there is no longer a VoidLogger.