From 4f316085d89ed3c8adf3000cf232f6ad47b36183 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Mon, 13 May 2024 13:34:49 +0100 Subject: [PATCH] fix(core): workspace remove generator should handle no root jest config (#23328) --- .../remove/lib/update-jest-config.spec.ts | 20 +++++++++++++++++++ .../remove/lib/update-jest-config.ts | 1 + 2 files changed, 21 insertions(+) diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts index bc018577684fe..a3d52906ef9da 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts @@ -91,4 +91,24 @@ describe('updateRootJestConfig', () => { expect(rootJestConfig).toMatchSnapshot(); }); + + it('should handle not having a root jest config file', async () => { + // ARRANGE + tree.delete('jest.config.ts'); + + await libraryGenerator(tree, { + name: 'test', + bundler: 'vite', + unitTestRunner: 'vitest', + }); + + // ACT + expect(() => + updateJestConfig( + tree, + { projectName: 'test', skipFormat: false, forceRemove: false }, + readProjectConfiguration(tree, 'test') + ) + ).not.toThrow(); + }); }); diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.ts index 1cf5aef33a8f5..8ac17f22b0f90 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.ts @@ -69,6 +69,7 @@ export function updateJestConfig( const rootConfigPath = findRootJestConfig(tree); if ( + !rootConfigPath || !tree.exists(rootConfigPath) || !tree.exists(join(projectConfig.root, 'jest.config.ts')) || isUsingUtilityFunction(tree) ||