From dce5bfaa7f4f64d77fd372b269784b0d0508f83c Mon Sep 17 00:00:00 2001 From: Alois Klink <alois@mermaidchart.com> Date: Tue, 23 Apr 2024 14:50:11 +0900 Subject: [PATCH] test(cli): handle CRLF in test fixture files 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. --- packages/cli/src/commander.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commander.test.ts b/packages/cli/src/commander.test.ts index 9a1f797..0691575 100644 --- a/packages/cli/src/commander.test.ts +++ b/packages/cli/src/commander.test.ts @@ -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'), ); }); });