backend-common: tweak package path resolution mock API

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-05 13:19:57 +02:00
parent b074053375
commit 289c224640
4 changed files with 53 additions and 31 deletions
@@ -22,22 +22,12 @@ import {
} from '@backstage/backend-test-utils';
import { appPlugin } from './appPlugin';
import { createRootLogger } from '@backstage/backend-common';
import { overridePackagePathResolution } from '@backstage/backend-common/testUtils';
const mockDir = createMockDirectory();
jest.mock('../../../../packages/backend-common/src/paths', () => {
const actual = jest.requireActual(
'../../../../packages/backend-common/src/paths',
);
return {
...actual,
resolvePackagePath: (pkg: string, ...args: string[]) => {
if (pkg === 'app') {
return mockDir.resolve(...args);
}
return actual.resolvePackagePath(pkg, ...args);
},
};
overridePackagePathResolution({
packageName: 'app',
path: mockDir.path,
});
// Make sure root logger is initialized ahead of FS mock
@@ -17,7 +17,7 @@ import {
getVoidLogger,
PluginEndpointDiscovery,
} from '@backstage/backend-common';
import { createPackagePathMock } from '@backstage/backend-common/testUtils';
import { overridePackagePathResolution } from '@backstage/backend-common/testUtils';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import request from 'supertest';
@@ -46,8 +46,8 @@ const testDiscovery: jest.Mocked<PluginEndpointDiscovery> = {
const mockPublishDir = createMockDirectory();
createPackagePathMock({
name: '@backstage/plugin-techdocs-backend',
overridePackagePathResolution({
packageName: '@backstage/plugin-techdocs-backend',
paths: {
'static/docs': mockPublishDir.path,
},