Skip to content

Commit 4e78833

Browse files
committed
Tests: Fix sitemap E2E test
1 parent 5e317fe commit 4e78833

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

code/e2e-tests/sitemap.spec.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
import { gunzipSync } from 'node:zlib';
2-
31
import { expect, test } from '@playwright/test';
42
import process from 'process';
53

64
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
75

86
test.describe('Sitemap', () => {
9-
test.beforeEach(async ({ page }) => {
10-
await page.goto(storybookUrl);
11-
});
12-
137
test('should have sitemap.xml with gzipped content', async ({ page }) => {
14-
const response = await page.evaluate(async () => {
15-
const res = await fetch('/sitemap.xml');
16-
const buffer = await res.arrayBuffer();
17-
return {
18-
status: res.status,
19-
contentType: res.headers.get('content-type'),
20-
contentEncoding: res.headers.get('content-encoding'),
21-
buffer: Array.from(new Uint8Array(buffer)),
22-
};
23-
});
24-
25-
expect(response.status).toBe(200);
26-
expect(response.contentType).toBe('application/xml');
27-
expect(response.contentEncoding).toBe('gzip');
28-
29-
const decompressed = gunzipSync(Uint8Array.from(response.buffer)).toString('utf-8');
8+
const response = await page.goto(`${storybookUrl}/sitemap.xml`);
9+
10+
expect(response?.status()).toBe(200);
11+
expect(response?.headers()['content-type']).toBe('application/xml');
12+
expect(response?.headers()['content-encoding']).toBe('gzip');
13+
14+
const decompressed = (await response?.body())?.toString('utf-8');
15+
expect(decompressed).toBeDefined();
3016

3117
expect(decompressed).toContain('<?xml version="1.0" encoding="UTF-8"?>');
3218
expect(decompressed).toContain('<urlset');

0 commit comments

Comments
 (0)