Add overrideTargetPaths test utility and fix rebase issues

Adds `overrideTargetPaths` to `@backstage/cli-common/testUtils` for
cleanly mocking `targetPaths` in tests without `jest.mock` or
`jest.spyOn`. Migrates all existing test mocks to use the new utility.

Also fixes translations module imports broken by the rebase.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Patrik Oldsberg
2026-02-23 14:20:59 +01:00
parent 553e727d5f
commit ebc01ef04d
18 changed files with 210 additions and 121 deletions
+5 -13
View File
@@ -22,14 +22,18 @@ import createApp from './createApp';
import { findOwnPaths, targetPaths } from '@backstage/cli-common';
import { tmpdir } from 'node:os';
import { createMockDirectory } from '@backstage/backend-test-utils';
import { overrideTargetPaths } from '@backstage/cli-common/testUtils';
jest.mock('./lib/tasks');
const MOCK_TARGET_DIR = '/mock/target-dir';
const MOCK_TARGET_ROOT = '/mock/target-root';
overrideTargetPaths({ dir: MOCK_TARGET_DIR, rootDir: MOCK_TARGET_ROOT });
jest.mock('@backstage/cli-common', () => {
const pathModule = require('node:path');
const actual = jest.requireActual('@backstage/cli-common');
const MOCK_CREATE_APP_ROOT = '/mock/create-app-root';
const MOCK_TARGET_DIR = '/mock/target-dir';
const mockOwnPaths = {
resolve: (...paths: string[]) =>
pathModule.join(MOCK_CREATE_APP_ROOT, ...paths),
@@ -40,18 +44,6 @@ jest.mock('@backstage/cli-common', () => {
...actual,
findPaths: jest.fn(),
findOwnPaths: () => mockOwnPaths,
targetPaths: {
get dir() {
return MOCK_TARGET_DIR;
},
get rootDir() {
return '/mock/target-root';
},
resolve: (...paths: string[]) =>
pathModule.resolve(MOCK_TARGET_DIR, ...paths),
resolveRoot: (...paths: string[]) =>
pathModule.resolve('/mock/target-root', ...paths),
},
};
});