Skip to content

Commit

Permalink
fix(core): fix json diff and implicitJsonChanges part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed Mar 10, 2020
1 parent 6a71284 commit c91000c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
32 changes: 32 additions & 0 deletions packages/workspace/src/utils/json-diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@ describe('jsonDiff', () => {
});
});

it('should work for added array values', () => {
const result = jsonDiff(
{
rules: undefined
},
{
rules: ['rule1']
}
);

expect(result).toEqual(
expect.arrayContaining([
{
type: DiffType.Modified,
path: ['rules'],
value: {
lhs: undefined,
rhs: ['rule1']
}
},
{
type: DiffType.Added,
path: ['rules', '0'],
value: {
lhs: undefined,
rhs: 'rule1'
}
}
])
);
});

it('should work for added array items', () => {
const result = jsonDiff(
{
Expand Down
5 changes: 2 additions & 3 deletions packages/workspace/src/utils/json-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function jsonDiff(lhs: any, rhs: any): JsonChange[] {
}
});
}
return typeof lhsValue === 'object';
return typeof lhsValue === 'object' || Array.isArray(lhsValue);
});

walkJsonTree(rhs, [], (path, rhsValue) => {
Expand All @@ -63,9 +63,8 @@ export function jsonDiff(lhs: any, rhs: any): JsonChange[] {
rhs: rhsValue
}
});
return false;
}
return typeof rhsValue === 'object';
return typeof rhsValue === 'object' || Array.isArray(rhsValue);
});

return result;
Expand Down

0 comments on commit c91000c

Please sign in to comment.