Skip to content

Commit 7b1d138

Browse files
authored
chore(adoption-insights): migrate to Jest 30 (#3005)
Install Jest 30 peer dependencies as required by @backstage/cli 0.36.0 and fix test incompatibilities for Jest 30 and JSDOM 27. Signed-off-by: Jon Koops <jonkoops@gmail.com>
1 parent b1d7f9e commit 7b1d138

8 files changed

Lines changed: 2263 additions & 145 deletions

File tree

workspaces/adoption-insights/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@
4949
"@backstage/e2e-test-utils": "^0.1.2",
5050
"@backstage/repo-tools": "^0.17.0",
5151
"@changesets/cli": "^2.27.1",
52+
"@jest/environment-jsdom-abstract": "^30.3.0",
5253
"@playwright/test": "1.58.2",
54+
"@types/jest": "^30.0.0",
55+
"@types/jsdom": "^27.0.0",
56+
"jest": "^30.3.0",
57+
"jsdom": "^27.1.0",
5358
"knip": "^5.27.4",
5459
"node-gyp": "^9.0.0",
5560
"prettier": "^2.3.2",

workspaces/adoption-insights/plugins/adoption-insights-backend/src/controllers/EventApiController.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
AnalyticsEvent,
2424
} from '@backstage/core-plugin-api';
2525
import { QUERY_TYPES, QueryParams } from '../types/event-request';
26+
import type { AuditorServiceEvent } from '@backstage/backend-plugin-api';
2627
import { toEndOfDayUTC, toStartOfDayUTC } from '../utils/date';
2728
import { TechDocsCount, TopTechDocsCount } from '../types/event';
2829

@@ -70,8 +71,10 @@ const mockEvent: AnalyticsEvent = {
7071
};
7172

7273
describe('trackEvents', () => {
73-
let mockProcessIncomingEvents: jest.SpyInstance;
74-
let mockProcessorAddEvent: jest.SpyInstance;
74+
let mockProcessIncomingEvents: jest.Spied<
75+
(events: AnalyticsEvent[], auditEvent: AuditorServiceEvent) => void
76+
>;
77+
let mockProcessorAddEvent: jest.Spied<EventBatchProcessor['addEvent']>;
7578

7679
beforeEach(() => {
7780
controller = new EventApiController(
@@ -82,13 +85,10 @@ describe('trackEvents', () => {
8285
);
8386

8487
mockProcessIncomingEvents = jest.spyOn(
85-
controller,
86-
'processIncomingEvents' as keyof EventApiController,
87-
);
88-
mockProcessorAddEvent = jest.spyOn(
89-
mockProcessor,
90-
'addEvent' as keyof EventBatchProcessor,
91-
);
88+
controller as any,
89+
'processIncomingEvents',
90+
) as typeof mockProcessIncomingEvents;
91+
mockProcessorAddEvent = jest.spyOn(mockProcessor, 'addEvent');
9292

9393
req = {
9494
body: [{ action: 'click' }] as AnalyticsEvent[],

workspaces/adoption-insights/plugins/adoption-insights-backend/src/database/adapters/BaseAdapter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { Event } from '../../models/Event';
2121
import { mockServices } from '@backstage/backend-test-utils';
2222

2323
describe('BaseAdapter', () => {
24-
let infoLog: jest.SpyInstance;
25-
let errorLog: jest.SpyInstance;
24+
let infoLog: jest.Spied<typeof logger.info>;
25+
let errorLog: jest.Spied<typeof logger.error>;
2626
const logger = mockServices.logger.mock();
2727
const mockKnex = {
2828
returning: jest.fn().mockReturnThis(),

workspaces/adoption-insights/plugins/adoption-insights-backend/src/domain/EventBatchProcessor.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import { EventDatabase } from '../database/event-database';
2121
import { Event } from '../models/Event';
2222

2323
describe('EventBatchProcessor', () => {
24-
let mockRetryOrStoreFailedEvent: jest.SpyInstance;
24+
let mockRetryOrStoreFailedEvent: jest.Spied<
25+
EventBatchProcessor['retryOrStoreFailedEvent']
26+
>;
2527

2628
const mockInsertEvents = jest.fn();
2729
const mockInsertFailedEvent = jest.fn();

workspaces/adoption-insights/plugins/adoption-insights/src/components/CatalogEntities/__tests__/CatalogEntities.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,6 @@ describe('CatalogEntities', () => {
222222
it('should apply correct styling to table rows', () => {
223223
renderComponent();
224224
const rows = screen.getAllByRole('row').slice(1);
225-
expect(rows[0]).toHaveStyle({ backgroundColor: 'inherit' });
225+
expect(rows[0].style.backgroundColor).toBe('');
226226
});
227227
});

workspaces/adoption-insights/plugins/adoption-insights/src/components/Techdocs/__tests__/Techdocs.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ describe('Techdocs', () => {
174174

175175
it('should apply correct styling to table rows', () => {
176176
const rows = screen.getAllByRole('row').slice(1);
177-
expect(rows[0]).toHaveStyle({ backgroundColor: 'inherit' });
177+
expect(rows[0].style.backgroundColor).toBe('');
178178
});
179179
});

workspaces/adoption-insights/plugins/adoption-insights/src/components/Templates/__tests__/Templates.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ describe('Templates', () => {
176176
it('should apply correct styling to table rows', () => {
177177
renderComponent();
178178
const rows = screen.getAllByRole('row').slice(1);
179-
expect(rows[0]).toHaveStyle({ backgroundColor: 'inherit' });
179+
expect(rows[0].style.backgroundColor).toBe('');
180180
});
181181
});

0 commit comments

Comments
 (0)