From b8fe86dfa36b7d02757b502093b62b93b06591da Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Fri, 10 Nov 2023 18:45:50 -0500 Subject: [PATCH] fix(testing): target defaults migration should not throw if workspace contains inferred projects (#20189) (cherry picked from commit fec681be13ab901775c0f31c660db8b4ac94c0ca) --- .../move-options-to-target-defaults.spec.ts | 42 +++++++++++++++++++ .../move-options-to-target-defaults.ts | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.spec.ts b/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.spec.ts index 38e8e15c396a3..8cf5f5532d76c 100644 --- a/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.spec.ts +++ b/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.spec.ts @@ -559,4 +559,46 @@ describe('move-options-to-target-defaults migration', () => { }, }); }); + + it("should't error if a project is present in the graph but not using project.json", async () => { + projectGraph.nodes['csproj'] = { + name: 'csproj', + type: 'lib', + data: { + root: 'csproj', + targets: { + build: { + command: 'echo HELLO', + }, + }, + }, + }; + addProjectConfiguration(tree, 'proj1', { + root: 'proj1', + targets: { + test: { + executor: '@nx/jest:jest', + options: { + jestConfig: 'jest.config.js', + passWithNoTests: true, + }, + configurations: { + ci: { + ci: true, + codeCoverage: true, + }, + }, + }, + }, + }); + updateNxJson(tree, { + targetDefaults: { + build: { + inputs: ['default', '^production'], + }, + }, + }); + const promise = update(tree); + await expect(promise).resolves.not.toThrow(); + }); }); diff --git a/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.ts b/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.ts index 407d8f7b8a28b..be882746d992e 100644 --- a/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.ts +++ b/packages/jest/src/migrations/update-17-1-0/move-options-to-target-defaults.ts @@ -174,7 +174,7 @@ function isTargetDefaultUsed( targetName, targetDefaults, // It might seem like we should use the graph here too but we don't want to pass an executor which was processed in the graph - projectMap.get(p.name).targets?.[targetName]?.executor + projectMap.get(p.name)?.targets?.[targetName]?.executor ) === targetDefault ) { return true;