Skip to content

Commit

Permalink
test(cli): handle CRLF in test fixture files
Browse files Browse the repository at this point in the history
On Windows, files are normally checked-out with
`git config core.autocrlf true`, which will replace `'\n'`/LF chars
with `'\r\n'`/CRLF chars. We should handle this in our unit tests,
otherwise tests will fail on Windows CI.
  • Loading branch information
aloisklink committed Apr 23, 2024
1 parent 79451c1 commit dce5bfa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/cli/src/commander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,10 @@ describe('link', () => {
expect(file).toMatch(idLineRegex);
// other than the added `id: xxxx` field, everything else should be identical,
// although in practice, we'd expect some formatting changes
expect(file.replace(idLineRegex, '')).toStrictEqual(
await readFile(UNUSUAL_MARKDOWN_FILE, { encoding: 'utf8' }),
//
// We also normalize line endings to LF to avoid issues with CRLF on Windows
expect(file.replace(idLineRegex, '').replaceAll('\r\n', '\n')).toStrictEqual(
(await readFile(UNUSUAL_MARKDOWN_FILE, { encoding: 'utf8' })).replaceAll('\r\n', '\n'),
);
});
});
Expand Down

0 comments on commit dce5bfa

Please sign in to comment.