|
| 1 | +import { NitroConfig } from 'nitropack'; |
| 2 | +import { ConfigEnv, UserConfig, ViteBuilder } from 'vite'; |
1 | 3 | import { describe, expect, it, vi } from 'vitest'; |
2 | 4 |
|
3 | 5 | import { PrerenderContentFile } from './options'; |
@@ -34,6 +36,48 @@ describe('nitro', () => { |
34 | 36 | expect(spy).not.toHaveBeenCalledWith('/api', expect.anything()); |
35 | 37 | }); |
36 | 38 |
|
| 39 | + describe('when building with the Vite Environment API', () => { |
| 40 | + it('builds the sitemap into the public assets before the server', async () => { |
| 41 | + // Arrange |
| 42 | + const { buildServerImportSpy, buildSitemapImportSpy } = |
| 43 | + await mockBuildFunctions(); |
| 44 | + const plugin = nitro({ |
| 45 | + ssr: true, |
| 46 | + prerender: { |
| 47 | + routes: ['/', '/about'], |
| 48 | + sitemap: { host: 'https://example.com' }, |
| 49 | + }, |
| 50 | + }); |
| 51 | + const config = (await ( |
| 52 | + plugin[1].config as ( |
| 53 | + config: UserConfig, |
| 54 | + env: ConfigEnv, |
| 55 | + ) => Promise<UserConfig> |
| 56 | + )({}, { command: 'build' } as ConfigEnv)) as UserConfig; |
| 57 | + const builder = { |
| 58 | + environments: { client: {}, ssr: {} }, |
| 59 | + build: vi.fn().mockResolvedValue(undefined), |
| 60 | + } as unknown as ViteBuilder; |
| 61 | + |
| 62 | + // Act |
| 63 | + await config.builder?.buildApp?.(builder); |
| 64 | + |
| 65 | + // Assert |
| 66 | + expect(buildSitemapImportSpy).toHaveBeenCalledTimes(1); |
| 67 | + expect(buildServerImportSpy).toHaveBeenCalledTimes(1); |
| 68 | + expect(buildSitemapImportSpy.mock.invocationCallOrder[0]).toBeLessThan( |
| 69 | + buildServerImportSpy.mock.invocationCallOrder[0], |
| 70 | + ); |
| 71 | + |
| 72 | + const nitroConfig = buildServerImportSpy.mock.calls[0][1] as NitroConfig; |
| 73 | + const sitemapDir = buildSitemapImportSpy.mock.calls[0][3]; |
| 74 | + expect(sitemapDir).toBe( |
| 75 | + (nitroConfig.publicAssets as { dir: string }[])[0].dir, |
| 76 | + ); |
| 77 | + expect(sitemapDir).not.toBe(nitroConfig.output?.publicDir); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
37 | 81 | describe.skip('when prerendering is configured...', () => { |
38 | 82 | it('should build the server with prerender route "/" if nothing was provided', async () => { |
39 | 83 | // Arrange |
|
0 commit comments