|
1 | | -import { describe, expect, it } from 'vitest'; |
| 1 | +import { mkdtemp, readFile, rm } from 'node:fs/promises'; |
| 2 | +import { tmpdir } from 'node:os'; |
| 3 | +import { join } from 'node:path'; |
| 4 | +import { afterEach, describe, expect, it, vi } from 'vitest'; |
2 | 5 | import { lintRules } from '../../docs/lint/rules.js'; |
3 | | -import { isSitemapPageUrl, renderSitemap } from './sitemap-xml.js'; |
| 6 | +import { isSitemapPageUrl, renderSitemap, sitemapPlugin } from './sitemap-xml.js'; |
4 | 7 |
|
5 | 8 | describe('isSitemapPageUrl', () => { |
6 | 9 | it('should include crawlable html pages', () => { |
@@ -105,3 +108,27 @@ describe('isSitemapPageUrl', () => { |
105 | 108 | expect(sitemap.match(/<video:video>/g)).toHaveLength(1); |
106 | 109 | }); |
107 | 110 | }); |
| 111 | + |
| 112 | +describe('sitemapPlugin', () => { |
| 113 | + let outputPath: string | undefined; |
| 114 | + |
| 115 | + afterEach(async () => { |
| 116 | + if (outputPath) await rm(outputPath, { force: true, recursive: true }); |
| 117 | + }); |
| 118 | + |
| 119 | + it('should publish the sitemap to the completed site output', async () => { |
| 120 | + outputPath = await mkdtemp(join(tmpdir(), 'elements-sitemap-')); |
| 121 | + const on = vi.fn(); |
| 122 | + sitemapPlugin({ on }); |
| 123 | + const afterBuild = on.mock.calls.find(([event]) => event === 'eleventy.after')?.[1]; |
| 124 | + |
| 125 | + await afterBuild({ |
| 126 | + directories: { output: outputPath }, |
| 127 | + results: [{ url: '/docs/elements/tabs/', content: '' }] |
| 128 | + }); |
| 129 | + |
| 130 | + await expect(readFile(join(outputPath, 'sitemap.xml'), 'utf-8')).resolves.toContain( |
| 131 | + '<loc>https://nvidia.github.io/elements/docs/elements/tabs/</loc>' |
| 132 | + ); |
| 133 | + }); |
| 134 | +}); |
0 commit comments