Skip to content

Commit 0b5cbb0

Browse files
JaspookyFrozenPandaz
authored andcommitted
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. (cherry picked from commit 8fd38cb)
1 parent cbaad02 commit 0b5cbb0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/vite/src/migrations/update-17-3-0/lib/fix-coverage-and-reporters.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ export function fixCoverageAndRerporters(
102102
configNode,
103103
`PropertyAssignment:has(Identifier[name="test"])`
104104
)?.[0];
105-
changes.push({
106-
type: ChangeType.Insert,
107-
index: testObject.getStart() + `test: {`.length + 1,
108-
text: `reporters: ['default'],`,
109-
});
105+
106+
if (testObject) {
107+
changes.push({
108+
type: ChangeType.Insert,
109+
index: testObject.getStart() + `test: {`.length + 1,
110+
text: `reporters: ['default'],`,
111+
});
112+
}
110113
}
111114

112115
if (changes.length > 0) {

0 commit comments

Comments
 (0)