|
1 | | -import { gunzipSync } from 'node:zlib'; |
2 | | - |
3 | 1 | import { expect, test } from '@playwright/test'; |
4 | 2 | import process from 'process'; |
5 | 3 |
|
6 | 4 | const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; |
7 | 5 |
|
8 | 6 | test.describe('Sitemap', () => { |
9 | | - test.beforeEach(async ({ page }) => { |
10 | | - await page.goto(storybookUrl); |
11 | | - }); |
12 | | - |
13 | 7 | 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(); |
30 | 16 |
|
31 | 17 | expect(decompressed).toContain('<?xml version="1.0" encoding="UTF-8"?>'); |
32 | 18 | expect(decompressed).toContain('<urlset'); |
|
0 commit comments