Skip to content

Commit 8911b38

Browse files
committed
test(llms-txt): add generateRootLlmsTxt unit tests
Test route pattern inclusion, example links, base URL substitution, and trailing newline for the root /llms.txt discovery page output.
1 parent fb11b66 commit 8911b38

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/unit/server/utils/llms-txt.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
discoverAgentFiles,
55
fetchAgentFiles,
66
generateLlmsTxt,
7+
generateRootLlmsTxt,
78
} from '../../../../server/utils/llms-txt'
89

910
describe('discoverAgentFiles', () => {
@@ -299,3 +300,36 @@ describe('generateLlmsTxt', () => {
299300
expect(output).toContain('- npm: https://www.npmjs.com/package/@nuxt/kit/v/1.0.0')
300301
})
301302
})
303+
304+
describe('generateRootLlmsTxt', () => {
305+
it('includes all route patterns', () => {
306+
const output = generateRootLlmsTxt('https://npmx.dev')
307+
308+
expect(output).toContain('# npmx.dev')
309+
expect(output).toContain('https://npmx.dev/package/<name>/llms.txt')
310+
expect(output).toContain('https://npmx.dev/package/<name>/v/<version>/llms.txt')
311+
expect(output).toContain('https://npmx.dev/package/@<org>/<name>/llms.txt')
312+
expect(output).toContain('https://npmx.dev/package/@<org>/<name>/v/<version>/llms.txt')
313+
expect(output).toContain('https://npmx.dev/package/<name>/llms_full.txt')
314+
expect(output).toContain('https://npmx.dev/package/@<org>/llms.txt')
315+
})
316+
317+
it('includes example links', () => {
318+
const output = generateRootLlmsTxt('https://npmx.dev')
319+
320+
expect(output).toContain('[nuxt llms.txt](https://npmx.dev/package/nuxt/llms.txt)')
321+
expect(output).toContain('[@nuxt org packages](https://npmx.dev/package/@nuxt/llms.txt)')
322+
})
323+
324+
it('uses provided base URL', () => {
325+
const output = generateRootLlmsTxt('http://localhost:3000')
326+
327+
expect(output).toContain('http://localhost:3000/package/<name>/llms.txt')
328+
expect(output).not.toContain('https://npmx.dev')
329+
})
330+
331+
it('ends with newline', () => {
332+
const output = generateRootLlmsTxt('https://npmx.dev')
333+
expect(output.endsWith('\n')).toBe(true)
334+
})
335+
})

0 commit comments

Comments
 (0)