Skip to content

Commit

Permalink
test: fix windows e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jul 8, 2024
1 parent de4287d commit 72788a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions e2e/cases/html-tags/function-usage/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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(`<!doctype html>
expect(normalizeNewlines(indexHtml)).toEqual(`<!doctype html>
<html>
<head><script src="/foo.js"></script><script src="/bar.js"></script><script src="/baz.js"></script><title>Rsbuild App</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/index.js"></script></head>
<body>
Expand Down
6 changes: 3 additions & 3 deletions e2e/cases/html/inject/index.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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(`<!doctype html>
expect(normalizeNewlines(fooHtml)).toEqual(`<!doctype html>
<html>
<head><title>Rsbuild App</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<body>
Expand All @@ -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(`<!doctype html>
expect(normalizeNewlines(indexHtml)).toEqual(`<!doctype html>
<html>
<head><title>Rsbuild App</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/index.js"></script><link href="/static/css/index.css" rel="stylesheet"></head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions e2e/cases/html/meta/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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(`<!doctype html>
expect(normalizeNewlines(html)).toEqual(`<!doctype html>
<html>
<head>
<title>Page Title</title>
Expand Down
3 changes: 3 additions & 0 deletions e2e/scripts/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 72788a9

Please sign in to comment.