Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion __tests__/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('order()', () => {
obj: T,
map: PropertyMap | null,
res: T
) => expect(order(obj, map, '.')).toEqual(res);
) => expect(JSON.stringify(order(obj, map, '.'))).toEqual(JSON.stringify(res));

it('returns nothing for a blank JSON string', () => expectObject({}, {}, {}));

Expand Down Expand Up @@ -163,4 +163,45 @@ describe('order()', () => {
},
{i: 7, a: {b: [8, {d: [{f: {h: 'h', g: true}, e: 12}, 10], c: 9}, 11]}}
));

it('sorts keys with special characters', () => {
const obj = {
'lint-staged': {
'**/src/**/*.{js,jsx,ts,tsx}': 'eslint --fix'
},
dependencies: {
a: '1.2.3',
z: '1.2.3',
'@types/a': '1.2.3',
'@types/z': '1.2.3',
'@types/b': '1.2.3',
},
};
const map = {
'$': ['dependencies', 'lint-staged'],
'$.dependencies':(() => {
const keys = Object.keys(obj.dependencies);

// sort keys naturally
keys.sort();

return keys;
})(),
'$.lint-staged': Object.keys(obj['lint-staged']),
};
const expected = {
dependencies: {
'@types/a': '1.2.3',
'@types/b': '1.2.3',
'@types/z': '1.2.3',
a: '1.2.3',
z: '1.2.3',
},
'lint-staged': {
'**/src/**/*.{js,jsx,ts,tsx}': 'eslint --fix'
},
};

expectObject(obj, map, expected);
});
});