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.
This commit is contained in:
parent
73858a094e
commit
8fd38cba9a
@ -102,12 +102,15 @@ export function fixCoverageAndRerporters(
|
|||||||
configNode,
|
configNode,
|
||||||
`PropertyAssignment:has(Identifier[name="test"])`
|
`PropertyAssignment:has(Identifier[name="test"])`
|
||||||
)?.[0];
|
)?.[0];
|
||||||
|
|
||||||
|
if (testObject) {
|
||||||
changes.push({
|
changes.push({
|
||||||
type: ChangeType.Insert,
|
type: ChangeType.Insert,
|
||||||
index: testObject.getStart() + `test: {`.length + 1,
|
index: testObject.getStart() + `test: {`.length + 1,
|
||||||
text: `reporters: ['default'],`,
|
text: `reporters: ['default'],`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (changes.length > 0) {
|
if (changes.length > 0) {
|
||||||
return applyChangesToString(configContents, changes);
|
return applyChangesToString(configContents, changes);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user