From 72788a92b209de889565b92e506d0154de02da3c Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jul 2024 15:51:05 +0800 Subject: [PATCH] test: fix windows e2e --- e2e/cases/html-tags/function-usage/index.test.ts | 4 ++-- e2e/cases/html/inject/index.test.ts | 6 +++--- e2e/cases/html/meta/index.test.ts | 4 ++-- e2e/scripts/helper.ts | 3 +++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/e2e/cases/html-tags/function-usage/index.test.ts b/e2e/cases/html-tags/function-usage/index.test.ts index 9e3432e481..c90e49d400 100644 --- a/e2e/cases/html-tags/function-usage/index.test.ts +++ b/e2e/cases/html-tags/function-usage/index.test.ts @@ -1,4 +1,4 @@ -import { build } from '@e2e/helper'; +import { build, normalizeNewlines } from '@e2e/helper'; import { expect, test } from '@playwright/test'; test('should inject tags with function usage correctly', async () => { @@ -11,7 +11,7 @@ test('should inject tags with function usage correctly', async () => { const indexHtml = files[Object.keys(files).find((file) => file.endsWith('index.html'))!]; - expect(indexHtml).toEqual(` + expect(normalizeNewlines(indexHtml)).toEqual(` Rsbuild App diff --git a/e2e/cases/html/inject/index.test.ts b/e2e/cases/html/inject/index.test.ts index 196c795a1d..0854f9edaf 100644 --- a/e2e/cases/html/inject/index.test.ts +++ b/e2e/cases/html/inject/index.test.ts @@ -1,5 +1,5 @@ import path from 'node:path'; -import { build } from '@e2e/helper'; +import { build, normalizeNewlines } from '@e2e/helper'; import { expect, test } from '@playwright/test'; import { pluginRem } from '@rsbuild/plugin-rem'; @@ -56,7 +56,7 @@ test('should set inject via function correctly', async () => { const fooHtml = files[Object.keys(files).find((file) => file.endsWith('foo.html'))!]; - expect(fooHtml).toEqual(` + expect(normalizeNewlines(fooHtml)).toEqual(` Rsbuild App @@ -67,7 +67,7 @@ test('should set inject via function correctly', async () => { const indexHtml = files[Object.keys(files).find((file) => file.endsWith('index.html'))!]; - expect(indexHtml).toEqual(` + expect(normalizeNewlines(indexHtml)).toEqual(` Rsbuild App diff --git a/e2e/cases/html/meta/index.test.ts b/e2e/cases/html/meta/index.test.ts index 37ceeb218b..722c727856 100644 --- a/e2e/cases/html/meta/index.test.ts +++ b/e2e/cases/html/meta/index.test.ts @@ -1,4 +1,4 @@ -import { build } from '@e2e/helper'; +import { build, normalizeNewlines } from '@e2e/helper'; import { expect, test } from '@playwright/test'; test('should not inject charset meta if template already contains it', async () => { @@ -17,7 +17,7 @@ test('should not inject charset meta if template already contains it', async () const html = files[Object.keys(files).find((file) => file.endsWith('index.html'))!]; - expect(html).toEqual(` + expect(normalizeNewlines(html)).toEqual(` Page Title diff --git a/e2e/scripts/helper.ts b/e2e/scripts/helper.ts index bf59ac8982..0cdd6e95f8 100644 --- a/e2e/scripts/helper.ts +++ b/e2e/scripts/helper.ts @@ -102,3 +102,6 @@ export const proxyConsole = ( }, }; }; + +// Windows and macOS use different new lines +export const normalizeNewlines = (str: string) => str.replace(/\r\n/g, '\n');