cli-node: refactor to remove mock-fs

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-12-28 15:15:35 +01:00
parent cdad4f0a02
commit 92ee157875
3 changed files with 13 additions and 11 deletions
@@ -15,15 +15,17 @@
*/
import { isMonoRepo } from './isMonoRepo';
import mockFs from 'mock-fs';
import { createMockDirectory } from '@backstage/backend-test-utils';
const mockDir = createMockDirectory();
jest.mock('../paths', () => ({
paths: { resolveTargetRoot: (...args: string[]) => mockDir.resolve(...args) },
}));
describe('isMonoRepo', () => {
afterEach(() => {
mockFs.restore();
});
it('should detect a monorepo', async () => {
mockFs({
mockDir.setContent({
'package.json': JSON.stringify({
name: 'foo',
workspaces: {
@@ -35,7 +37,7 @@ describe('isMonoRepo', () => {
});
it('should detect a non- monorepo', async () => {
mockFs({
mockDir.setContent({
'package.json': JSON.stringify({
name: 'foo',
}),
@@ -44,7 +46,7 @@ describe('isMonoRepo', () => {
});
it('should return false if package.json is missing', async () => {
mockFs({});
mockDir.setContent({});
await expect(isMonoRepo()).resolves.toBe(false);
});
});