|
| 1 | +import { describe, expect, it, vi } from 'vitest' |
| 2 | + |
| 3 | +import { getStartupHints, logStartupHints } from './startup.js' |
| 4 | + |
| 5 | +describe('getStartupHints', () => { |
| 6 | + it('only reports content-directory issues when no content root exists', () => { |
| 7 | + const hints = getStartupHints({ |
| 8 | + projectRoot: '/tmp/my-docs', |
| 9 | + contentRoot: '/tmp/my-docs/source', |
| 10 | + contentDirExists: false, |
| 11 | + hasRoutes: false, |
| 12 | + }) |
| 13 | + |
| 14 | + expect(hints).toEqual([ |
| 15 | + 'Content directory "source" was not found. Create it or pass --content <dir> to point Clarify at a different directory.', |
| 16 | + ]) |
| 17 | + }) |
| 18 | + |
| 19 | + it('recommends adding an entry page when content exists but has no routes', () => { |
| 20 | + const hints = getStartupHints({ |
| 21 | + projectRoot: '/tmp/my-docs', |
| 22 | + contentRoot: '/tmp/my-docs/docs', |
| 23 | + contentDirExists: true, |
| 24 | + hasRoutes: false, |
| 25 | + }) |
| 26 | + |
| 27 | + expect(hints).toEqual([ |
| 28 | + 'No content pages were found yet. Add docs/index.mdx to get started.', |
| 29 | + ]) |
| 30 | + }) |
| 31 | +}) |
| 32 | + |
| 33 | +describe('logStartupHints', () => { |
| 34 | + it('prints a warn line per startup hint', () => { |
| 35 | + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}) |
| 36 | + |
| 37 | + logStartupHints({ |
| 38 | + projectRoot: '/tmp/my-docs', |
| 39 | + contentRoot: '/tmp/my-docs/source', |
| 40 | + contentDirExists: false, |
| 41 | + hasRoutes: false, |
| 42 | + }) |
| 43 | + |
| 44 | + expect(warn).toHaveBeenCalledWith(expect.stringContaining('[clarify] Content directory')) |
| 45 | + warn.mockRestore() |
| 46 | + }) |
| 47 | +}) |
0 commit comments