From ca66eda1fb2a7b16dab6411044a3c38c8fdde7e2 Mon Sep 17 00:00:00 2001 From: Alexander Opran Date: Fri, 28 Mar 2025 20:56:32 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8FNormalize=20test=20lin?= =?UTF-8?q?e=20endings.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/fixtures.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/fixtures.test.ts b/tests/fixtures.test.ts index 82fdd24..c5ae0f4 100644 --- a/tests/fixtures.test.ts +++ b/tests/fixtures.test.ts @@ -115,10 +115,12 @@ describe('fixtures', () => { let outputPath = path.resolve(fixturePath, `output.${ext}`) let cmd = `${binPath} ${inputPath} --plugin ${pluginPath}` + const normalizeLineEndings = (text: string) => text.replace(/\r\n/g, '\n') + test.concurrent(name, async ({ expect }) => { let results = await execAsync(cmd) - let formatted = results.stdout - let expected = await fs.readFile(outputPath, 'utf-8') + let formatted = normalizeLineEndings(results.stdout) + let expected = normalizeLineEndings(await fs.readFile(outputPath, 'utf-8')) expect(formatted.trim()).toEqual(expected.trim()) }) From 448ddf303fa8d38cde0e80e0ed2e8cf40eb7a006 Mon Sep 17 00:00:00 2001 From: Alexander Opran Date: Sun, 30 Mar 2025 17:58:17 +0300 Subject: [PATCH 2/3] Moved normalizeLineEndings function declaration out of loop. --- tests/fixtures.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/fixtures.test.ts b/tests/fixtures.test.ts index c5ae0f4..7c1366d 100644 --- a/tests/fixtures.test.ts +++ b/tests/fixtures.test.ts @@ -8,8 +8,8 @@ import { format, pluginPath } from './utils' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) - const execAsync = promisify(exec) +const normalizeLineEndings = (text: string) => text.replace(/\r\n/g, '\n') let fixtures = [ { @@ -115,8 +115,6 @@ describe('fixtures', () => { let outputPath = path.resolve(fixturePath, `output.${ext}`) let cmd = `${binPath} ${inputPath} --plugin ${pluginPath}` - const normalizeLineEndings = (text: string) => text.replace(/\r\n/g, '\n') - test.concurrent(name, async ({ expect }) => { let results = await execAsync(cmd) let formatted = normalizeLineEndings(results.stdout) From 00eab64b64fe1a26e1c8002030a7c817e455e7ea Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 30 May 2025 11:31:12 -0400 Subject: [PATCH 3/3] Simplify --- tests/fixtures.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/fixtures.test.ts b/tests/fixtures.test.ts index 7c1366d..b60c1a6 100644 --- a/tests/fixtures.test.ts +++ b/tests/fixtures.test.ts @@ -9,7 +9,6 @@ import { format, pluginPath } from './utils' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const execAsync = promisify(exec) -const normalizeLineEndings = (text: string) => text.replace(/\r\n/g, '\n') let fixtures = [ { @@ -117,8 +116,10 @@ describe('fixtures', () => { test.concurrent(name, async ({ expect }) => { let results = await execAsync(cmd) - let formatted = normalizeLineEndings(results.stdout) - let expected = normalizeLineEndings(await fs.readFile(outputPath, 'utf-8')) + let formatted = results.stdout.replace(/\r\n/g, '\n') + let expected = await fs + .readFile(outputPath, 'utf-8') + .then((c) => c.replace(/\r\n/g, '\n')) expect(formatted.trim()).toEqual(expected.trim()) })