Skip to content

Commit

Permalink
applied suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Nov 23, 2024
1 parent a1e6a45 commit f7cf1b6
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions tests/build-post-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ describe('buildPostList', () => {
[join(tempDir, 'about'), '/about'],
];

const normalizedDir = normalize(join(tempDir, 'blog'));
await fs.ensureDir(normalizedDir);

await fs.ensureDir(join(tempDir, 'blog'));
await fs.writeFile(join(tempDir, 'blog', 'release-notes-2.1.0.mdx'), '---\ntitle: Release Notes 2.1.0\n---\nThis is a release note.');

Expand All @@ -43,10 +40,44 @@ describe('buildPostList', () => {

const output = JSON.parse(await fs.readFile(writeFilePath, 'utf-8'));

expect(output).toHaveProperty('docs');
expect(output).toHaveProperty('blog');
expect(output).toHaveProperty('about');
expect(output).toHaveProperty('docsTree');
expect(output.docs).toEqual(
expect.arrayContaining([
expect.objectContaining({
title: 'Docs Home',
slug: '/docs',
}),
expect.objectContaining({
title: 'Reference',
slug: '/docs/reference',
isRootSection: true,
}),
expect.objectContaining({
title: 'Specification',
slug: '/docs/reference/specification',
isSection: true,
}),
])
);

expect(output.blog).toEqual(
expect.arrayContaining([
expect.objectContaining({
title: 'Release Notes 2.1.0',
slug: '/blog/release-notes-2.1.0',
}),
])
);

expect(output.about).toEqual(
expect.arrayContaining([
expect.objectContaining({
title: 'About Us',
slug: '/about',
}),
])
);

expect(output.docsTree).toBeDefined();

const blogEntry = output.blog.find(item => item.slug === '/blog/release-notes-2.1.0');
expect(blogEntry).toBeDefined();
Expand All @@ -61,8 +92,12 @@ describe('buildPostList', () => {

const output = JSON.parse(await fs.readFile(writeFilePath, 'utf-8'));

expect(output.docs.length).toBeGreaterThan(0);
expect(output.docs.find(item => item.title === 'Section 1')).toBeDefined();
const sectionEntry = output.docs.find(item => item.title === 'Section 1');
expect(sectionEntry).toMatchObject({
title: 'Section 1',
slug: expect.stringContaining('/docs/section1'),
isSection: true
});
});

it('handles multiple release notes correctly', async () => {
Expand Down

0 comments on commit f7cf1b6

Please sign in to comment.