Skip to content

Commit

Permalink
fix(vite): Only attempt to amend test object if one exists (nrwl#26822)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jaspooky authored Jul 9, 2024
1 parent 73858a0 commit 8fd38cb
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8fd38cb

Please sign in to comment.