Skip to content

Commit 11cd9cb

Browse files
Copilothotlong
andcommitted
feat: add migrate command test to CLI lifecycle suite
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 0830116 commit 11cd9cb

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

packages/cli/test/cli-lifecycle.test.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,49 @@ describe('CLI Lifecycle: init → content → build', () => {
199199
const rootNextDir = path.join(testDir, '.next');
200200
expect(fs.existsSync(rootNextDir)).toBe(true);
201201
});
202+
203+
// ------------------------------------------------------------------
204+
// Step 6: Migrate markdown files to MDX
205+
// ------------------------------------------------------------------
206+
it('should migrate markdown files to MDX format', () => {
207+
// Create a sample markdown file at the project root
208+
const mdContent = [
209+
'# My Guide',
210+
'',
211+
'This is a comprehensive guide for getting started.',
212+
'',
213+
'## Installation',
214+
'',
215+
'```bash',
216+
'npm install my-lib',
217+
'```',
218+
'',
219+
'## Usage',
220+
'',
221+
'Import and use the library.',
222+
].join('\n');
223+
fs.writeFileSync(path.join(testDir, 'GUIDE.md'), mdContent);
224+
225+
// Run migrate
226+
runCli(['migrate', 'GUIDE.md', '--output', 'content/docs']);
227+
228+
// Verify the MDX file was created
229+
const mdxPath = path.join(testDir, 'content', 'docs', 'guide.mdx');
230+
expect(fs.existsSync(mdxPath)).toBe(true);
231+
232+
// Verify frontmatter was added
233+
const mdxContent = fs.readFileSync(mdxPath, 'utf-8');
234+
expect(mdxContent).toContain('---');
235+
expect(mdxContent).toContain('title: "My Guide"');
236+
expect(mdxContent).toContain('description:');
237+
238+
// Verify the H1 heading is removed (it's in frontmatter now)
239+
expect(mdxContent).not.toMatch(/^# My Guide$/m);
240+
241+
// Verify meta.json was updated
242+
const meta = JSON.parse(
243+
fs.readFileSync(path.join(testDir, 'content', 'docs', 'meta.json'), 'utf-8'),
244+
);
245+
expect(meta.pages).toContain('guide');
246+
});
202247
});

0 commit comments

Comments
 (0)