Skip to content

Commit b73c75f

Browse files
committed
fix: normalize line endings in structure snapshots for cross-platform compatibility
1 parent 1b65709 commit b73c75f

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

tests/all-pages.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import { verifyPageLoads, createPageStructureSnapshot } from './test-utils';
2+
import { verifyPageLoads, createPageStructureSnapshot, toNormalizedSnapshot } from './test-utils';
33

44
/**
55
* Comprehensive tests that verify ALL collection items render correctly
@@ -182,30 +182,30 @@ test.describe('Page Content Snapshots', () => {
182182
await page.waitForLoadState('networkidle');
183183

184184
const structure = await createPageStructureSnapshot(page);
185-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('all-home-structure.txt');
185+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('all-home-structure.txt');
186186
});
187187

188188
test('events page content snapshot', async ({ page }) => {
189189
await page.goto('/events/');
190190
await page.waitForLoadState('networkidle');
191191

192192
const structure = await createPageStructureSnapshot(page);
193-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('all-events-structure.txt');
193+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('all-events-structure.txt');
194194
});
195195

196196
test('sponsors page content snapshot', async ({ page }) => {
197197
await page.goto('/sponsors/');
198198
await page.waitForLoadState('networkidle');
199199

200200
const structure = await createPageStructureSnapshot(page);
201-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('all-sponsors-structure.txt');
201+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('all-sponsors-structure.txt');
202202
});
203203

204204
test('speakers page content snapshot', async ({ page }) => {
205205
await page.goto('/speakers/');
206206
await page.waitForLoadState('networkidle');
207207

208208
const structure = await createPageStructureSnapshot(page);
209-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('all-speakers-structure.txt');
209+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('all-speakers-structure.txt');
210210
});
211211
});

tests/events.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import { verifyPageLoads, createPageStructureSnapshot } from './test-utils';
2+
import { verifyPageLoads, createPageStructureSnapshot, toNormalizedSnapshot } from './test-utils';
33

44
test.describe('Events Page', () => {
55
test('should load successfully', async ({ page }) => {
@@ -44,7 +44,7 @@ test.describe('Events Page', () => {
4444
await page.goto('/events/');
4545
const structure = await createPageStructureSnapshot(page);
4646

47-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('events-page-structure.txt');
47+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('events-page-structure.txt');
4848
});
4949

5050
test('visual snapshot', async ({ page }) => {

tests/home.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import { verifyPageLoads, createPageStructureSnapshot, extractTextContent } from './test-utils';
2+
import { verifyPageLoads, createPageStructureSnapshot, extractTextContent, toNormalizedSnapshot } from './test-utils';
33

44
test.describe('Home Page', () => {
55
test('should load successfully', async ({ page }) => {
@@ -51,7 +51,7 @@ test.describe('Home Page', () => {
5151
await page.goto('/');
5252
const structure = await createPageStructureSnapshot(page);
5353

54-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('home-page-structure.txt');
54+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('home-page-structure.txt');
5555
});
5656

5757
test('visual snapshot', async ({ page }) => {

tests/speakers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import { verifyPageLoads, createPageStructureSnapshot, extractTextContent } from './test-utils';
2+
import { verifyPageLoads, createPageStructureSnapshot, extractTextContent, toNormalizedSnapshot } from './test-utils';
33

44
test.describe('Speakers Page', () => {
55
test('should load successfully', async ({ page }) => {
@@ -46,7 +46,7 @@ test.describe('Speakers Page', () => {
4646
await page.goto('/speakers/');
4747
const structure = await createPageStructureSnapshot(page);
4848

49-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('speakers-page-structure.txt');
49+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('speakers-page-structure.txt');
5050
});
5151

5252
test('visual snapshot', async ({ page }) => {

tests/sponsors.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import { verifyPageLoads, createPageStructureSnapshot, extractTextContent } from './test-utils';
2+
import { verifyPageLoads, createPageStructureSnapshot, extractTextContent, toNormalizedSnapshot } from './test-utils';
33

44
test.describe('Sponsors Page', () => {
55
test('should load successfully', async ({ page }) => {
@@ -36,7 +36,7 @@ test.describe('Sponsors Page', () => {
3636
await page.goto('/sponsors/');
3737
const structure = await createPageStructureSnapshot(page);
3838

39-
expect(JSON.stringify(structure, null, 2)).toMatchSnapshot('sponsors-page-structure.txt');
39+
expect(toNormalizedSnapshot(structure)).toMatchSnapshot('sponsors-page-structure.txt');
4040
});
4141

4242
test('visual snapshot', async ({ page }) => {

tests/test-utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ import { expect, Page } from '@playwright/test';
44
* Utility functions for approval testing
55
*/
66

7+
/**
8+
* Normalizes line endings to LF and removes empty lines for cross-platform snapshot comparison
9+
*/
10+
export function normalizeLineEndings(text: string): string {
11+
return text
12+
.replace(/\r\n/g, '\n') // Convert CRLF to LF
13+
.replace(/\r/g, '\n') // Convert remaining CR to LF
14+
.replace(/\n\s*\n/g, '\n') // Remove empty lines
15+
.trim();
16+
}
17+
18+
/**
19+
* Creates a normalized JSON string for snapshot comparison
20+
*/
21+
export function toNormalizedSnapshot(obj: object): string {
22+
return normalizeLineEndings(JSON.stringify(obj, null, 2));
23+
}
24+
725
/**
826
* Normalizes HTML content for approval testing by removing dynamic content
927
* like timestamps, session IDs, etc.

0 commit comments

Comments
 (0)