From 8fd38cba9a806578cea8fb79c6d67d06b3eeef24 Mon Sep 17 00:00:00 2001 From: Jasper McCulloch Date: Tue, 9 Jul 2024 14:47:37 +0100 Subject: [PATCH] fix(vite): Only attempt to amend test object if one exists (#26822) Test object is assigned using optional chaining but previously did not check that any value had actually been assigned which would cause the `getStart` call to fail resulting in a failed migration. ## Current Behavior Migration fails if no matching test object is found. ## Expected Behavior Migration should not fail. ## Related Issue(s) I haven't opened an issue, just the PR. I can open an issue if required for tracking. --- .../update-17-3-0/lib/fix-coverage-and-reporters.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.ts b/packages/vite/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.ts index 6e0a141884..52ddbb9c4a 100644 --- a/packages/vite/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.ts +++ b/packages/vite/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.ts @@ -102,11 +102,14 @@ export function fixCoverageAndRerporters( configNode, `PropertyAssignment:has(Identifier[name="test"])` )?.[0]; - changes.push({ - type: ChangeType.Insert, - index: testObject.getStart() + `test: {`.length + 1, - text: `reporters: ['default'],`, - }); + + if (testObject) { + changes.push({ + type: ChangeType.Insert, + index: testObject.getStart() + `test: {`.length + 1, + text: `reporters: ['default'],`, + }); + } } if (changes.length > 0) {