Skip to content

Commit f6214bb

Browse files
Copilotargyleink
andcommitted
Refactor tests: use beforeEach to reduce duplication in test setup
Co-authored-by: argyleink <1134620+argyleink@users.noreply.github.com>
1 parent 346e054 commit f6214bb

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

tests/unit/robots.test.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,42 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect, it, beforeEach } from 'vitest';
22
import { getRobotsTxt } from '../../src/pages/robots.txt';
33

44
describe('Robots.txt', () => {
5+
let mockSite: URL;
6+
let mockSitemap: URL;
7+
let robotsTxt: string;
8+
9+
beforeEach(() => {
10+
mockSite = new URL('https://whiskey.fm');
11+
mockSitemap = new URL('sitemap-index.xml', mockSite);
12+
robotsTxt = getRobotsTxt(mockSitemap, mockSite);
13+
});
14+
515
describe('Generated content', () => {
616
it('should contain welcoming comment for AI agents', () => {
7-
const mockSite = new URL('https://whiskey.fm');
8-
const mockSitemap = new URL('sitemap-index.xml', mockSite);
9-
10-
const robotsTxt = getRobotsTxt(mockSitemap, mockSite);
11-
1217
expect(robotsTxt).toContain('Welcome AI agents and crawlers');
1318
expect(robotsTxt).toContain('User-agent: *');
1419
expect(robotsTxt).toContain('Allow: /');
1520
});
1621

1722
it('should include sitemap reference', () => {
18-
const mockSite = new URL('https://whiskey.fm');
19-
const mockSitemap = new URL('sitemap-index.xml', mockSite);
20-
21-
const robotsTxt = getRobotsTxt(mockSitemap, mockSite);
22-
2323
expect(robotsTxt).toContain('Sitemap: https://whiskey.fm/sitemap-index.xml');
2424
});
2525

2626
it('should reference LLM-specific resources', () => {
27-
const mockSite = new URL('https://whiskey.fm');
28-
const mockSitemap = new URL('sitemap-index.xml', mockSite);
29-
30-
const robotsTxt = getRobotsTxt(mockSitemap, mockSite);
31-
3227
expect(robotsTxt).toContain('/llms.txt');
3328
expect(robotsTxt).toContain('/for-llms');
3429
expect(robotsTxt).toContain('/episodes-index.html.md');
3530
});
3631

3732
it('should describe available content types', () => {
38-
const mockSite = new URL('https://whiskey.fm');
39-
const mockSitemap = new URL('sitemap-index.xml', mockSite);
40-
41-
const robotsTxt = getRobotsTxt(mockSitemap, mockSite);
42-
4333
expect(robotsTxt).toContain('Podcast metadata');
4434
expect(robotsTxt).toContain('Episode information');
4535
expect(robotsTxt).toContain('Full transcripts');
4636
expect(robotsTxt).toContain('Guest information');
4737
});
4838

4939
it('should include encouraging closing message', () => {
50-
const mockSite = new URL('https://whiskey.fm');
51-
const mockSitemap = new URL('sitemap-index.xml', mockSite);
52-
53-
const robotsTxt = getRobotsTxt(mockSitemap, mockSite);
54-
5540
expect(robotsTxt).toContain('Feel free to crawl, index, and use this content');
5641
expect(robotsTxt).toContain('help users discover');
5742
});

0 commit comments

Comments
 (0)