From a169d7f6e96882c77091a1a2709abca8e98dd5e0 Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Mon, 8 Dec 2025 14:16:28 +0100 Subject: [PATCH] fix(cli): add helpful error message for missing jest dependency Since jest is now a peer dependencies, users must add it as a devDependency themselves. This commit adds early detection and a helpful error message when jest is missing, directing users to the migration guide. Signed-off-by: Johan Persson --- .../src/modules/test/commands/package/test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/cli/src/modules/test/commands/package/test.ts b/packages/cli/src/modules/test/commands/package/test.ts index 1ecf5b395e..d63600dbd2 100644 --- a/packages/cli/src/modules/test/commands/package/test.ts +++ b/packages/cli/src/modules/test/commands/package/test.ts @@ -83,5 +83,23 @@ export default async (_opts: OptionValues, cmd: Command) => { (process.stdout as any)._handle.setBlocking(true); } + // Because of the ongoing migration to v30 of jest, jest is no longer hard-depended to allow + // opt-in migration. Users instead need to add jest as a devDependency themselves and specify + // the version they want. This prints a helpful error message if jest is not found, i.e. they + // forgot/didn't know they had to add jest themselves. + try { + require.resolve('jest'); + } catch { + console.error( + [ + 'No Jest installation found in this project.', + '', + 'To support opt-in migration to Jest v30, the Backstage CLI now expects Jest to be installed as a devDependency.', + 'See the migration guide in the changelog for version options and their consequences.', + ].join('\n'), + ); + process.exit(1); + } + await require('jest').run(args); };