From bc6ca70fe1d770bdc1a47bd08c0e0d642b119d03 Mon Sep 17 00:00:00 2001 From: Jasper McCulloch Date: Wed, 3 Jul 2024 23:19:17 +0100 Subject: [PATCH] fix(vite): Only attempt to amend test object if one exists 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. --- .../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 6e0a1418842c1..52ddbb9c4aa5c 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) {