Skip to content

Commit

Permalink
Reuse same obj w/ slightly different pos (EOL on win32 is one more char)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 22, 2023
1 parent 7e483d4 commit da945fc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/cli-reporter-jsonExt.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'node:assert/strict';
import { EOL } from 'node:os';
import { platform } from 'node:os';
import test from 'node:test';
import { resolve } from '../src/util/path.js';
import { execFactory } from './helpers/execKnip.js';
Expand Down Expand Up @@ -127,5 +127,21 @@ test('knip --reporter jsonext', () => {
},
];

assert.equal(exec('knip --reporter jsonExt'), JSON.stringify(json) + EOL);
if (platform() === 'win32') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const updatePos = (obj: any) => {
if (Array.isArray(obj)) {
obj.forEach(item => updatePos(item));
} else if (obj && typeof obj === 'object') {
for (const key in obj) {
if (key === 'pos' && 'line' in obj) obj[key] += obj['line'] - 1;
else updatePos(obj[key]);
}
}
};
// Add line - 1 to every pos (each EOL is one more char)
updatePos(json);
}

assert.equal(exec('knip --reporter jsonExt'), JSON.stringify(json) + '\n');
});

0 comments on commit da945fc

Please sign in to comment.