Skip to content

Commit

Permalink
Try to sort the keys before comparing the obj
Browse files Browse the repository at this point in the history
  • Loading branch information
huyphung1602 committed Jan 2, 2025
1 parent da4e3d7 commit d2de814
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/dbml-connector/__tests__/connector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import path from 'path';
import { scanDirNames } from '../jestHelpers.ts';
import { connector } from '../src/index.ts';

const sortKeys = (obj: any): any => {
if (Array.isArray(obj)) {
return obj.map(sortKeys);
} else if (obj !== null && typeof obj === 'object') {
return Object.keys(obj).sort().reduce((result: any, key: string) => {
result[key] = sortKeys(obj[key]);
return result;
}, {});
}
return obj;
};

describe('@dbml/connector', () => {
const runTest = async (dirName: string) => {
process.chdir(dirName);
Expand All @@ -23,7 +35,7 @@ describe('@dbml/connector', () => {
const contentObj = JSON.parse(contentJson);
const expectObj = JSON.parse(expectContent);

expect(contentObj).toEqual(expectObj);
expect(sortKeys(contentObj)).toEqual(sortKeys(expectObj));
};

test.each(scanDirNames(__dirname, 'connectors'))('connectors/%s', async (dirName) => {
Expand Down

0 comments on commit d2de814

Please sign in to comment.